Documentation › The endpoint

Streaming

stream true is accepted. Where streamed calls are enabled, the answer arrives as the model writes it and the passport follows at the end of the stream. Otherwise the answer waits for its passport and is then sent as a stream.

What you get#

A request with "stream": true is accepted. The answer arrives as a server-sent event stream (text/event-stream) of chat.completion.chunk objects, closed by data: [DONE], as OpenAI clients expect.

stream = client.chat.completions.create(
    model="provider/model-name",
    messages=messages,
    stream=True,
)
for chunk in stream:
    if chunk.choices and chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="")

There are two ways a stream is delivered.

WayWhenWhat it means
Answer firstWhere streamed calls are enabled, for a model whose supports.streaming is "live", unless you ask for passport firstThe model's text is passed on as it is written. The passport follows at the end of the stream
Passport firstYou send X-OSPP-Stream: passport-first; or the model's supports.streaming is "replayed"; or streamed calls are not enabledThe answer waits for its passport. It is then sent as a stream, with the passport in the response headers

Whether streamed calls are enabled is a setting of the OSPP installation you call. Do not build on it being on: read the response headers to see which way an answer came. supports.streaming of each model is in GET /models; see models.

Do not build on the timing or the size of the chunks either: an answer may arrive in few chunks or in many.

Answer first#

The response headers arrive before the model has answered, so they cannot carry a passport id:

Response headerValue
X-OSPP-RunThe run id of this call
X-OSPP-NodeThe node and version the call is counted under
X-OSPP-Outcome-URLThis call's outcome address
X-OSPP-Passport-Statuspending

The first chunk has an empty assistant delta and an ospp object with the run id:

data: {"id": "chatcmpl-...", "object": "chat.completion.chunk", "choices": [{"index": 0, "delta": {"role": "assistant", "content": ""}, "finish_reason": null}], "ospp": {"run_id": "...", "node": "support-bot@3f9a1c2b7d10", "node_family": "support-bot", "passport_status": "PENDING", "outcome_url": "..."}}

Then the model's text arrives, chunk by chunk, as it is written.

The last chunk, the one that carries finish_reason, has the full ospp object. OSPP waits about ten seconds after the answer for the passport:

  • issued in that time: ospp.passport_id, ospp.verify_url and ospp.passport_file_url are set and passport_status is CERTIFIED;
  • not issued yet: passport_id is null and passport_status is PENDING. Read the passport later with GET /v1/runs/{run_id}; see responses.
data: {"id": "chatcmpl-...", "object": "chat.completion.chunk", "choices": [{"index": 0, "delta": {}, "finish_reason": "stop"}], "ospp": {"run_id": "...", "passport_id": "...", "passport_status": "CERTIFIED", "verify_url": "...", "passport_file_url": "...", "outcome_url": "..."}}

data: [DONE]

With the openai Python client, extra fields of a chunk are on the parsed object: chunk.model_extra.get("ospp").

If the live stream breaks off part way, OSPP sends a line of text saying so and then the complete recorded answer in one chunk. If nothing came through live, the complete answer is sent in one chunk. The recorded answer is the one that counts.

Passport first#

Send the header X-OSPP-Stream: passport-first with a streamed request when your application needs the passport before it shows the answer:

stream = client.chat.completions.create(
    model="provider/model-name",
    messages=messages,
    stream=True,
    extra_headers={"X-OSPP-Stream": "passport-first"},
)

The model is then called without streaming. When the passport is issued, the whole answer is sent as a stream: one chunk with the content, then the chunk with finish_reason and the full ospp object. The response headers are those of a call without streaming, X-OSPP-Passport, X-OSPP-Verify-URL and X-OSPP-Passport-File included; see responses. Your client waits for the first byte as long as the whole call takes.

Models with supports.streaming "replayed" always behave this way, with or without the header (today no model is listed that way: OpenAI-compatible providers and Anthropic models are both "live"). So does every model where streamed calls are not enabled.

If the passport is not issued within the wait of a normal answer, the stream carries X-OSPP-Passport-Status: pending and passport_status: PENDING instead, as described in responses.

Streaming and versions#

Where an answer is streamed live, stream is one of the parameters of the node's definition. A streamed call and an unstreamed call of the same model and system prompt are therefore two versions of the same node; their figures stay under that node.

Usage#

Send "stream_options": {"include_usage": true} to receive one more chunk with the token usage before [DONE], as in the OpenAI API.

Tool calls#

Tool calls are delivered in the stream in OpenAI's chunk format, and the last chunk has finish_reason: "tool_calls". See tool calling.

Errors#

A request that is refused gets a normal JSON error response, not a stream. So does a passport-first call that ends without a passport. See errors.

An answer-first stream has already started when the call ends. If the call then fails, the stream carries one event with an error object in the usual shape and ospp.run_id, followed by data: [DONE]:

data: {"error": {"message": "the run ended FAILED: ...", "type": "api_error", "param": null, "code": "run_failed"}, "ospp": {"run_id": "..."}}

data: [DONE]

Self-hosted#

The local proxy of a self-hosted organisation accepts "stream": true and sends the finished answer as a stream. It does not stream live. See the local proxy.