Skip to main content

Overview

Streaming delivers model output in small events instead of waiting for the full answer. Use Responses streaming for a model that lists responses in accepted_request_formats; keep Chat Completions streaming when that is what your SDK or application already expects.

Responses streaming

Responses SSE keeps the documented event names, order, and fields. After the first event arrives, an interrupted stream is incomplete and is not restarted automatically.

Responses WebSocket

Connect to wss://api.tokenlab.sh/v1/responses and send response.create events. WebSocket responses are always streamed and do not support background or response.cancel. A response.create with generate: false returns an ID that can be continued without generating model output or creating a model charge. Each connection handles one active response at a time and lasts up to 60 minutes. Events include a response-scoped sequence_number. Stream events named error use a flat event object; connection and protocol failures use a nested error object.

Chat Completions Streaming

If your framework still expects SSE chunks from /v1/chat/completions, that also works:

Gemini Streaming

POST /v1beta/models/{model}:streamGenerateContent?alt=sse returns Gemini chunks. An event can contain only metadata, intermediate events may omit finishReason, and the stream can end naturally without a Chat Completions [DONE] marker.

Stream End Conditions

Typical completion conditions:
  • response.completed for Responses API streams
  • finish_reason: "stop" for Chat Completions streams
  • finish_reason: "length" when a token limit is hit
  • tool/function call events when the model wants to use tools

Web App Pattern

Handle streams well

Use Responses streaming when the selected model and your client support it. Existing Chat Completions streaming code can stay on /v1/chat/completions.
Append delta chunks to the UI or terminal as they arrive rather than waiting for the full response.
Preserve the partial output if it is useful, but do not mark it as complete. Repeating a request may produce different output and another charge.