A streaming request does not make an AI API faster or more reliable. It changes when you can start using the output. When you set stream=true, the provider begins sending the model’s output as it is generated instead of generating the entire response and returning it in one HTTP response. That is valuable for perceived latency and for long generations, but it also creates three questions your client previously did not have to answer: how do I know the answer is finished, what do I do with the piece I already have, and which of my several deadlines just fired?
This article is for developers, automation builders, and technically curious practitioners who already make API calls and are now wiring streaming into a user-facing app, a scheduled WordPress job, or a local inference workflow. It focuses on the mechanics that are easy to get wrong: terminal events, partial output, and timeout classification.
What streaming changes, and what it does not
By default, an OpenAI API request generates the model’s entire output before sending it back in a single HTTP response. Streaming responses let you start printing or processing the beginning of the model’s output while it continues generating the full response. The standard mechanism is HTTP streaming with stream=true over server-sent events (SSE). The Responses API also offers a WebSocket mode for persistent transport with incremental inputs via previous_response_id.
Turning it on is a small change to an existing request. The Python example below follows the pattern in the official streaming guide, with a completion check added:
from openai import OpenAI
client = OpenAI()
stream = client.responses.create(
model="gpt-6-astra",
input=[{"role": "user", "content": "Summarize this changelog."}],
stream=True,
)
completed = False
for event in stream:
# Attribute names vary by SDK version; check your installed client.
if event.type == "response.completed":
completed = True
print(event)
if not completed:
raise RuntimeError("stream ended without response.completed")What does not change is the number of parties holding a stopwatch. Your client, any reverse proxy or edge platform in the path, and the provider all keep their own deadlines. Streaming is a delivery mechanism, not a guarantee of completion.
The terminal event is the only proof of completion
Text deltas are a display convenience, not a success signal. OpenAI Responses emits a response.completed event for a successful completed response. Anthropic’s Messages API ends a normal SSE sequence with message_stop. Text deltas that arrive before those events are useful for display and for recovery, but they do not prove the request completed.
The practical rule: treat a stream without the provider’s successful terminal event as incomplete. If the socket closes early, preserve the partial text for diagnosis, but mark the attempt as failed. Scoring a truncated answer as if it were complete silently rewards transport failures, and in an evaluation or logging pipeline it corrupts exactly the data you would use to find the real cause.
Reading the stream format without guessing
SSE is a line-oriented text protocol: a set of field lines (event:, data:, id:, retry:) terminated by a blank line forms one event. Implementations differ in what they put in those fields. Some providers use named events, some emit a sentinel value at the end, and some send comment lines as keep-alives. Read the framing your provider documents rather than assuming the shape of the last chunk, and do not assume the final chunk is a complete JSON object.
Three deadlines, not one
Most “the streaming API timed out” reports collapse several distinct failures into one label. They have different causes and different fixes:
- Connection timeout — fires before a usable response is established. Nothing has been generated for you yet.
- Idle-read timeout — fires after the response has started but no bytes arrive for too long. The stream may still be alive on the provider side.
- Overall deadline — stops the request even if chunks continue to arrive normally.
Raising one value does not repair the other two. A client with a generous idle-read timeout will still be cut off by a hard 60-second cap at the edge, and a client with no overall deadline will still hang when a proxy silently drops the connection.
Diagnosing a stream that stops early
Work from cheap, low-impact observations toward configuration changes. Each step narrows which layer is responsible.
- Confirm the terminal event is missing. Log every event type you receive. If
response.completedormessage_stopnever appears, the attempt is incomplete regardless of how much text arrived. - Record four timestamps per attempt: when the request started, when headers arrived, when the first event arrived, and when the last event arrived. Keep the endpoint, protocol, model, effort setting, status code, and attempt number alongside them.
- Compare wall-clock duration across attempts. If several runs end at nearly the same elapsed time — say 89.9, 90.1, and 90.0 seconds — suspect an absolute request cap somewhere in the path rather than an idle timeout or a slow model.
- Distinguish a gap from a cut. An idle-read timeout usually shows a pause with no bytes, then an error. An overall deadline or proxy cap shows steady traffic that stops abruptly at a fixed time.
- Check the transport path. The same request may behave differently through your library, a reverse proxy, an edge platform, and the provider. Reverse proxies sometimes buffer responses by default; if your client receives nothing until the very end, that is a buffering configuration issue, not a model issue.
- Inspect error events and status codes. A stream can carry an error event before the socket closes. Capture it; do not reduce every transport failure to “network error.”
- Only then tune retries. Retry settings cannot fix a hard cap enforced by another layer.
Handling partial output responsibly
Partial output is useful, but only if you keep it separate from committed results.
- Buffer before you commit. Write deltas to a display buffer, and only promote the buffer to a stored answer when the terminal event arrives.
- Mark incomplete text as incomplete. If you persist partial output for diagnostics, label it as truncated. Never let a downstream automation treat it as final.
- Be careful with structured output. A JSON payload that arrives in pieces is not valid JSON until it is complete. Either wait for the terminal event before parsing, or use an incremental parser that tolerates an open structure — and still validate the finished object.
- Decide the user-facing behaviour in advance. Showing tokens as they arrive is usually fine in a chat interface. Silently saving a half-finished summary into a WordPress post is not.
Retries, resumption, and duplicate work
Retry only a bounded number of times, and record each attempt so that a flapping endpoint is visible in your logs rather than invisible in your error rate. Exponential backoff with jitter is the conventional pattern for transient failures.
The harder problem is side effects. If the partial stream already triggered a tool call, sent a notification, or wrote a draft, a blind retry can duplicate that work. Where possible, make the retried unit idempotent, or split generation from execution so that only the generation step is retried.
For resumption, the Responses API documents a WebSocket mode with incremental inputs via previous_response_id. Treat that as a transport feature to verify against your provider’s current documentation rather than an assumption you can carry across vendors; resumption semantics differ between HTTP streaming and persistent transports.
Proxy and edge limits you cannot stream past
Streaming cannot override an absolute proxy limit. Regular events can prevent an idle connection from looking dead, but they cannot extend an absolute request cap enforced by a client, reverse proxy, edge platform, or the provider itself. When a request repeatedly ends at nearly the same wall-clock time, inspect those layers instead of assuming the model is slow or the network is unstable.
The practical consequence: for genuinely long generations, the fix is usually architectural — raise the cap at the layer that enforces it, or split the work into smaller requests that each finish comfortably inside every deadline in the path.
An illustrative failure walkthrough
The following scenario is a constructed example, not an observed test result, and is included to show how the diagnostic order applies.
A nightly WordPress job summarizes new posts through a streaming API call. One run ends after roughly 90 seconds with no response.completed event. The timing log shows headers at 0.4 s, first event at 1.1 s, last event at 89.8 s. Three earlier runs ended at 89.9 s, 90.1 s, and 90.0 s. Because the end times cluster tightly and bytes flowed steadily until the cut, an absolute 90-second cap somewhere in the request path is the leading hypothesis — not an idle-read timeout, which would show a silent gap before failure. The next checks would be the reverse proxy’s request timeout, the hosting platform’s execution limit, and the client library’s own deadline, in that order.
When streaming is the wrong choice
Streaming adds state to your client: buffers, terminal-event handling, partial-output policy, and a second class of timeout to reason about. For short outputs, batch jobs that only need the final result, or pipelines where a downstream consumer cannot tolerate partial state, a normal non-streaming request is simpler and easier to make correct. Choose streaming when the perceived latency or the length of the generation justifies the extra bookkeeping.
The first change to make
Before tuning timeouts or retry counts, add two things: a check that the provider’s terminal event arrived, and a timing log with request start, headers, first event, and last event. That single change converts most vague “the model is flaky” reports into a specific layer with a specific fix. If you have a stream that dies at a suspiciously round number of seconds, share the endpoint type, transport path, and your four timestamps in the community — that evidence is usually enough for other practitioners to identify the layer enforcing the cap.
FAQ
Do text deltas mean the request succeeded?
No. Only the provider's terminal event — response.completed for OpenAI Responses, message_stop for Anthropic Messages — indicates a successful completed response. Deltas are useful for display and recovery but do not prove completion.
Can streaming prevent a proxy from timing out my request?
No. Regular events can stop an idle connection from looking dead, but they cannot extend an absolute request cap enforced by a client, reverse proxy, edge platform, or provider. If requests repeatedly end at nearly the same wall-clock time, inspect those layers.
How do I tell which timeout fired?
Log when the request started, when headers arrived, when the first event arrived, and when the last event arrived. A silent gap before failure points to an idle-read timeout; steady traffic ending at a consistent elapsed time points to an absolute deadline or proxy cap.
Should I retry after receiving partial output?
Retry only a bounded number of times and record each attempt. Before retrying, consider whether the partial stream already caused a side effect such as a tool call or notification, and make the retried unit idempotent where possible.