API reference
Responses as they happen.
Receive incremental output through Server-Sent Events.
Enable streaming
#Set stream: true in a supported generation request. The gateway forwards events incrementally and keeps the selected upstream connection for the life of the stream.
with client.responses.stream(
model="gpt-5.6-terra",
input="Write a short welcome message.",
) as stream:
for event in stream:
if event.type == "response.output_text.delta":
print(event.delta, end="", flush=True)Handle complete events
#An SSE event ends with a blank line. Network chunks do not necessarily align with events or UTF-8 characters. Use an SDK or an incremental SSE parser rather than treating every received chunk as complete JSON.
- Responses streams use response lifecycle events.
- Chat Completions streams send data events and a
[DONE]marker. - Messages streams use Anthropic event names, including content-block and message lifecycle events.
- A stream can begin successfully and later report an error. Check its completion event and error events.
Timeouts, cancellation and retries
#Closing the client connection cancels the upstream stream. Reported token usage is recorded. If final usage is missing, the credit hold remains pending reconciliation; cancellation does not guarantee a free request.
Do not blindly replay a started request
Rolling updates allow existing streams to drain before an instance stops. Network, host or provider failures can still interrupt a connection; applications should handle incomplete output.