{
  "id": "near-route-check",
  "name": "Taifoon × NEAR AI Cloud — one routed call, as NEAR's router makes it, and its settlement line",
  "nodes": [
    {
      "parameters": {},
      "id": "start",
      "name": "Start",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        0,
        300
      ]
    },
    {
      "parameters": {
        "resource": "inference",
        "operation": "listModels"
      },
      "id": "list",
      "name": "List models",
      "type": "n8n-nodes-taifoon.taifoon",
      "typeVersion": 1,
      "position": [
        220,
        300
      ],
      "notes": "GET /v1/models with the key: the models the gate serves at the list price (the same list the registry discovers).",
      "notesInFlow": true,
      "credentials": {
        "taifoonRelayerApi": {
          "id": "taifoon-relayer",
          "name": "Taifoon Relayer API"
        }
      }
    },
    {
      "parameters": {
        "resource": "inference",
        "operation": "chat",
        "model": "deepseek-ai/DeepSeek-V3.2",
        "messages": "[{\"role\":\"user\",\"content\":\"Reply with the single word: routed\"}]",
        "maxTokens": 8
      },
      "id": "chat",
      "name": "One call",
      "type": "n8n-nodes-taifoon.taifoon",
      "typeVersion": 1,
      "position": [
        440,
        300
      ],
      "notes": "POST /v1/chat/completions, OpenAI-compatible, metered on the key at the list price. Streaming with stream_options.include_usage is the same door.",
      "notesInFlow": true,
      "credentials": {
        "taifoonRelayerApi": {
          "id": "taifoon-relayer",
          "name": "Taifoon Relayer API"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "// NEAR settles per attempt: POST /v1/admin/provider-attempts/{id}/settlement { actual_cost_microusd, evidence }.\n// Taifoon's list price is USD per 1M tokens, so the price per token in micro-USD is the SAME number: cost = prompt × in + completion × out.\nconst r = $('One call').first().json; const list = $('List models').first().json.data ?? [];\nconst m = list.find((x) => x.id === r.model) ?? {}; const p = m.pricing ?? m.price ?? {}; const inP = Number(p.input ?? p.in ?? 0), outP = Number(p.output ?? p.out ?? 0);\nconst u = r.usage ?? {}; const cost = Math.round((u.prompt_tokens ?? 0) * inP + (u.completion_tokens ?? 0) * outP);\nreturn [{ json: { model: r.model, answer: r.choices?.[0]?.message?.content ?? null, usage: u, list_price_usd_per_mtok: { in: inP, out: outP }, settlement: { actual_cost_microusd: cost, evidence: r.id ?? null }, note: 'evidence = the completion id; on the x402 door it is the sale id the 402 receipt names' } }];"
      },
      "id": "line",
      "name": "Settlement line",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        660,
        300
      ],
      "notes": "The line NEAR posts to its own settlement endpoint, computed from the usage the answer carries and the list price.",
      "notesInFlow": true
    }
  ],
  "connections": {
    "Start": {
      "main": [
        [
          {
            "node": "List models",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "List models": {
      "main": [
        [
          {
            "node": "One call",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "One call": {
      "main": [
        [
          {
            "node": "Settlement line",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1",
    "saveDataSuccessExecution": "all",
    "saveManualExecutions": true
  },
  "meta": {
    "templateCredsSetupCompleted": false,
    "instanceId": "taifoon-coordination"
  }
}
