Skip to main content
Streaming returns model output as it is generated. Set stream: true, process each event in order, and close the response when the terminal event arrives.

OpenAI Chat Completions

Direct HTTP responses use Server-Sent Events:
Each event starts with data:. The final event is data: [DONE]. A final usage chunk may have an empty choices array.

Anthropic Messages

Anthropic streams typed events including message_start, content_block_delta, message_delta, and message_stop. Use the official SDK to assemble content blocks and tool inputs.

Disconnects and retries

A disconnected stream may already have produced billable tokens. Do not append a blind retry to the partial assistant message.
  1. Record whether the terminal event was received.
  2. If no user-visible output was consumed, retry with exponential backoff and jitter.
  3. If partial output was consumed, either show it as interrupted or restart the turn as a new request.
  4. For 429, honor Retry-After before retrying.
  5. Do not retry 400 or 401 until the request or credential is corrected.
Use a stable prompt_cache_key for repeated turns in one OpenAI conversation. This improves cache affinity but does not make a request idempotent.
Last modified on September 9, 2026