Streaming
All LLM endpoints support "stream": true and speak their protocol's SSE format. The proxy translates the upstream stream on the fly, so a client always sees the wire format it asked for.
SSE basics
Every streaming response uses:
Content-Type: text/event-stream
Cache-Control: no-cache
Connection: keep-alive
Access-Control-Allow-Origin: *Heartbeats: whenever the upstream is silent for the keepalive interval (default 15 s), the proxy emits an SSE comment frame:
: keep-aliveSSE parsers ignore comments by definition, so no client action is required. Disable buffering in your reverse proxy or the heartbeats (and tokens) will pile up behind it.
OpenAI Chat Completions
data: {"id":"chatcmpl-…","object":"chat.completion.chunk","model":"auto","choices":[…],"usage":null}
data: {"id":"chatcmpl-…","object":"chat.completion.chunk","choices":[],"usage":{"prompt_tokens":…,"completion_tokens":…,"total_tokens":…}}
data: [DONE]- The
modelfield in chunks is the model the client requested (e.g.auto), not the upstream model. - A final usage-only chunk is emitted when the upstream supplied usage (relocated to the end of the stream, before
data: [DONE]); if the upstream sent none, no usage chunk appears. stream_optionsis not required from the client: the proxy requests usage from the upstream automatically and includes the final usage chunk when available.
stream = client.chat.completions.create(model="auto", messages=[...], stream=True)
for chunk in stream:
if chunk.choices and chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="")Anthropic Messages
Named events, no [DONE]; the stream simply ends:
event: message_start
data: {"type":"message_start","message":{…}}
event: content_block_start
event: content_block_delta
event: content_block_stop
event: message_delta ← carries stop_reason and usage
event: message_stopMid-stream failures arrive as event: error. Usage (including cache read/creation tokens) is reported in message_delta, where usage carries only the official MessageDeltaUsage keys, with no OpenAI-dialect prompt_tokens_details/total_tokens.
On the converted tier the upstream's own prompt count only arrives with message_delta, so message_start.usage.input_tokens carries the proxy's o200k-based estimate of the request (the same heuristic count_tokens falls back to) rather than zero. On the native tier the upstream value is forwarded untouched.
OpenAI Responses API
Every event's event: name equals its body type, and each event carries a sequence_number. Event families include:
response.created,response.in_progressresponse.output_item.added/.doneresponse.content_part.added/.doneresponse.output_text.delta/.doneresponse.reasoning_summary_part.added,response.reasoning_summary_text.delta/.doneresponse.function_call_arguments.delta/.doneresponse.refusal.delta/.doneresponse.completed(withresponse.usage),response.incompleteerror,response.failed
The terminal sentinel is data: [DONE]; the failure framing is response.failed followed by [DONE] (never a bare [DONE] without a status event).
Usage arrives in response.completed.response.usage: input_tokens, output_tokens, total_tokens, input_tokens_details.cached_tokens, output_tokens_details.reasoning_tokens.
Native passthrough streams
When an Anthropic or Responses request goes to a matching upstream provider, the stream is passed through directly. If the upstream ends without a [DONE] sentinel, the proxy appends one. Anthropic streams are the exception and end by closing the connection.
WebSocket transports
| Transport | Behavior |
|---|---|
WS /v1/responses | Same event objects as the SSE stream; client sends {"type":"response.create", …}. One in-flight response per connection, turns handled sequentially |
WS /v1/realtime | OpenAI Realtime relay. Requires ?model=<configured-model> with supports_realtime, and an openai/openai-compatible provider |
WebSocket limits: 64 MiB per message, 60-minute connection cap. Auth via Authorization/x-api-key header, ?api_key=, or (Realtime) openai-insecure-api-key.<key> subprotocol. Close codes differ per transport: /v1/responses only ever closes with 4401 (unauthorized; other failures arrive as error frames); the Realtime relay also uses 4403 forbidden (allowlist), 4004 invalid model, 4007 rate limited, and 1011 upstream failure.
Non-streaming keepalive
Long non-streaming responses are protected against CDN idle timeouts (Cloudflare 524) by the keepalive mechanism: after the grace period the proxy returns HTTP 200 and writes whitespace heartbeats until the response body is ready. Two consequences for clients:
- A failure after that point arrives as 200 + error JSON.
- Prefer
stream: truefor anything that can run for minutes; streaming avoids the tradeoff entirely.
Configuration and caveats: Reverse Proxy & TLS.
Disconnects
If the client goes away mid-stream, the upstream call is cancelled and the request is logged as 499; partial usage is still billed and counted.
The proxy only observes that the socket closed, never why: an SDK read timeout, a closed browser tab, proxy_read_timeout in nginx and a Cloudflare 524 are indistinguishable from the origin's side. The error text names Cloudflare because its 524 is the classic case, not because a CDN is involved.
A close that lands once the response is complete is a clean success, not a 499. The terminal [DONE] / message_stop frame is out, or the provider's last chunk was delivered with nothing left queued. SSE clients routinely drop the connection the moment they have what they came for. The response is still finalized for the request log and its reasoning cached, and a store: true response is still persisted, so a follow-up previous_response_id continuation keeps working.
Content-Type: text/event-stream
Cache-Control: no-cache
Connection: keep-alive
Access-Control-Allow-Origin: *: keep-alivedata: {"id":"chatcmpl-…","object":"chat.completion.chunk","model":"auto","choices":[…],"usage":null}
data: {"id":"chatcmpl-…","object":"chat.completion.chunk","choices":[],"usage":{"prompt_tokens":…,"completion_tokens":…,"total_tokens":…}}
data: [DONE]stream = client.chat.completions.create(model="auto", messages=[...], stream=True)
for chunk in stream:
if chunk.choices and chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="")event: message_start
data: {"type":"message_start","message":{…}}
event: content_block_start
event: content_block_delta
event: content_block_stop
event: message_delta ← carries stop_reason and usage
event: message_stop