# floprouter > An OpenAI-compatible API in front of every GPU miner registered on FLOP Network. It lists and scores miners from chain data, picks one per request (auto mode) or uses the miners you name, and pays through on-chain payment channels. Runs on FLOP devnet; devnet and testnet FLOP have no monetary value. Base URL for OpenAI clients: https://api.floprouter.com/v1 Auth: Authorization: Bearer fr_... (a key from signing a challenge with a FLOP wallet). Router options: `provider` (order, only, ignore, sort, allow_fallbacks) and `flop` (wait_for_settlement, payer). Tool calls are not supported. Replies take about 15 to 50 s; settlement 2 to 4 minutes in the background. --- # Overview > What floprouter is, what it does for each request, and where to start. floprouter is an OpenAI-compatible API in front of FLOP Network. FLOP is a Substrate chain where GPU miners sell LLM inference and are paid through payment channels. The router lists every miner registered on chain, scores each one from its on-chain record, picks one for your request or uses the one you name, and runs the paid session for you. It runs on FLOP devnet today. Devnet and testnet FLOP have no monetary value. ## What happens on each request 1. **A miner is chosen.** In auto mode the router takes the best ready miner for your model by score. You can also name miners with the `provider` object. 2. **A payment channel opens on chain.** Escrow for this one request is locked, normally against the miner's signed offer. 3. **The miner answers.** With streaming you see the text as it is decoded; the whole reply is then checked against the miner's signed receipt. On devnet a reply takes about 15 to 50 s. 4. **The miner settles.** The settlement is final on chain 2 to 4 minutes later, in the background. You can watch it with `GET /v1/sessions/{id}` or in the [playground](/playground/). ## Base URL ```text https://api.floprouter.com/v1 ``` Any OpenAI client works with that base URL and a floprouter key. See the [quick start](/docs/quickstart/). ## What is live | Part | State | | - | - | | Miner directory, scores, models | Live | | Chat completions, auto and pinned routing | Live | | Session status and on-chain links | Live | | Wallet sign-in and API keys | (live) | | Your wallet as the on-chain payer (grant) | (live) | | Prepaid balance | (live) | | Router fee charged | (live) | | Streaming (text forwarded as the miner sends it) | (live) | | Tool calls | Not supported | The website checks these against the API it talks to on every visit; the [status page](/status/) shows the result. ## For agents - [`/llms.txt`](/llms.txt) lists every page. [`/llms-full.txt`](/llms-full.txt) is the whole documentation in one file. - Every docs page is also plain Markdown: add `.md` to its path, for example [`/docs/quickstart.md`](/docs/quickstart.md). - The OpenAPI schema is at [`/openapi.json`](/openapi.json) and at `https://api.floprouter.com/openapi.json`. --- # Quick start > Send your first request in three steps. Only the base URL and the key differ from the OpenAI API. ## 1. Get a key Open the [account page](/account/), connect a Polkadot wallet (polkadot-js, Talisman, SubWallet), and sign the login message. You get a key that starts with `fr_`. It is shown once. (live) ```bash export FLOPROUTER_API_KEY=fr_... ``` A new key makes **your wallet** the payer on chain. That needs one more signature: the grant, on the same page. If you would rather not sign it, switch the key to **Balance** there and deposit a little FLOP. See [payer modes](/docs/payer-modes/). ## 2. Pick a model ```bash curl https://api.floprouter.com/v1/models ``` Each model lists `miners_ready`. A model with `available: true` has at least one ready miner. The [models page](/models/) shows the same list. ## 3. Send a request ```bash curl https://api.floprouter.com/v1/chat/completions \ -H "Authorization: Bearer $FLOPROUTER_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "model": "qwen/qwen3-8b", "messages": [{"role": "user", "content": "What is a payment channel?"}], "max_tokens": 128, "flop": {"wait_for_settlement": false} }' ``` ```python import os from openai import OpenAI client = OpenAI( base_url="https://api.floprouter.com/v1", api_key=os.environ["FLOPROUTER_API_KEY"], ) reply = client.chat.completions.create( model="qwen/qwen3-8b", messages=[{"role": "user", "content": "What is a payment channel?"}], max_tokens=128, extra_body={"flop": {"wait_for_settlement": False}}, ) print(reply.choices[0].message.content) print(reply.model_extra["flop"]["channel_id"]) ``` ```js import OpenAI from "openai"; const client = new OpenAI({ baseURL: "https://api.floprouter.com/v1", apiKey: process.env.FLOPROUTER_API_KEY, }); const reply = await client.chat.completions.create({ model: "qwen/qwen3-8b", messages: [{ role: "user", content: "What is a payment channel?" }], max_tokens: 128, flop: { wait_for_settlement: false }, }); console.log(reply.choices[0].message.content); console.log(reply.flop.channel_id); ``` In TypeScript the extra `flop` field is not in the SDK's types. Add `// @ts-expect-error` above it, or pass the body through a variable typed as `any`. The call returns as soon as the reply is verified, usually in 15 to 50 s. `"wait_for_settlement": false` is the default; it is written out here so you can see the option. Setting it to `true` waits for the on-chain settlement too, which takes 2 to 4 minutes more. For text as it is produced, use [streaming](/docs/streaming/). ## 4. Read the response The body is a normal `chat.completion`. Two fields are added: `provider`, the miner that served the request, and `flop`, the record of the session. ```json { "id": "gen-mwto3ds1-0811fd3833f3", "object": "chat.completion", "model": "qwen/qwen2.5-0.5b-instruct", "provider": "5HdTbhVY9jZCsfJVFENYF89hRfkBvoby2YxPest3XLLRhnrt", "choices": [{"index": 0, "message": {"role": "assistant", "content": "..."}, "finish_reason": "length"}], "usage": {"prompt_tokens": 6, "completion_tokens": 24, "total_tokens": 30}, "flop": { "session_id": "gen-mwto3ds1-0811fd3833f3", "status": "settling", "channel_id": "0x96cc8fd277657749a32b2acd6b0ee035fe5837785663a8d31ce4179212f3cddb", "miner": "5HdTbhVY9jZCsfJVFENYF89hRfkBvoby2YxPest3XLLRhnrt", "via": "force", "payer": {"address": "5Gmdxzsm...", "kind": "router-wallet"}, "escrow": "0.01", "miner_paid": null, "router_fee": {"percent": 5, "amount": "0.0005", "charged": false}, "on_chain": {"open_block": 4467284, "outcome": null, "outcome_block": null, "outcome_tx": null} } } ``` This is an abridged real response from devnet. Amounts are decimal strings in FLOP. ## 5. Watch it settle ```bash curl https://api.floprouter.com/v1/sessions/gen-mwto3ds1-0811fd3833f3 ``` `status` moves from `settling` to `settled`, and `miner_paid`, `on_chain.outcome_block` and `on_chain.outcome_tx` fill in. Open the channel on the explorer at `https://explorer.devnet.flop.network/channels/`. ## Next - [Routing](/docs/routing/): choose miners yourself. - [Payer modes](/docs/payer-modes/): keep your own wallet as the payer on chain. - [Connect](/docs/connect/): SDKs, agent frameworks, editor tools, MCP and the CLI. --- # Authentication > Wallet sign-in, API keys, and how to get a key from a script without a browser. (live) Send your key as a bearer token: ```text Authorization: Bearer fr_... ``` A key belongs to one FLOP wallet. There are no accounts, emails or passwords. Your wallet signs a one-time login message and the server gives you a key for that wallet. Signing the message is free and is not a transaction. ## In the browser Go to the [account page](/account/), connect a wallet extension and press **Sign and create key**. The key is shown once. You can keep it in that browser for the playground. ## From a script or an agent Two calls. The challenge is a short string that expires. ```bash curl -X POST https://api.floprouter.com/v1/auth/challenge \ -H "Content-Type: application/json" \ -d '{"address": "5YourWalletAddress..."}' # {"challenge": "...", "expires_at": "..."} ``` Sign the challenge string's UTF-8 bytes with the wallet's sr25519 or ed25519 key, then exchange the signature for a key: ```bash curl -X POST https://api.floprouter.com/v1/auth/keys \ -H "Content-Type: application/json" \ -d '{"address": "5YourWalletAddress...", "challenge": "...", "signature": "0x..."}' # {"key": "fr_...", "address": "5YourWalletAddress..."} ``` The challenge is a few lines of text naming your address, the network and an expiry. It states that signing does not move funds. The same flow in Node with polkadot-js: ```js import { Keyring } from "@polkadot/keyring"; import { cryptoWaitReady } from "@polkadot/util-crypto"; import { stringToU8a, u8aToHex } from "@polkadot/util"; const API = "https://api.floprouter.com"; await cryptoWaitReady(); const pair = new Keyring({ type: "sr25519" }).addFromUri(process.env.FLOP_WALLET_URI); const post = (path, body) => fetch(API + path, { method: "POST", headers: { "content-type": "application/json" }, body: JSON.stringify(body) }).then((r) => r.json()); const { challenge } = await post("/v1/auth/challenge", { address: pair.address }); const signature = u8aToHex(pair.sign(stringToU8a(challenge))); const { key } = await post("/v1/auth/keys", { address: pair.address, challenge, signature }); console.log(key); ``` Browser wallet extensions wrap the bytes as `...` before signing. The website signs that way; a script usually signs the bare bytes. The response includes the key's `id` and its `payer_mode`. ## Payer mode of a key A new key starts in `grant` mode: your wallet pays on chain, which needs the one-time grant. Until you sign it, chat requests with that key fail with `402 grant_required`. Either sign the grant on the [account page](/account/), or switch the key to `credit` so the router pays from your prepaid balance: ```bash curl -X PATCH https://api.floprouter.com/v1/auth/keys/ \ -H "Authorization: Bearer $FLOPROUTER_API_KEY" \ -H "Content-Type: application/json" \ -d '{"payer": "credit"}' ``` See [payer modes](/docs/payer-modes/). ## List and revoke keys ```bash curl https://api.floprouter.com/v1/auth/keys -H "Authorization: Bearer $FLOPROUTER_API_KEY" curl -X DELETE https://api.floprouter.com/v1/auth/keys/ -H "Authorization: Bearer $FLOPROUTER_API_KEY" ``` Both act on the wallet that owns the key you send. A wallet can hold a limited number of active keys; past it, creating one fails with `409 too_many_keys`. ## Without a key The directory endpoints (`/v1/miners`, `/v1/models`, `/v1/stats`, `/health`) need no key. Chat completions need one, unless the server runs an anonymous demo mode. That mode is off unless the operator turns it on; it is limited to devnet, has a small rate limit, and the router pays. (not live yet) ## Keep keys secret A key can spend your balance and, with a grant, open sessions paid by your wallet within the grant's limits. Do not put it in front-end code or public repositories. Revoke a key you no longer use. --- # Payer modes > Who pays on chain for each session, and why the grant keeps the on-chain record with your wallet. Every session opens a payment channel on chain. The account that opens it is the channel's payer, recorded in the channel's `agent` field. floprouter has two ways to pay: `grant` and `credit`. You choose per key (new keys start in `grant`), and can override per request with `"flop": {"payer": "credit"}`. Switch a key's mode on the [account page](/account/) or with `PATCH /v1/auth/keys/{id}` and `{"payer": "grant"}` or `{"payer": "credit"}`. | | Grant | Balance | | - | - | - | | Payer on chain | your wallet | the router's wallet | | What you sign | one grant, once | nothing per request | | Escrow paid from | your wallet | your router balance | | Router fee paid from | your router balance | your router balance | | Best for | people and agents that want the on-chain record in their own name | quick scripts and agents | Every response says who paid, in `flop.payer`: ```json "payer": {"address": "5...", "kind": "session-key"} ``` `kind` is `session-key` when your wallet paid through a grant, and `router-wallet` when the router's wallet paid. ## Grant mode (`grant`, recommended) (live) You sign one extrinsic with your wallet: `flopSessionKeys.createSession`. It names a delegate key held by the router and sets limits: a total spending cap, a per-transaction limit, a daily cap, a duration in blocks, and the pallets the delegate may use. floprouter asks only for `ComputeChannel`. After that, for each request, the router signs `flopSessionKeys.executeViaSession` with its delegate key. The chain runs the inner call, opening the channel, **as your account**. So: - The channel's payer on chain is your address, not the router's. The explorer shows your address as the payer. - The escrow comes from your wallet. - Your wallet signs nothing during the session. The router holds the per-channel session key and does everything after the open. Grant mode opens channels only against a miner's signed offer. When no ready miner has a live offer, or the grant cannot pay, a grant-mode request fails. To have it run in balance mode instead, send `"flop": {"fallback_payer": "credit"}`. It is off by default, so your wallet stays the payer unless you ask otherwise. ### What the delegate can and cannot do - It can open compute channels to any miner, at any escrow, within your caps. The chain enforces the caps. - It cannot transfer your funds or call anything outside `ComputeChannel`. - It stops working when the grant expires or when you revoke it with `flopSessionKeys.revokeSession`, signed by your wallet. ### Limits The chain limits how long a grant lasts and how many grants one delegate key can hold. `GET /v1/grants/params` returns the delegate address, the caps the router asks for (`amounts`), the chain's limits (`limits`), and the exact call to sign, both as `call` (pallet, method, arguments) and as encoded `call_data`. Without a key, pass `?address=`. `GET /v1/grants` returns your grant's state: sessions left and expiry. After you sign, `POST /v1/grants/sync` asks the router to read it from the chain at once. ```bash curl https://api.floprouter.com/v1/grants/params -H "Authorization: Bearer $FLOPROUTER_API_KEY" curl https://api.floprouter.com/v1/grants -H "Authorization: Bearer $FLOPROUTER_API_KEY" curl -X POST https://api.floprouter.com/v1/grants/sync -H "Authorization: Bearer $FLOPROUTER_API_KEY" ``` The [account page](/account/) does all three and builds the transaction for your wallet to sign. Signing the same delegate again replaces the old grant, so renewing is the same one signature. ## Balance mode (`credit`) (live) The router's wallet opens the channel and the cost, escrow plus fee, is taken from your prepaid balance. Nothing to sign per request. On chain, the payer of each session is the router, not you. ## What the current server offers `GET /health` lists the payer modes the server offers in `payer.modes`, and the router wallet's address in `payer.router_wallet`. Every response says who actually paid, in `flop.payer`. --- # Fees and pricing > What a request costs, who receives it, and how to fund a balance. A request has two costs. 1. **Escrow.** The amount locked in the payment channel. A cooperative settlement pays all of it out: to the miner, with the protocol's shares for validators and audit taken from it. Miners do not set prices. The chain sets a tariff floor per request, and the payer chooses the escrow above it. 2. **Router fee.** A percentage of the escrow, in FLOP, charged only for sessions that settle as paid. (live) ## How the escrow is sized The router sets the escrow per request as the largest of: - the chain's tariff floor for the model and token count, plus a margin, - the configured price per token times the prompt estimate plus `max_tokens`, - a configured minimum, - the minimum the miner's signed offer asks for. A request whose escrow would pass the configured maximum is refused with `escrow_limit`. Lower `max_tokens` to lower the escrow. `GET /v1/models` shows each model's escrow per 1,000 tokens and the chain's tariff floor: ```json "pricing": { "escrow_per_1000_tokens": "0.05", "basis": "token_price", "tariff_floor_per_1000_tokens": "0.000000000000030001", "router_fee_percent": 5 } ``` On devnet the tariff floor is tiny, so the configured price or the minimum decides. ## The router fee The current percentage is in `pricing.router_fee_percent` of every model and in `flop.router_fee` of every response: ```json "router_fee": {"percent": 5, "amount": "0.0005", "charged": false, "status": "pending"} ``` | `status` | Meaning | | - | - | | `pending` | The session has not settled yet. The fee is taken if it settles as paid. | | `charged` | Taken from your balance. `charged_amount` says how much. | | `not_charged` | The session ended without a paid settlement: no fee. | | `not_billed` | The request had no wallet key, so there was no balance to bill. | ## Your balance (live) Fund it with a plain FLOP transfer (`balances.transferKeepAlive`) from your wallet to the router's deposit address. It is credited to the sending address when its block is finalized, usually within a minute. Send from the same wallet that owns your key. ```bash curl https://api.floprouter.com/v1/balance -H "Authorization: Bearer $FLOPROUTER_API_KEY" ``` ```json {"object": "balance", "address": "5...", "currency": "FLOP", "balance": "0", "held": "0", "available": "0", "deposit_address": "5...", "fee_percent": 5, "recent": []} ``` `held` is reserved for sessions in progress; `available` is what new requests can use. In grant mode only the fee comes from the balance. In balance mode the escrow and the fee do. When the balance cannot cover a request the API answers `402` with code `insufficient_balance`. Devnet and testnet FLOP have no monetary value. Get devnet FLOP from the [FLOP faucet](https://faucet.flop.network). --- # Routing > Auto mode, pinning miners with the provider object, fallbacks, and how to read which miner served you. ## Auto mode Send no `provider` object and the router chooses. It considers miners that - serve the requested model, - have a session endpoint the router has proven, and - report ready, and tries them in order of score. In grant mode only miners with a live signed offer qualify. If an attempt fails before any output, the next miner is tried. Once a miner has produced output there is no retry, so you are never charged twice for one answer. The score runs from 0 to 100 and is computed from on-chain facts only: how a miner's paid sessions ended, how many and how recent, who paid for them, its stake, its slashing record and its calibration. The formula is not published. The inputs are, on every miner in `GET /v1/miners` and on the [miners page](/miners/). ## The provider object The same fields as OpenRouter's provider preferences. Miners are named by their account address. | Field | Type | Meaning | | - | - | - | | `order` | string[] | Try these miners first, in this order. | | `only` | string[] | Use only these miners. | | `ignore` | string[] | Never use these miners. | | `sort` | `reliability` or `latency` | `reliability` (default): by score. `latency`: by the router's measured proof latency. | | `allow_fallbacks` | boolean | With `order`: whether other miners may be tried after the listed ones. Default `true`. | Pin one miner and fail rather than fall back: ```json { "model": "qwen/qwen3-8b", "messages": [{"role": "user", "content": "Hello"}], "provider": {"only": ["5HKiGNFSqSyEMVMjjr8JBKkkppytaqFZCRm27KGbCeHhUq92"], "allow_fallbacks": false} } ``` Prefer two miners, then let the router choose: ```json "provider": {"order": ["5HKiGN...", "5CJxjZ..."], "allow_fallbacks": true} ``` Avoid a miner: ```json "provider": {"ignore": ["5HbvZY..."]} ``` With the OpenAI Python SDK put it in `extra_body`: ```python client.chat.completions.create( model="qwen/qwen3-8b", messages=[{"role": "user", "content": "Hello"}], extra_body={"provider": {"sort": "latency"}}, ) ``` ## Which miner served you - `provider` at the top level of the response is the miner's address. - `flop.miner`, `flop.endpoint` and `flop.via` say who served it and how the channel was opened: `offer` (against the miner's signed offer) or `force` (a force-open, when the miner has no live offer). - `flop.attempts` lists every try, including failed ones, with the stage it reached and the error. ## Finding miners ```bash # miners with a proven endpoint for one model, best first curl "https://api.floprouter.com/v1/miners?reachable=true&view=full&model=qwen/qwen3-8b" # every registered miner, sorted by settle rate curl "https://api.floprouter.com/v1/miners?sort=settle_rate&limit=1000" ``` Filters: `reachable`, `ready`, `active`, `calibrated`, `model`, `min_score`. Sort: `score`, `settle_rate`, `sessions`, `stake`, `latency`, `capacity`, with `order`, `limit`, `offset`. Without `view=full`, `reachable=true` returns the compact list of proven pairs. ## Models and price There is no per-miner price on FLOP Network, so the router does not route on price. It routes on reliability and reachability. See [fees](/docs/fees/). --- # Streaming > Text as the miner decodes it, how it is verified, and what the stream carries. `"stream": true` returns server-sent events in the OpenAI chunk format, ending with `data: [DONE]`. OpenAI SDKs read it unchanged. (live) The stream carries: 1. the first bytes once the router's own checks pass (payer, balance, grant, miner availability), or after 8 s, 2. keep-alive comments (lines that start with `:`) at least every 15 s while the miner works, so proxies and clients do not time out, 3. text deltas, forwarded **as the miner streams them**, 4. a last chunk with `usage` and the `flop` session record, 5. `data: [DONE]`. ```python stream = client.chat.completions.create( model="qwen/qwen3-8b", messages=[{"role": "user", "content": "Hello"}], stream=True, ) for chunk in stream: if chunk.choices and chunk.choices[0].delta.content: print(chunk.choices[0].delta.content, end="", flush=True) ``` ```bash curl -N https://api.floprouter.com/v1/chat/completions \ -H "Authorization: Bearer $FLOPROUTER_API_KEY" \ -H "Content-Type: application/json" \ -d '{"model": "qwen/qwen3-8b", "messages": [{"role": "user", "content": "Hello"}], "stream": true}' ``` The router forwards text as soon as the miner sends it. Miners on devnet today (worker 0.1.418) send the reply in one piece at the end of the turn, so for now a stream shows keep-alives and then the whole reply at once. When workers stream as they decode, the same requests show text as it is produced; nothing changes on your side. ## Verification The streamed text is provisional while it arrives. When the turn ends, the miner's signed receipt is checked against the whole reply, and the finish chunk is sent only after that check. The receipt commits to the same bytes, so the two match. If they ever did not, the stream ends with an error chunk that carries the verified text: ```json {"error": {"message": "the streamed text differs from the verified reply; use the verified content", "type": "server_error", "code": "stream_mismatch", "verified_content": "..."}} ``` Once text has reached you, the router does not fail over to another miner, so you never get two answers for one request. ## Why stream - You see text within seconds instead of waiting for the whole reply. - Non-streaming calls have a response deadline. When no verified reply arrives in time, they return `202` with a pending body and you poll for the reply (see [settlement](/docs/settlement/)). A stream has no such deadline. Streams never wait for the settlement. Read it from `GET /v1/sessions/{id}` with the `flop.session_id` from the last chunk. --- # Settlement > Timing, session states, and how to follow a payment channel to its final state on chain. Each request opens one payment channel. Its life on devnet: | Step | Typical time | | - | - | | Miner chosen, channel opened | a few seconds | | Verified reply | about 15 to 50 s after the request, sometimes longer | | Settlement final on chain | 2 to 4 minutes after the reply, in the background | ## When the call returns A non-streaming call returns as soon as the reply is verified, with `flop.status: "settling"`. The settlement continues in the background. To wait for the settlement instead, send `"flop": {"wait_for_settlement": true}`. The call then returns once the settlement is final, with `miner_paid` set, but only up to the response deadline below. ### The response deadline Some proxies drop responses that stay idle for long. So a non-streaming call answers within a fixed deadline (85 s on this server). If no verified reply has arrived by then, it returns `202` instead of failing: ```json { "id": "gen-...", "object": "chat.completion.pending", "status": "pending", "message": "no verified reply within 85 s; the session continues. Poll GET /v1/sessions/gen-... until reply is set, or use stream: true.", "poll": "/v1/sessions/gen-...", "flop": {"session_id": "gen-...", "status": "running"} } ``` The session keeps running. Poll `GET /v1/sessions/{id}` with the same key until `reply` is set. Streaming avoids this case entirely. ## Following a session ```bash curl https://api.floprouter.com/v1/sessions/ ``` | `status` | Meaning | | - | - | | `running` | The request is in progress. | | `settling` | The reply was delivered. The settlement is not final yet. | | `settled` | The miner was paid on chain. `miner_paid` and `on_chain.outcome_tx` are set. | | `refunded` | The escrow went back to the payer. | | `recovering` | The miner went silent after the channel opened. The router is closing the channel on chain. | | `failed` | No attempt produced output. | | `fraud`, `voided` | Final outcomes decided on chain. | `on_chain` holds the open block, the outcome, the outcome block and the transaction. With the key that made the request, the record also carries `reply`: the verified reply, once there is one. Look the channel up on the explorer: `https://explorer.devnet.flop.network/channels/`. ## When a miner goes silent The router watches every channel it opened. If a channel stays open past its deadlines, the router sends the matching recovery call on chain (`expire_force_open`, `timeout`, `force_settle` or `finalize`). These calls are open to anyone on FLOP; the router pays their transaction fees. The session's `attempts[].recovery` lists what was sent. ## One channel per request A multi-turn conversation is one request per turn, each with its own channel. Send the whole history in `messages` each time, as with any OpenAI-style API. --- # Errors > The error shape, every error code, and what to do about each. Errors use the OpenAI shape, so SDKs raise their usual exceptions: ```json {"error": {"message": "no ready miner serves this model", "type": "invalid_request_error", "code": "no_miner_available"}} ``` When a session was started before the error, `error.session_id` is set. Look it up with `GET /v1/sessions/{id}` to see every attempt and any channel that was opened. | HTTP | `code` | Meaning | What to do | | - | - | - | - | | 202 | (not an error) | `object: "chat.completion.pending"`: no verified reply within the response deadline. The session continues. | Poll `GET /v1/sessions/{id}` until `reply` is set, or use `stream: true`. | | 400 | `invalid_json`, `model_required`, `messages_required`, `invalid_message`, `invalid_max_tokens` | The body is not valid. | Fix the request. The message says which field. | | 400 | `unsupported` | The request asks for something not supported: `tools`, or `n` above 1. | Remove the field. | | 400 | `invalid_provider`, `invalid_sort`, `invalid_payer`, `invalid_address` | A `provider`, `flop.payer` or address value is wrong. | See [routing](/docs/routing/) and [payer modes](/docs/payer-modes/). | | 400 | `escrow_limit` | The escrow for this request would pass the maximum per request. | Lower `max_tokens` or shorten the prompt. | | 401 | `unauthorized` | Missing, unknown or revoked key, or the payer mode needs a wallet key. | Check the `Authorization` header. Create a key on the [account page](/account/). | | 401 | `invalid_challenge`, `challenge_expired`, `challenge_used`, `invalid_signature` | Sign-in failed. | Ask for a new challenge and sign it with the same address. | | 402 | `insufficient_balance` | Your prepaid balance cannot cover the request. The error carries `available` and `required`. | [Top up](/docs/fees/) or lower `max_tokens`. | | 402 | `insufficient_funds` | In grant mode, your wallet cannot cover the escrow. | Fund your wallet. | | 402 | `grant_required`, `grant_expired`, `grant_expiring`, `grant_revoked`, `grant_exhausted`, `grant_not_usable`, `grant_per_tx_limit` | Grant mode, and the grant cannot pay for this request. | Sign a new grant on the [account page](/account/), or raise its caps. | | 404 | `model_not_found` | Unknown model id. | Use an id from `GET /v1/models`. | | 404 | `miner_not_found`, `session_not_found`, `key_not_found`, `not_found` | Unknown miner, session, key or path. | | | 403 | `forbidden` | The request did not come through the public endpoint. | Use the documented base URL. | | 409 | `too_many_keys` | This wallet has the most active keys allowed. | Revoke one first. | | 200, in a stream | `stream_mismatch` | The streamed text differs from the verified reply. | Use `verified_content` from the error chunk. | | 413 | `body_too_large` | The request body is too large. | Shorten the prompt. | | 429 | `rate_limited`, `too_many_concurrent`, `grant_daily_cap`, `demo_budget_exhausted` | A rate, concurrency, grant daily or demo limit was reached. | Wait for the `Retry-After` header, or use a wallet key. | | 503 | `all_attempts_failed` | Every miner tried failed before producing output. It is 503, not 502, because OpenAI SDKs retry 502 at once and each retry can cost an on-chain fee. | Wait for `Retry-After`, or choose other miners. | | 503 | `no_miner_available` | No ready miner matches the model and your `provider` rules. | Check the [ready miners](/miners/?reach=ready) or relax `provider`. | | 503 | `payer_underfunded`, `daily_cap_reached`, `delegate_unfunded`, `payer_unavailable` | The router's wallet cannot pay right now, or hit its daily cap. | Retry later. | | 503 | `shutting_down` | The service is restarting. | Retry in a few seconds. | This list follows the server at the time of writing; [`/openapi.json`](/openapi.json) is the reference. Treat an unknown 5xx as retryable after a pause, and any 4xx as a problem with the request. 429 and 503 responses carry a `Retry-After` header. ## Retries The router already retries on another miner when an attempt fails before any output. A reply that started is never retried, so a client-side retry can open a second channel. Retry only on errors, not on slow replies: a normal reply takes 15 to 50 s on devnet. Set your client timeout to at least 120 s. ```python client = OpenAI(base_url="https://api.floprouter.com/v1", api_key=key, timeout=120, max_retries=1) ``` --- # Limits and supported fields > Which OpenAI fields work, which are ignored or rejected, and the limits on each request. ## Request fields | Field | Support | | - | - | | `model` | Required. An id or model hash from `GET /v1/models`. | | `messages` | Required. Roles `system`, `developer`, `user`, `assistant`. Text content. | | `max_tokens` | 1 to 32768, default 256. `max_completion_tokens` is an alias. It sizes the escrow. | | `stream` | Text as the miner decodes it, see [streaming](/docs/streaming/). | | `provider` | Miner choice, see [routing](/docs/routing/). | | `flop` | `wait_for_settlement` (default `false`), `payer` (`grant` or `credit`) to override the key's payer mode, and `fallback_payer: "credit"` to fall back to balance mode when the grant cannot serve a request. | | `temperature`, `top_p`, `seed`, `stop`, penalties | Accepted and ignored. Each model's decode policy is fixed on chain, so every miner answers the same way. | | `tools`, `tool_choice`, `functions` | Rejected with 400. Tool calls are not supported. (not live yet) | | `n` above 1 | Rejected with 400. | | `response_format`, `logprobs` | Ignored. | | other fields | Ignored, not rejected, so clients that send extra fields keep working. | ## Per request - One payment channel per request. Multi-turn chat sends the history each time. - A non-streaming call answers within a response deadline (85 s on this server); past it you get `202` and poll the session. See [settlement](/docs/settlement/). - The escrow has a maximum per request. Past it the request fails with `escrow_limit`. - The router has a daily spending cap for the sessions it pays. Past it requests fail with `daily_cap_reached`. ## Per key - Rate limits apply per key. Past them the API answers 429. - In grant mode your grant's caps apply as well: total, per transaction, daily, and its expiry. The chain enforces them. ## Not supported - Tool and function calling. (not live yet) - Images, audio, embeddings, the Responses API and the legacy completions API. --- # Miners and scores > How the directory is built, what the score is made from, and how a miner operator submits an endpoint. ## Where the list comes from Every miner in the on-chain registry is listed, reachable or not. Stake, calibration, capacity, slashing and models come from chain storage, read at a finalized block and refreshed every few minutes. Session history comes from finalized chain events: every compute channel the miner was paid through and how it ended. New miners appear on the next pass with no manual step. ## The score A number from 0 to 100, with a rank. It is computed from on-chain facts only: - how the miner's paid sessions ended: settled, timed out, acknowledgement expired, refunded, voided, fraud upheld, - how many there were, how recent, and from how many distinct payers, - stake, - slashing record: strikes, blacklist, failed acknowledgements, - the state of its hardware calibration. The exact formula is not published. Every input is returned beside the score, so anyone can judge a miner for themselves. The same chain state always gives the same score. Scores are recomputed about once a minute. Facts the router measures itself, such as whether the endpoint answers and how fast, are reported separately under `router_measured` and are not part of the score. ## Endpoints Session URLs are not on chain. The router collects candidate URLs from public sources and from operators, and accepts one only when the worker behind it proves which miner it is: 1. The URL is https, canonical, and resolves only to public addresses. 2. `GET /session/info` answers 401 with a session challenge, as a live worker does. 3. `POST /session/info-proof` answers a fresh random challenge with a signature for this chain. 4. The account named in the proof is a registered miner. 5. The session key that signed is tied to that miner on chain, by a signed offer of the miner or a finalized channel of the miner that used it. An entry that passes 1 to 4 but not 5 is kept as not yet tied and is never routed to. Entries are checked again every few minutes and before every session. | Directory label | Meaning | | - | - | | Ready | Proven, and the worker reports ready. Takes traffic. | | Live, not ready | Proven and answering, but the worker reports it is not ready. | | Key not tied | Valid proof, but the session key is not yet tied to the miner on chain. | | Down | Proven before, failing its checks now. | | No endpoint | No session URL is known. | ## Submitting an endpoint Use the [form](/operators/) or: ```bash curl -X POST https://api.floprouter.com/v1/miners//endpoint \ -H "Content-Type: application/json" \ -d '{"url": "https://miner.example.org"}' ``` `200` accepted and routable, `202` recorded but not routable until the chain ties the session key to the miner, `422` rejected or unreachable. Anyone may submit; only the proof decides which miner a URL belongs to. ## Network totals `GET /v1/stats` returns totals for the whole network: miners, reachable miners, models, sessions routed, settle rate. (live) --- # Connect > OpenAI SDKs, curl, agent frameworks, editor tools, the MCP server and the CLI. floprouter speaks the OpenAI chat completions API. Anything that lets you set an OpenAI-compatible base URL can use it. You need two values: | Setting | Value | | - | - | | Base URL | `https://api.floprouter.com/v1` | | API key | your `fr_...` key from the [account page](/account/) | | Model | an id from [`/v1/models`](/models/), for example `qwen/qwen3-8b` | Two things to know before you connect a tool: - **Plain chat only.** Tool calling is not supported, so a request that sends `tools` is rejected with 400. Agent modes in editors and frameworks usually send tools. Use their chat mode. - **Replies are slow by API standards.** 15 to 50 s on devnet. Raise client timeouts to at least 120 s. ## OpenAI Python SDK ```python from openai import OpenAI client = OpenAI(base_url="https://api.floprouter.com/v1", api_key="fr_...", timeout=120) reply = client.chat.completions.create( model="qwen/qwen3-8b", messages=[{"role": "user", "content": "Hello"}], extra_body={"flop": {"wait_for_settlement": False}}, ) ``` Router fields (`provider`, `flop`) go in `extra_body`. The `flop` object of the response is in `reply.model_extra["flop"]`. ## OpenAI JavaScript SDK ```js import OpenAI from "openai"; const client = new OpenAI({ baseURL: "https://api.floprouter.com/v1", apiKey: process.env.FLOPROUTER_API_KEY, timeout: 120_000 }); const reply = await client.chat.completions.create({ model: "qwen/qwen3-8b", messages: [{ role: "user", content: "Hello" }], flop: { wait_for_settlement: false }, }); ``` ## curl ```bash curl https://api.floprouter.com/v1/chat/completions \ -H "Authorization: Bearer $FLOPROUTER_API_KEY" \ -H "Content-Type: application/json" \ -d '{"model": "qwen/qwen3-8b", "messages": [{"role": "user", "content": "Hello"}], "flop": {"wait_for_settlement": false}}' ``` ## Agent frameworks Plain chat works; tool calls do not. The LangChain and Vercel AI SDK snippets below were checked against responses recorded from the live API, not with separate paid calls. LangChain (Python, `langchain-openai`): ```python from langchain_openai import ChatOpenAI llm = ChatOpenAI( base_url="https://api.floprouter.com/v1", api_key="fr_...", model="qwen/qwen3-8b", max_tokens=64, timeout=300, extra_body={"flop": {"wait_for_settlement": False}}, ) print(llm.invoke("What does a GPU miner do?").content) ``` Vercel AI SDK, with `@ai-sdk/openai-compatible` (it calls chat completions, which floprouter offers; the Responses API is not offered): ```js import { generateText, streamText } from "ai"; import { createOpenAICompatible } from "@ai-sdk/openai-compatible"; const floprouter = createOpenAICompatible({ name: "floprouter", baseURL: "https://api.floprouter.com/v1", apiKey: process.env.FLOPROUTER_API_KEY, }); // fields under providerOptions.floprouter go into the request body const { text } = await generateText({ model: floprouter("qwen/qwen3-8b"), prompt: "In one sentence, what is a payment channel?", providerOptions: { floprouter: { flop: { wait_for_settlement: false } } }, }); ``` An agent that needs tools can ask the model for a JSON action in plain text and parse it itself. That works today, because it is plain chat. ## Editor tools and chat apps Tools with an "OpenAI-compatible" provider setting take the base URL, key and model id above. Use chat, not agent or edit modes that rely on tool calls. Set the model's context and output limits low, since `max_tokens` sizes the escrow of every request. ## MCP server `floprouter-mcp` lets an agent list models and miners, run paid chat completions, and check sessions, balance and grant state. It never handles wallet keys. **Not published yet.** The package is built and tested, but it is not on npm yet. The commands below work once it is published. ```bash npx -y floprouter-mcp # stdio, what desktop and IDE clients use npx -y floprouter-mcp --http # streamable HTTP on http://127.0.0.1:8792/mcp ``` | Variable | Meaning | | - | - | | `FLOPROUTER_API_KEY` | Your `fr_...` key. Without it, only the read-only tools work. Falls back to the key saved by `floprouter login`. | | `FLOPROUTER_BASE_URL` | Default `https://api.floprouter.com` | | Tool | What it does | Paid | | - | - | - | | `list_models` | Models, ready and reachable miners, escrow per 1,000 tokens | no | | `list_miners` | Miners with score, settle rate, sessions, strikes, calibration and reachability, with filters | no | | `get_miner` | One miner in detail | no | | `chat` | One chat completion, auto or pinned miner. Returns the reply, session id, miner, escrow and payer | yes | | `session_status` | Settlement state of a session | no | | `account` | Balance, deposit address, fee and grant state | no | | `router_status` | Network, sync state and payer | no | Claude Code: ```bash claude mcp add floprouter --scope user -e FLOPROUTER_API_KEY=fr_... -- npx -y floprouter-mcp ``` Claude Desktop (`claude_desktop_config.json`) and Cursor (`~/.cursor/mcp.json`): ```json { "mcpServers": { "floprouter": { "command": "npx", "args": ["-y", "floprouter-mcp"], "env": { "FLOPROUTER_API_KEY": "fr_..." } } } } ``` Codex (`~/.codex/config.toml`): ```toml [mcp_servers.floprouter] command = "npx" args = ["-y", "floprouter-mcp"] env = { FLOPROUTER_API_KEY = "fr_..." } ``` `chat` returns once the reply is verified. Use `session_status` for the settlement; many MCP clients time a tool out before a settlement would finish. ## CLI `floprouter` browses miners and models, runs chat, and does the wallet steps on your own machine: creating a key, signing the grant, depositing FLOP. Keys stay local; the router only receives your address, a signature over its login challenge, and transactions you sign, which go to the chain. **Not published yet.** Same as the MCP server: the commands below work once the package is on npm. Needs Node 18.17 or later. ```bash npx floprouter models npx floprouter miners --reachable --sort settle_rate npx floprouter login --key-file ./my-wallet.json # polkadot-js JSON export, or --seed-file, or a hidden prompt npx floprouter grant # one signature: your wallet stays the payer on chain npx floprouter deposit 1 # fund the balance for the router fee npx floprouter chat "What is a payment channel?" npx floprouter chat --miner
--stream "..." npx floprouter session ``` A seed or password is never accepted as a command-line argument. Before signing a grant, the CLI checks the chain's genesis hash against the router's, builds the call itself, and refuses anything other than `flopSessionKeys.createSession` limited to `ComputeChannel`. ## For agents reading this - Every page of these docs is plain Markdown at its path plus `.md`. - [`/llms.txt`](/llms.txt) is the index; [`/llms-full.txt`](/llms-full.txt) is everything in one file. - [`/openapi.json`](/openapi.json) is the machine-readable schema.