<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ace Brown</title>
    <description>The latest articles on DEV Community by Ace Brown (@acecoolguydev).</description>
    <link>https://dev.to/acecoolguydev</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4280958%2Fc25f9553-5b08-4c3f-87f7-8ba824858bcc.jpg</url>
      <title>DEV Community: Ace Brown</title>
      <link>https://dev.to/acecoolguydev</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/acecoolguydev"/>
    <language>en</language>
    <item>
      <title>Your AI API Returned 200 OK. Your User Got Half an Answer.</title>
      <dc:creator>Ace Brown</dc:creator>
      <pubDate>Fri, 04 Dec 2026 14:13:44 +0000</pubDate>
      <link>https://dev.to/acecoolguydev/your-ai-api-returned-200-ok-your-user-got-half-an-answer-5g9d</link>
      <guid>https://dev.to/acecoolguydev/your-ai-api-returned-200-ok-your-user-got-half-an-answer-5g9d</guid>
      <description>&lt;p&gt;Imagine this:&lt;/p&gt;

&lt;p&gt;You're building an AI chatbot. A user asks a question, the model starts responding, and everything looks fine.&lt;/p&gt;

&lt;p&gt;Your server logs show:&lt;/p&gt;

&lt;p&gt;200 OK&lt;/p&gt;

&lt;p&gt;Except the chatbot stopped halfway through its answer.&lt;/p&gt;

&lt;p&gt;No completed response. No obvious HTTP error. Just half a sentence and a confused user.&lt;/p&gt;

&lt;p&gt;Welcome to one of the more annoying parts of streaming LLM responses.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Wait, how can HTTP 200 be a failure?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When you use an LLM API with streaming enabled, the response arrives incrementally through Server-Sent Events (SSE).&lt;/p&gt;

&lt;p&gt;Instead of waiting for the entire answer, your application receives chunks as the model generates them.&lt;/p&gt;

&lt;p&gt;A successful stream might look something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="no"&gt;HTTP&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mf"&gt;1.1&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt; &lt;span class="no"&gt;OK&lt;/span&gt;

&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"choices"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"delta"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"content"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="s2"&gt;"Hello"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"choices"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"delta"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"content"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="s2"&gt;" world!"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"choices"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"delta"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s2"&gt;"finish_reason"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="s2"&gt;"stop"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="no"&gt;DONE&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;All good.&lt;/p&gt;

&lt;p&gt;But what happens if the connection drops halfway through?&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight http"&gt;&lt;code&gt;&lt;span class="no"&gt;HTTP&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mf"&gt;1.1&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt; &lt;span class="no"&gt;OK&lt;/span&gt;

&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"choices"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"delta"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"content"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="s2"&gt;"Hello"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"choices"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"delta"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"content"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="s2"&gt;" wor"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;[Connection lost]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The HTTP status is still 200.&lt;/p&gt;

&lt;p&gt;That's because the server already sent the response headers. It can't suddenly go back and change the status to 500.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;HTTP 200 tells you the request successfully started returning a response. It doesn't guarantee the stream actually finished.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;And if your monitoring only checks HTTP status codes, you might miss this entirely.&lt;/p&gt;

&lt;p&gt;So I built something to catch it&lt;/p&gt;

&lt;p&gt;I've been working on Tensorstand, an open-source, self-hosted AI gateway for OpenAI and Anthropic.&lt;/p&gt;

&lt;p&gt;One of the things I wanted to get right was knowing whether a streamed response actually completed.&lt;/p&gt;

&lt;p&gt;Rather than relying entirely on HTTP status codes, Tensorstand tracks the stream's lifecycle.&lt;/p&gt;

&lt;p&gt;That includes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Whether the stream completed or was interrupted.&lt;/li&gt;
&lt;li&gt;Time to first content.&lt;/li&gt;
&lt;li&gt;How many chunks were forwarded.&lt;/li&gt;
&lt;li&gt;The last recognized provider event.&lt;/li&gt;
&lt;li&gt;Where the request failed.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For example, a request could produce a diagnostic record like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;"status_code"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"stream_outcome"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"incomplete"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"chunks_forwarded"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="nl"&gt;"error_code"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"UPSTREAM_TIMEOUT"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we've got a much clearer picture.&lt;/p&gt;

&lt;p&gt;The HTTP request started successfully, four chunks were forwarded, and the stream eventually timed out.&lt;/p&gt;

&lt;p&gt;That's very different from a fully completed request.&lt;/p&gt;

&lt;p&gt;And importantly, the gateway doesn't need to log your actual prompts or generated responses to capture those diagnostics.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The tricky part: what do you do after HTTP 200?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This was one of the more interesting implementation challenges.&lt;/p&gt;

&lt;p&gt;If an upstream provider returns HTTP 429 before streaming starts, the gateway can return a normal error response.&lt;/p&gt;

&lt;p&gt;Easy enough.&lt;/p&gt;

&lt;p&gt;But once the gateway has started sending chunks to the client, things get more complicated.&lt;/p&gt;

&lt;p&gt;If the upstream stream fails, you can't just replace the response with a JSON error.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;That makes blindly retrying an interrupted request potentially expensive.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;To test this, I built a small reproducible demo using a simulated AI provider.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It demonstrates three scenarios:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Normal completion: The provider finishes streaming successfully.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Interrupted stream: The provider begins responding, then the stream terminates before completion.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Rate limiting: The provider returns HTTP 429 before the stream begins.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The demo exercises Tensorstand's actual diagnostic behavior, and it doesn't require paid AI API calls.&lt;/p&gt;

&lt;p&gt;You can check out the code and demo instructions here:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/AceCoolGuyDev/Tensorstand-AI" rel="noopener noreferrer"&gt;GitHub — Tensorstand AI&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Is this something you've run into?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Tensorstand is still an early project I'm building solo, and I'm definitely not claiming other gateways haven't addressed this.&lt;/p&gt;

&lt;p&gt;But working through streaming failures made me realize how much useful information can get lost when you're only tracking request-level status codes.&lt;/p&gt;

&lt;p&gt;I'm curious how other people building LLM applications handle this.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Do you explicitly check that streams finish successfully, or do you mostly rely on whatever errors your SDK throws?&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>api</category>
      <category>llm</category>
      <category>streaming</category>
    </item>
  </channel>
</rss>
