Supported endpoints
| Endpoint | Streaming |
|---|---|
POST /v1/chat/completions | Yes |
POST /v1/completions | Yes |
POST /v1/audio/speech | Yes |
POST /v1/audio/transcriptions | Yes |
Python SDK
Passstream=True to receive an iterator of chunks:
cURL
Set"stream": true in the request body:
-N flag disables buffering so chunks arrive as they are sent.
Response format
Each SSE line is adata: event containing a JSON object. A typical chunk looks like:
Tool calling with streaming
When using tools, streamed chunks may includedelta.tool_calls with partial function arguments. Accumulate tool call fragments across chunks before invoking functions.
See Tool calling for a complete example.
Error handling
If an error occurs mid-stream, the connection may close with a non-200 status before[DONE]. Wrap streaming loops in try/except and implement retry logic with exponential backoff for transient 429 or 500 responses.
See API overview and Troubleshooting for error details.
Production tips
- Set reasonable
max_tokensto bound latency and cost. - Use Always ready or Super fast readiness for user-facing streaming to avoid first-token delay from cold starts.
- Implement client-side timeouts and cancellation (close the HTTP connection to stop generation when the user navigates away).

