Imagine this:
You're building an AI chatbot. A user asks a question, the model starts responding, and everything looks fine.
Your server logs show:
200 OK
Except the chatbot stopped halfway through its answer.
No completed response. No obvious HTTP error. Just half a sentence and a confused user.
Welcome to one of the more annoying parts of streaming LLM responses.
Wait, how can HTTP 200 be a failure?
When you use an LLM API with streaming enabled, the response arrives incrementally through Server-Sent Events (SSE).
Instead of waiting for the entire answer, your application receives chunks as the model generates them.
A successful stream might look something like this:
HTTP/1.1 200 OK
data: {"choices":[{"delta":{"content":"Hello"}}]}
data: {"choices":[{"delta":{"content":" world!"}}]}
data: {"choices":[{"delta":{},"finish_reason":"stop"}]}
data: [DONE]
All good.
But what happens if the connection drops halfway through?
HTTP/1.1 200 OK
data: {"choices":[{"delta":{"content":"Hello"}}]}
data: {"choices":[{"delta":{"content":" wor"}}]}
[Connection lost]
The HTTP status is still 200.
That's because the server already sent the response headers. It can't suddenly go back and change the status to 500.
HTTP 200 tells you the request successfully started returning a response. It doesn't guarantee the stream actually finished.
And if your monitoring only checks HTTP status codes, you might miss this entirely.
So I built something to catch it
I've been working on Tensorstand, an open-source, self-hosted AI gateway for OpenAI and Anthropic.
One of the things I wanted to get right was knowing whether a streamed response actually completed.
Rather than relying entirely on HTTP status codes, Tensorstand tracks the stream's lifecycle.
That includes:
- Whether the stream completed or was interrupted.
- Time to first content.
- How many chunks were forwarded.
- The last recognized provider event.
- Where the request failed.
For example, a request could produce a diagnostic record like this:
{
"status_code": 200,
"stream_outcome": "incomplete",
"chunks_forwarded": 4,
"error_code": "UPSTREAM_TIMEOUT"
}
Now we've got a much clearer picture.
The HTTP request started successfully, four chunks were forwarded, and the stream eventually timed out.
That's very different from a fully completed request.
And importantly, the gateway doesn't need to log your actual prompts or generated responses to capture those diagnostics.
The tricky part: what do you do after HTTP 200?
This was one of the more interesting implementation challenges.
If an upstream provider returns HTTP 429 before streaming starts, the gateway can return a normal error response.
Easy enough.
But once the gateway has started sending chunks to the client, things get more complicated.
If the upstream stream fails, you can't just replace the response with a JSON error.
Instead, you need to detect that the stream didn't complete, avoid sending a fake successful termination, clean up the connection, and record what actually happened.
There's also the question of billing. If a provider times out after processing part of a request, you can't automatically assume it wasn't charged.
That makes blindly retrying an interrupted request potentially expensive.
To test this, I built a small reproducible demo using a simulated AI provider.
It demonstrates three scenarios:
Normal completion: The provider finishes streaming successfully.
Interrupted stream: The provider begins responding, then the stream terminates before completion.
Rate limiting: The provider returns HTTP 429 before the stream begins.
The demo exercises Tensorstand's actual diagnostic behavior, and it doesn't require paid AI API calls.
You can check out the code and demo instructions here:
Is this something you've run into?
Tensorstand is still an early project I'm building solo, and I'm definitely not claiming other gateways haven't addressed this.
But working through streaming failures made me realize how much useful information can get lost when you're only tracking request-level status codes.
I'm curious how other people building LLM applications handle this.
Do you explicitly check that streams finish successfully, or do you mostly rely on whatever errors your SDK throws?
Top comments (0)