Skip to main content

Streaming

Every text endpoint can stream tokens as they are generated. Set stream: true and read the response as Server-Sent Events (SSE). Streaming is a transport choice; it does not change how you are billed.

OpenAI-compatible (/v1/chat/completions, /v1/responses)​

curl https://gateway.primexos.com/v1/chat/completions \
-H "Authorization: Bearer prx-YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{ "model": "YOUR_MODEL", "stream": true,
"messages": [{"role":"user","content":"Stream a haiku."}] }'
  • /v1/chat/completions emits data: chunks whose choices[].delta carries the incremental text, then a final data: [DONE].
  • /v1/responses (native Responses models) emits typed events, ending with response.completed, which carries the final usage.

Any OpenAI SDK's streaming helper works unchanged against the Primex base URL.

Anthropic-compatible (/v1/messages)​

With stream: true, /v1/messages emits Anthropic's event sequence (message_start, content_block_delta, …, message_stop). The Anthropic SDK and Claude Code consume it directly.

Billing and broken-stream protection​

Usage is metered from the provider's reported token counts at the end of the stream, identical to a non-streamed request. A stream can open with 200 and then fail mid-flight carrying only a provider error frame; Primex detects that case and settles the request at $0 rather than charging an estimate. See Billing & Credits and Errors & Limits.

Client disconnects​

If you close the connection early, Primex cancels the upstream request, settles the call as a zero-charge 499 (CLIENT_ABORT), and releases its capacity slot. You are not billed for a stream you abandoned.