> ## Documentation Index
> Fetch the complete documentation index at: https://docs.floprouter.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Chat completion, settled on chain

> Chooses a miner (or follows `provider`), opens a payment channel with the caller's payer mode, runs one verified turn, and answers with the reply. If an attempt fails before any output, the next miner is tried, then the next model of `models`. Grant mode opens channels with miners' signed offers only: miners with a live offer are tried first, and when none has one the request waits up to 40 s for a fresh offer before moving on. Also served at `/api/v1/chat/completions`. A non-streaming call answers with one JSON body however long it takes: when no answer exists after 75 s the headers are sent; until then every answer, error or not, has its own HTTP status and a space is written every 10 s until the body follows (JSON allows leading whitespace); an error after that point is the JSON error body with status 200. With `flop.async: true` the call instead answers 202 `chat.completion.pending` when no reply exists within about 85 s. Closing the connection cancels the request (nothing is signed afterwards).



## OpenAPI

````yaml /openapi.json post /v1/chat/completions
openapi: 3.1.0
info:
  title: floprouter API
  version: 1.0.0
  description: >-
    The floprouter API routes chat requests to FLOP Network miners and settles
    each one on chain. One request format covers every model: chat completions
    with `provider` preferences and a `models` fallback list, model objects, a
    generation lookup, one error format and one streaming format. FLOP's own
    concepts have their own routes: miners, sessions on payment channels,
    session-key grants, the prepaid FLOP balance, settlement and on-chain
    attribution. **Base paths**: `/api/v1/...` and `/v1/...` serve the same
    routes; this document lists them under `/v1`. **Payer modes** (per key,
    overridable per request with `flop.payer`):

    - `grant`: the caller's wallet is the on-chain payer (channel `agent`) of
    every session. The wallet signs one `flopSessionKeys.createSession` grant to
    the router's delegate (`GET /v1/grants/params` returns the exact call data);
    the router then opens channels within the grant's caps. The escrow is paid
    on chain from the wallet; only the router fee comes from the prepaid
    balance. - `credit`: the router's wallet pays the session on chain; escrow
    and router fee are taken from the prepaid balance. **Balance**: fund it with
    a plain FLOP transfer from your wallet to `deposit_address` (`GET
    /v1/balance`); it is credited once the block is finalized. Withdraw with
    `POST /v1/balance/withdraw` (to the owning wallet only). Every balance can
    be recomputed from finalized chain state: billed sessions carry an encrypted
    ledger tag on chain, and the service checks its ledger against the chain
    continuously. The router fee is `fee_percent` of the session's escrow,
    charged only when the channel settles paid. **One request shape for every
    model**: the router chooses the chat envelope, template version, token
    limits and parameter support per model from what the chain and the miner's
    signed info say. Parameters a model does not support (see its
    `supported_parameters`) are ignored and named in
    `X-Floprouter-Ignored-Parameters`; `provider.require_parameters` refuses
    them instead. **Cost** (`usage.cost`, in FLOP): the escrow (prompt plus
    `max_tokens` at the model's price, paid in full on a cooperative settle)
    plus the router fee. Final once the session settles; a refunded session
    costs 0. **Timing**: a proxy in front closes responses idle for 100 s.
    Non-streaming calls answer within about 85 s: with the verified reply, or
    with HTTP 202 and the generation id to poll (`GET /v1/generation?id=`).
    Streams send `: FLOPROUTER PROCESSING` comments at least every 15 s.
    **Streaming**: chat completion chunks ending in a usage chunk (one choice
    repeating `finish_reason`) and `data: [DONE]`. Text is forwarded as the
    miner streams it and is provisional until the turn's signed receipt is
    verified at the end of the turn. A mid-stream error is one chunk with a
    top-level `error` and `finish_reason: "error"`. **Errors**: `{"error":
    {"code": <HTTP status>, "message", "metadata": {"reason", ...}}}`; 429 and
    503 carry `Retry-After`. **Miner score**: computed by the router from
    on-chain facts only (settlement history, volume, stake, slashing record,
    calibration state). The raw facts are returned beside it. **Client
    libraries**: the chat endpoint uses the widely used chat completions request
    and response format, so any client library for that format works with
    `baseURL` set to `https://api.floprouter.com/api/v1` and a floprouter key.
  license:
    name: Proprietary
    identifier: LicenseRef-Proprietary
servers:
  - url: https://api.floprouter.com
    description: API used by this site
security: []
tags:
  - name: Inference
    description: Chat completions and sessions.
  - name: Models
    description: >-
      Models, with their prices, limits and supported parameters, and the miners
      serving each.
  - name: Auth
    description: Wallet-signed API keys.
  - name: Grants
    description: 'Grant payer mode: the wallet stays the on-chain payer.'
  - name: Balance
    description: Prepaid balance and ledger.
  - name: Directory
    description: No key needed.
  - name: Service
    description: Health and this document.
paths:
  /v1/chat/completions:
    post:
      tags:
        - Inference
      summary: Chat completion, settled on chain
      description: >-
        Chooses a miner (or follows `provider`), opens a payment channel with
        the caller's payer mode, runs one verified turn, and answers with the
        reply. If an attempt fails before any output, the next miner is tried,
        then the next model of `models`. Grant mode opens channels with miners'
        signed offers only: miners with a live offer are tried first, and when
        none has one the request waits up to 40 s for a fresh offer before
        moving on. Also served at `/api/v1/chat/completions`. A non-streaming
        call answers with one JSON body however long it takes: when no answer
        exists after 75 s the headers are sent; until then every answer, error
        or not, has its own HTTP status and a space is written every 10 s until
        the body follows (JSON allows leading whitespace); an error after that
        point is the JSON error body with status 200. With `flop.async: true`
        the call instead answers 202 `chat.completion.pending` when no reply
        exists within about 85 s. Closing the connection cancels the request
        (nothing is signed afterwards).
      operationId: createChatCompletion
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ChatRequest'
            examples:
              conversation:
                value:
                  model: qwen/qwen3-8b
                  max_tokens: 60
                  messages:
                    - role: system
                      content: >-
                        You are a pirate. Answer every question in one short
                        sentence of pirate speech.
                    - role: user
                      content: My name is Ada. What is 2 + 2?
                    - role: assistant
                      content: Arr, that be 4, matey!
                    - role: user
                      content: What is my name?
              stream:
                value:
                  model: qwen/qwen3-8b
                  stream: true
                  max_tokens: 40
                  messages:
                    - role: user
                      content: Name a primary colour.
              fallback_and_routing:
                value:
                  model: qwen/qwen3-8b
                  models:
                    - qwen/qwen2.5-0.5b-instruct
                  messages:
                    - role: user
                      content: Who pays for this request?
                  max_tokens: 32
                  provider:
                    sort: latency
                    max_price:
                      prompt: 100
                      completion: 100
                    quantizations:
                      - bf16
                  flop:
                    payer: grant
                    fallback_payer: credit
      responses:
        '200':
          description: 'Verified reply. With `stream: true` the body is `text/event-stream`.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChatResponse'
              example:
                id: gen-mwu3v1s3-ab700a21edac
                object: chat.completion
                created: 1795489132
                model: qwen/qwen3-8b
                provider: 5HKiGNFSqSyEMVMjjr8JBKkkppytaqFZCRm27KGbCeHhUq92
                choices:
                  - index: 0
                    message:
                      role: assistant
                      content: The user pays for this request.
                      refusal: null
                      reasoning: null
                    finish_reason: stop
                    logprobs: null
                    native_finish_reason: stop
                usage:
                  prompt_tokens: 29
                  completion_tokens: 8
                  total_tokens: 37
                  prompt_tokens_details:
                    cached_tokens: 0
                  completion_tokens_details:
                    reasoning_tokens: 0
                  cost: 0.0105
                  is_byok: false
                  cost_details:
                    upstream_inference_cost: 0.01
                    upstream_inference_prompt_cost: 0.007838
                    upstream_inference_completions_cost: 0.002162
                    router_fee: 0.0005
                    currency: FLOP
                    final: false
                flop:
                  session_id: gen-mwu3v1s3-ab700a21edac
                  status: settling
                  model: Qwen/Qwen3-8B
                  model_hash: >-
                    0xfab8ec57f3bc1b5d4ca644fe12fab2ca1c35c24697d577c610b382cfea14d52d
                  created_at: '2026-11-24T02:58:37.000Z'
                  channel_id: >-
                    0xcddfd0102e2155f8e604bf7b0ad1c22a204112b2be7de6a0f374faa5c3f42e33
                  miner: 5HKiGNFSqSyEMVMjjr8JBKkkppytaqFZCRm27KGbCeHhUq92
                  endpoint: https://miner-002.0xmakase.co.jp
                  via: offer
                  payer:
                    address: 5F29vNoqgKpXxgUyz4DXifLnfAPQUQCq3ZQXGVjVbxp7sWBS
                    kind: session-key
                    mode: grant
                    fallback_from: null
                    account: 5F29vNoqgKpXxgUyz4DXifLnfAPQUQCq3ZQXGVjVbxp7sWBS
                    delegate: 5EfBc9f69NuPUV9zue18zeURWriF64Q9d7MN7h626D3pm2r7
                    note: >-
                      The on-chain payer (channel agent) is
                      5F29vNoqgKpXxgUyz4DXifLnfAPQUQCq3ZQXGVjVbxp7sWBS, through
                      a flopSessionKeys grant to the router's delegate
                      5EfBc9f69NuPUV9zue18zeURWriF64Q9d7MN7h626D3pm2r7; the
                      delegate signed the open and paid its transaction fee, the
                      escrow came from
                      5F29vNoqgKpXxgUyz4DXifLnfAPQUQCq3ZQXGVjVbxp7sWBS.
                  escrow: '0.01'
                  miner_paid: null
                  router_fee:
                    percent: 5
                    amount: '0.0005'
                    charged: false
                    charged_amount: null
                    status: pending
                    note: >-
                      Charged from the prepaid balance only when the session's
                      channel settles paid.
                  wire: flop.chat-turn.v2
                  currency: FLOP
                  network: devnet
                  on_chain:
                    open_block: 4493717
                    outcome: null
                    outcome_block: null
                    outcome_tx: null
                  usage:
                    prompt_tokens: 29
                    completion_tokens: 8
                    finish_reason: stop
                  error: null
                  attempts:
                    - 'n': 1
                      miner: 5HKiGNFSqSyEMVMjjr8JBKkkppytaqFZCRm27KGbCeHhUq92
                      endpoint: https://miner-002.0xmakase.co.jp
                      via: offer
                      channel_id: >-
                        0xcddfd0102e2155f8e604bf7b0ad1c22a204112b2be7de6a0f374faa5c3f42e33
                      escrow: '0.01'
                      status: settled
                      stage: settlement
                      error: null
                      outcome: settled
                      miner_paid: '0.0085'
                      refunded: null
                      open_block: 4493717
                      outcome_block: 4493761
                      outcome_tx: >-
                        0x10e0b1517da1fae6b5dcdeb08cde2efcc33f488a34b9f66bf8bafe438796b57a
                      first_output_ms: 14748
                      recovery: []
                  links:
                    channel: >-
                      https://explorer.devnet.flop.network/api/compute-channels/0xcddfd0102e2155f8e604bf7b0ad1c22a204112b2be7de6a0f374faa5c3f42e33
                    session: /v1/sessions/gen-mwu3v1s3-ab700a21edac
                  ignored_parameters:
                    - temperature
            text/event-stream:
              schema:
                type: string
              example: >+
                : FLOPROUTER PROCESSING


                data:
                {"id":"gen-mwu43k8o-4c620dd46c46","object":"chat.completion.chunk","created":1795489493,"model":"qwen/qwen3-8b","choices":[{"index":0,"delta":{"role":"assistant","content":""},"finish_reason":null,"native_finish_reason":null,"logprobs":null}]}


                : FLOPROUTER PROCESSING


                data:
                {"id":"gen-mwu43k8o-4c620dd46c46","object":"chat.completion.chunk","created":1795489493,"model":"qwen/qwen3-8b","choices":[{"index":0,"delta":{"content":"Red."},"finish_reason":null,"native_finish_reason":null,"logprobs":null}]}


                data:
                {"id":"gen-mwu43k8o-4c620dd46c46","object":"chat.completion.chunk","created":1795489493,"model":"qwen/qwen3-8b","choices":[{"index":0,"delta":{"content":""},"finish_reason":"stop","native_finish_reason":"stop","logprobs":null}],"provider":"5HKiGNFSqSyEMVMjjr8JBKkkppytaqFZCRm27KGbCeHhUq92"}


                data:
                {"id":"gen-mwu43k8o-4c620dd46c46","object":"chat.completion.chunk","created":1795489493,"model":"qwen/qwen3-8b","choices":[{"index":0,"delta":{"content":"","role":"assistant"},"finish_reason":"stop","native_finish_reason":"stop","logprobs":null}],"provider":"5HKiGNFSqSyEMVMjjr8JBKkkppytaqFZCRm27KGbCeHhUq92","usage":{"prompt_tokens":28,"completion_tokens":3,"total_tokens":31,"cost":0.0105},"flop":{"session_id":"gen-mwu43k8o-4c620dd46c46","status":"settling"}}


                data: [DONE]

          headers:
            X-Generation-Id:
              schema:
                type: string
            X-Floprouter-Ignored-Parameters:
              schema:
                type: string
              description: Comma-separated parameters this model ignored.
        '202':
          description: >-
            Only with `flop.async: true`: no verified reply within the response
            deadline; poll the generation.
          headers:
            Location:
              schema:
                type: string
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ChatPending'
              example:
                id: gen-mwu3v1s3-ab700a21edac
                object: chat.completion.pending
                created: 1795489132
                model: qwen/qwen3-8b
                status: pending
                message: >-
                  no verified reply within 85 s; the generation continues. Poll
                  GET /api/v1/generation?id=gen-mwu3v1s3-ab700a21edac (or GET
                  /api/v1/sessions/gen-mwu3v1s3-ab700a21edac) until it has a
                  reply, or use stream: true.
                poll: /v1/sessions/gen-mwu3v1s3-ab700a21edac
                flop: null
                generation: /api/v1/generation?id=gen-mwu3v1s3-ab700a21edac
        '400':
          $ref: '#/components/responses/E400'
        '401':
          $ref: '#/components/responses/E401'
        '402':
          $ref: '#/components/responses/E402'
        '403':
          $ref: '#/components/responses/E403'
        '404':
          $ref: '#/components/responses/E404'
        '413':
          $ref: '#/components/responses/E413'
        '429':
          $ref: '#/components/responses/E429'
        '503':
          $ref: '#/components/responses/E503'
      security:
        - bearer: []
        - {}
components:
  schemas:
    ChatRequest:
      type: object
      required:
        - messages
      additionalProperties: true
      description: >-
        Model parameters follow each model's `supported_parameters` (today
        `max_tokens`): others are ignored and named in
        `X-Floprouter-Ignored-Parameters`, or refused with
        `provider.require_parameters`. A non-empty `tools` gets 404 (no model is
        served with tool use yet). `tool` messages, non-text parts, `prompt`, `n
        > 1` and enabled `plugins` get 400. `transforms`, `user`, `session_id`,
        `metadata`, `trace`, `debug`, `service_tier` are accepted and ignored.
      properties:
        model:
          type: string
          examples:
            - qwen/qwen3-8b
          description: >-
            Model id from `GET /v1/models` (required; there is no account
            default).
        messages:
          type: array
          minItems: 1
          items:
            type: object
            required:
              - role
              - content
            properties:
              role:
                enum:
                  - developer
                  - system
                  - user
                  - assistant
              content:
                type:
                  - string
                  - array
                  - 'null'
                description: Text, or an array of `text` parts (joined).
        max_tokens:
          type: integer
          minimum: 1
          maximum: 32768
          default: 256
          description: >-
            Sets the escrow together with the prompt size.
            `max_completion_tokens` is accepted as an alias.
        stream:
          type: boolean
          default: false
        stream_options:
          type: object
          description: Accepted; the usage chunk is always sent.
        provider:
          $ref: '#/components/schemas/ProviderPreferences'
        flop:
          type: object
          properties:
            payer:
              enum:
                - grant
                - credit
              description: Override the key's payer mode for this request.
            fallback_payer:
              enum:
                - credit
              description: >-
                Grant mode only: if no miner can be served through the grant (no
                live signed offer, or the grant cannot pay), run the request in
                credit mode instead. Off by default.
            wait_for_settlement:
              type: boolean
              default: false
              description: >-
                Also wait for the finalized on-chain settlement before
                answering, within the response deadline (about 85 s). The
                settlement usually takes 1 to 4 minutes, so the answer may still
                say `settling`; poll `GET /v1/sessions/{id}`.
            async:
              type: boolean
              default: false
              description: >-
                Answer 202 with the generation id when no verified reply exists
                within about 85 s, instead of keeping the response open with
                whitespace keep-alives.
        models:
          type: array
          items:
            type: string
          description: >-
            Fallback models, tried in order after `model` when it has no serving
            provider or the request is too large for it; never after any output.
            The response `model` names the model used.
        route:
          enum:
            - fallback
        temperature:
          description: >-
            Ignored unless the model lists it in supported_parameters (none does
            today); with provider.require_parameters the request is refused.
        top_p:
          description: >-
            Ignored unless the model lists it in supported_parameters (none does
            today); with provider.require_parameters the request is refused.
        top_k:
          description: >-
            Ignored unless the model lists it in supported_parameters (none does
            today); with provider.require_parameters the request is refused.
        frequency_penalty:
          description: >-
            Ignored unless the model lists it in supported_parameters (none does
            today); with provider.require_parameters the request is refused.
        presence_penalty:
          description: >-
            Ignored unless the model lists it in supported_parameters (none does
            today); with provider.require_parameters the request is refused.
        repetition_penalty:
          description: >-
            Ignored unless the model lists it in supported_parameters (none does
            today); with provider.require_parameters the request is refused.
        min_p:
          description: >-
            Ignored unless the model lists it in supported_parameters (none does
            today); with provider.require_parameters the request is refused.
        top_a:
          description: >-
            Ignored unless the model lists it in supported_parameters (none does
            today); with provider.require_parameters the request is refused.
        seed:
          description: >-
            Ignored unless the model lists it in supported_parameters (none does
            today); with provider.require_parameters the request is refused.
        stop:
          description: >-
            Ignored unless the model lists it in supported_parameters (none does
            today); with provider.require_parameters the request is refused.
        response_format:
          description: >-
            Ignored unless the model lists it in supported_parameters (none does
            today); with provider.require_parameters the request is refused.
        logit_bias:
          description: >-
            Ignored unless the model lists it in supported_parameters (none does
            today); with provider.require_parameters the request is refused.
        logprobs:
          description: >-
            Ignored unless the model lists it in supported_parameters (none does
            today); with provider.require_parameters the request is refused.
        top_logprobs:
          description: >-
            Ignored unless the model lists it in supported_parameters (none does
            today); with provider.require_parameters the request is refused.
        reasoning:
          description: >-
            Ignored unless the model lists it in supported_parameters (none does
            today); with provider.require_parameters the request is refused.
        reasoning_effort:
          description: >-
            Ignored unless the model lists it in supported_parameters (none does
            today); with provider.require_parameters the request is refused.
        tools:
          type: array
          description: 'Non-empty: 404, no endpoint supports tool use yet.'
        plugins:
          type: array
          description: 'Enabled plugins are refused (400): none exists here.'
        transforms:
          type: array
          description: Accepted and ignored.
        user:
          type: string
          description: Accepted and ignored.
    ChatResponse:
      type: object
      properties:
        id:
          type: string
          description: Session id.
        object:
          const: chat.completion
        created:
          type: integer
        model:
          type: string
        provider:
          type: string
          description: 'The miner (provider slug: its address).'
        choices:
          type: array
          items:
            type: object
            properties:
              index:
                type: integer
              message:
                type: object
                properties:
                  role:
                    const: assistant
                  content:
                    type: string
              finish_reason:
                enum:
                  - stop
                  - length
                  - tool_calls
                  - content_filter
                  - error
              logprobs:
                type: 'null'
              native_finish_reason:
                type:
                  - string
                  - 'null'
                description: From the miner's signed receipt.
        usage:
          type: object
          properties:
            prompt_tokens:
              type: integer
            completion_tokens:
              type: integer
            total_tokens:
              type: integer
            prompt_tokens_details:
              type: object
              properties:
                cached_tokens:
                  type: integer
            completion_tokens_details:
              type: object
              properties:
                reasoning_tokens:
                  type: integer
            cost:
              type: number
              description: >-
                In FLOP: escrow plus router fee. Final once the session settles;
                0 when refunded.
            is_byok:
              type: boolean
            cost_details:
              type: object
              properties:
                upstream_inference_cost:
                  type: number
                upstream_inference_prompt_cost:
                  type: number
                upstream_inference_completions_cost:
                  type: number
                router_fee:
                  type: number
                currency:
                  type: string
                final:
                  type: boolean
        flop:
          $ref: '#/components/schemas/Session'
    ChatPending:
      type: object
      description: >-
        Returned with HTTP 202 when no verified reply exists within the response
        deadline. The session continues; poll it.
      properties:
        id:
          type:
            - string
            - 'null'
        object:
          const: chat.completion.pending
        created:
          type: integer
        model:
          type: string
        status:
          const: pending
        message:
          type: string
        poll:
          type:
            - string
            - 'null'
        flop:
          oneOf:
            - $ref: '#/components/schemas/Session'
            - type: 'null'
        generation:
          type:
            - string
            - 'null'
          description: Generation lookup for the same session.
    ProviderPreferences:
      type: object
      description: >-
        Provider preferences. A provider is a FLOP miner; its slug is the
        miner's SS58 address (the endpoint host is accepted as an alias).
      properties:
        order:
          type: array
          items:
            type: string
        only:
          type: array
          items:
            type: string
        ignore:
          type: array
          items:
            type: string
        allow_fallbacks:
          type: boolean
          default: true
          description: >-
            false: only the listed miners (with order), or only the top-ranked
            miner (without).
        sort:
          oneOf:
            - enum:
                - price
                - throughput
                - latency
                - reliability
            - type: object
              properties:
                by:
                  enum:
                    - price
                    - throughput
                    - latency
                    - reliability
                partition:
                  enum:
                    - model
                    - none
          description: >-
            price: all miners of a model are priced alike, default order
            applies; throughput and latency: router-measured time to the
            verified reply; reliability (default): on-chain score.
        max_price:
          type: object
          description: >-
            In FLOP: prompt and completion per million tokens, request per
            request. A model above it is skipped.
          properties:
            prompt:
              type: number
            completion:
              type: number
            request:
              type: number
            image:
              type: number
        require_parameters:
          type: boolean
          default: false
          description: >-
            Refuse (503) instead of ignoring parameters the model does not
            support.
        data_collection:
          enum:
            - allow
            - deny
          default: allow
          description: >-
            deny cannot be met: miners keep signed session evidence for audit
            and settlement (503).
        zdr:
          type: boolean
          description: true cannot be met (503), as data_collection deny.
        quantizations:
          type: array
          items:
            type: string
          examples:
            - - bf16
        preferred_min_throughput:
          description: Accepted and ignored.
        preferred_max_latency:
          description: Accepted and ignored.
        enforce_distillable_text:
          type: boolean
          description: Accepted and ignored.
    Session:
      type: object
      properties:
        session_id:
          type: string
        status:
          enum:
            - running
            - settling
            - settled
            - refunded
            - recovering
            - failed
            - fraud
            - voided
          description: >-
            `settling`: reply delivered, settlement not yet final. `settled`:
            miner paid on chain. `refunded`: escrow returned.
        model:
          type: string
        model_hash:
          type: string
        created_at:
          type: string
          format: date-time
        channel_id:
          type:
            - string
            - 'null'
          description: On-chain compute channel (0x + 64 hex).
        miner:
          type:
            - string
            - 'null'
        endpoint:
          type:
            - string
            - 'null'
        via:
          enum:
            - offer
            - force
            - null
          description: >-
            How the channel was opened: against the miner's signed offer, or by
            force-open.
        payer:
          type: object
          properties:
            address:
              type: string
              description: Account recorded on chain as the channel's payer (`agent`).
            kind:
              enum:
                - router-wallet
                - session-key
            mode:
              enum:
                - grant
                - credit
                - demo
                - operator
            fallback_from:
              type:
                - string
                - 'null'
              description: Set when the request fell back from grant to credit mode.
            account:
              type:
                - string
                - 'null'
              description: Wallet that owns the API key.
            delegate:
              type:
                - string
                - 'null'
              description: 'Grant mode: the router delegate that signed the open.'
            note:
              type: string
        escrow:
          type:
            - string
            - 'null'
          description: >-
            FLOP escrowed for the request. A cooperative settlement pays all of
            it.
          examples:
            - '0.01'
        miner_paid:
          type:
            - string
            - 'null'
          description: >-
            Amount paid to the miner, from the finalized `Settled` event. Null
            until settled.
          examples:
            - '0.01'
        router_fee:
          type: object
          properties:
            percent:
              type: number
            amount:
              type:
                - string
                - 'null'
              description: Fee for this session's escrow.
            charged:
              type: boolean
            charged_amount:
              type:
                - string
                - 'null'
            status:
              enum:
                - pending
                - charged
                - not_charged
                - not_billed
              description: >-
                `pending` until the channel's outcome is final; `charged` when
                it settled paid; `not_charged` when it was refunded or failed;
                `not_billed` for demo sessions.
            note:
              type: string
        currency:
          type: string
        network:
          type: string
        on_chain:
          type: object
          properties:
            open_block:
              type:
                - integer
                - 'null'
            outcome:
              enum:
                - settled
                - timed_out
                - ack_expired
                - refunded
                - voided
                - fraud
                - null
            outcome_block:
              type:
                - integer
                - 'null'
            outcome_tx:
              type:
                - string
                - 'null'
        usage:
          type: object
          properties:
            prompt_tokens:
              type:
                - integer
                - 'null'
            completion_tokens:
              type:
                - integer
                - 'null'
            finish_reason:
              type:
                - string
                - 'null'
        error:
          type:
            - string
            - 'null'
        attempts:
          type: array
          items:
            $ref: '#/components/schemas/Attempt'
        links:
          type: object
          properties:
            channel:
              type: string
              format: uri
            session:
              type: string
        wire:
          type:
            - string
            - 'null'
          description: >-
            Chat envelope version sent to the miner (`flop.chat-turn.v2` renders
            the model's chat template).
        reply:
          type:
            - object
            - 'null'
          description: >-
            The verified reply, for the wallet that owns the session (absent for
            other callers).
          properties:
            role:
              const: assistant
            content:
              type: string
            finish_reason:
              type:
                - string
                - 'null'
        reply_visible:
          type: boolean
        ignored_parameters:
          type: array
          items:
            type: string
          description: >-
            Request parameters this model ignored (see its
            supported_parameters).
    Error:
      type: object
      description: >-
        `code` is the HTTP status; `metadata.reason` is floprouter's specific
        reason.
      properties:
        error:
          type: object
          required:
            - code
            - message
          properties:
            code:
              type: integer
              examples:
                - 400
                - 401
                - 402
                - 403
                - 404
                - 408
                - 409
                - 413
                - 429
                - 502
                - 503
            message:
              type: string
            metadata:
              type: object
              properties:
                reason:
                  type: string
                  examples:
                    - insufficient_balance
                    - grant_expired
                    - all_attempts_failed
                    - no_provider_supports_parameters
                    - tools_not_supported
                    - model_not_found
                    - rate_limited
                    - withdrawal_in_progress
                session_id:
                  type: string
              additionalProperties: true
    Attempt:
      type: object
      description: One try on one miner. Every attempt is recorded.
      properties:
        'n':
          type: integer
        miner:
          type: string
        endpoint:
          type:
            - string
            - 'null'
        via:
          type:
            - string
            - 'null'
        channel_id:
          type:
            - string
            - 'null'
        escrow:
          type:
            - string
            - 'null'
          description: Decimal amount in FLOP.
          examples:
            - '0.01'
        status:
          type: string
        stage:
          type:
            - string
            - 'null'
        error:
          type:
            - string
            - 'null'
        outcome:
          type:
            - string
            - 'null'
        miner_paid:
          type:
            - string
            - 'null'
          description: Decimal amount in FLOP.
          examples:
            - '0.01'
        refunded:
          type:
            - string
            - 'null'
          description: Decimal amount in FLOP.
          examples:
            - '0.01'
        open_block:
          type:
            - integer
            - 'null'
        outcome_block:
          type:
            - integer
            - 'null'
        outcome_tx:
          type:
            - string
            - 'null'
        first_output_ms:
          type:
            - integer
            - 'null'
        recovery:
          type: array
          items:
            type: object
          description: >-
            Recovery extrinsics sent for this channel (expire_force_open,
            timeout, force_settle, finalize).
  responses:
    E400:
      description: Invalid request
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: 400
              message: >-
                each message needs a role of system, developer, user or
                assistant (tool messages are not supported)
              metadata:
                reason: invalid_message
    E401:
      description: Missing or invalid key
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: 401
              message: >-
                a wallet API key is required (Authorization: Bearer fr_...); see
                POST /v1/auth/challenge
              metadata:
                reason: unauthorized
    E402:
      description: The payer cannot cover this request
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: 402
              message: >-
                prepaid balance 0 FLOP available cannot cover 0.0105 FLOP
                (escrow plus router fee); send FLOP to the deposit address, see
                GET /v1/balance
              metadata:
                reason: insufficient_balance
                available: '0'
                required: '0.0105'
                session_id: gen-mwu3pgp7-1130f87d046b
    E403:
      description: >-
        The request did not come through the public endpoint (origin header
        missing or wrong)
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: 403
              message: requests must come through the public endpoint
              metadata:
                reason: forbidden
    E404:
      description: Not found
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: 404
              message: no such session
              metadata:
                reason: session_not_found
    E413:
      description: Body too large
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: 413
              message: request body exceeds 524288 bytes
              metadata:
                reason: body_too_large
    E429:
      description: Rate limit, concurrency cap, grant daily cap or demo budget
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: 429
              message: 'chat requests for this key: limit 20 per minute; retry in 41 s'
              metadata:
                reason: rate_limited
      headers:
        Retry-After:
          schema:
            type: integer
          description: Seconds to wait.
    E503:
      description: >-
        No provider could complete the request, or the service is restarting.
        Not 502: client SDKs retry 502 at once, and each retry can cost an
        on-chain fee.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: 503
              message: >-
                no miner completed the request after 1 attempt(s):
                5HKiGNFSqSyEMVMjjr8JBKkkppytaqFZCRm27KGbCeHhUq92:
                computeChannel.MinerCapacityFullyReserved: D-0542: the miner's
                live capacity reservations leave no room for this channel's
                rate.
              metadata:
                reason: all_attempts_failed
                session_id: gen-mwu3pgp7-1130f87d046b
      headers:
        Retry-After:
          schema:
            type: integer
          description: Seconds to wait.
  securitySchemes:
    bearer:
      type: http
      scheme: bearer
      description: Wallet API key `fr_...` from `POST /v1/auth/keys`.

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.