Guides

Streaming

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

View as Markdown

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