Skip to Content
Docs

Features

Streaming

Text as the miner decodes it, how it is verified, and what the stream carries.

"stream": true returns server-sent events of chat.completion.chunk objects, ending with data: [DONE]. 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 :, such as : FLOPROUTER PROCESSING) 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 (it repeats finish_reason in choices),
  5. data: [DONE].
import json, os, requests

with requests.post(
    "https://api.floprouter.com/v1/chat/completions",
    headers={"Authorization": f"Bearer {os.environ['FLOPROUTER_API_KEY']}"},
    json={"model": "qwen/qwen3-8b", "messages": [{"role": "user", "content": "Hello"}], "stream": True},
    stream=True,
    timeout=300,
) as res:
    for line in res.iter_lines(decode_unicode=True):
        if not line or not line.startswith("data: "):
            continue  # blank lines and ': keep-alive' comments
        data = line[6:]
        if data == "[DONE]":
            break
        chunk = json.loads(data)
        if "error" in chunk:
            raise RuntimeError(chunk["error"])
        for choice in chunk.get("choices", []):
            print(choice["delta"].get("content", ""), end="", flush=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.

Errors after the stream started Not live yet

A mid-stream error arrives as one chunk with a top-level error (code, message, metadata) and choices: [{"delta": {"content": ""}, "finish_reason": "error"}]. The stream ends after it, with no [DONE]. The reason is in error.metadata.reason, and for stream_mismatch the verified text is in error.metadata.verified_content.

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). 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.