What you'll get from this post
- A reusable playbook for diagnosing streaming issues: first-token probe → comparison sweep → cracking open the raw SSE frames. Next time someone says "the AI endpoint is slow," you'll know what to measure first and where to dig next
- A mental model: the two-hop architecture of an AI request — and why the missing SSE EventStream panel in DevTools doesn't mean nothing is streaming
- A concrete takeaway: reasoning models ship with thinking enabled by default, and generic adapters silently drop vendor dialect fields — stack the two and your users see a frozen UI
This is a full postmortem of a real production incident. Every numbered experiment can be reproduced with a single command in the companion repo ai-sdk-streaming-lab.
Background: the feature that blew up
Let's put the offending code on the table first — everything else revolves around it.
The feature is an "AI summary for sales follow-up notes" in a CRM: a rep pastes a meeting transcript into a textbox, and the AI condenses it into a summary of 150 characters or less and extracts action items along the way. The stack is Next.js + the Vercel AI SDK, with DeepSeek as the model.
The server side is a standard streamObject route — hand it a zod schema and have the model stream back structured JSON:
// app/api/notes/analyze/route.ts
import { streamObject } from "ai";
import { createOpenAI } from "@ai-sdk/openai";
import { z } from "zod";
// We connect through the AiHubMix gateway (a multi-model aggregator that only
// speaks the OpenAI protocol), so the vendor-specific package (@ai-sdk/deepseek)
// is off the table — we point the generic OpenAI adapter at it instead
const deepseek = createOpenAI({
baseURL: "https://aihubmix.com/v1",
apiKey: process.env.AIHUBMIX_API_KEY!,
});
const noteSchema = z.object({
summary: z.string().describe("Summary, 150 characters or less"),
todos: z.array(
z.object({
action: z.string(),
dueDate: z.string().nullable().describe("YYYY-MM-DD or null"),
}),
),
});
export async function POST(req: Request) {
const { content } = await req.json();
const result = streamObject({
model: deepseek.chat("deepseek-v4-pro"),
schema: noteSchema,
system: "You are a CRM assistant. Extract a summary and action items from sales follow-up notes.",
prompt: content,
});
return result.toTextStreamResponse(); // stream the model output back to the browser
}
The frontend consumes the stream with the companion useObject hook — the object "fills in" progressively and renders as it streams:
// Frontend component (excerpt)
import { experimental_useObject as useObject } from "@ai-sdk/react";
const { object, submit, isLoading } = useObject({
api: "/api/notes/analyze",
schema: noteSchema,
});
// object.summary grows incrementally: "Met" → "Met with the client..." — bind it straight to the UI
Two pieces of infrastructure context — they're the variables in the comparison sweep later, so let's get them out of the way now:
| Context | Details |
|---|---|
| Two model tiers | DeepSeek comes in flash (fast, cheap) and pro (million-token context). Short inputs go to flash; the 10,000+-character transcript of an hour-long meeting blows past flash's context window, so it goes to pro |
| Two access paths | One through AiHubMix (multi-model gateway, OpenAI protocol, centralized key management and billing for the team); one direct to DeepSeek's official API. The incident happened on the gateway path |
Short-text testing looked perfectly fine, and the feature shipped.
Symptom: a streaming endpoint, tens of seconds of nothing
A user pasted the 10,000+-character transcript of an hour-long meeting and hit save — the UI froze for tens of seconds, then all the text suddenly gushed out at once. The bug report said "I waited 50-something seconds" (perceived time, including retries and the entire save flow); reproducing with the same transcript, we consistently saw 15-20 seconds of dead silence followed by a flood. All numbers below come from our reproduction.
Everyone's first instinct is the same: "Is it even really streaming? Is it faking a typewriter effect after the request finishes?" — don't guess, measure it. Paste this into the frontend and timestamp every chunk of the response stream:
const body = JSON.stringify({ content: transcript }); // 11,430-character meeting transcript
const res = await fetch("/api/notes/analyze", { method: "POST", body });
const reader = res.body!.getReader();
const t0 = performance.now(), marks: number[] = [];
while (true) {
const { done, value } = await reader.read();
if (done) break;
marks.push(Math.round(performance.now() - t0)); // arrival time of each chunk
}
console.log({ ttftMs: marks[0], chunkCount: marks.length, totalMs: marks.at(-1) });
The actual measurements (numbers untouched):
(We're measuring when the first content chunk arrives, hence time-to-first-token, TTFT — don't confuse it with HTTP's TTFB. In streaming, the response headers can come back instantly while the content takes forever.)
These numbers immediately rule out "fake streaming": the chunks arrive in batches, so the HTTP layer is streaming faithfully. The question becomes — why did the upstream hold its breath for 20 seconds before the first character?
Mental model: your request makes two hops
Before we dig further, we need a mental model — without it, the diagnosis below won't make sense: an AI request makes two hops, and the "streaming" on each hop has nothing to do with the other.
The two-hop architecture of an AI request
Hop 2: the SDK's custom stream format ← server translates → Hop 1: vendor protocol (standard SSE)
Hop 1 (your server ↔ the LLM API) speaks the vendor's protocol — textbook SSE (content-type: text/event-stream). Hop 2 (browser ↔ your server) is the AI SDK's own stream format — toTextStreamResponse() returns a plain-text chunked stream that is not SSE at all. That's why there's no EventStream panel in DevTools: it's not that nothing is streaming, it's a different protocol.
Key Concept
Why doesn't hop 2 just reuse SSE?
The SDK unpacks the upstream SSE on the server and repackages it, which buys three things: the frontend never touches vendor protocols (swap models with zero frontend changes), each frame is slimmed from a blob of metadata down to pure deltas, and the vendor's raw response never gets piped straight to the client. SSE is just one text-framing convention on top of an HTTP chunked stream — it's no more "standard" than bare chunks. We take the SDK's full layered architecture apart (the provider system, the core, the UI hooks) in Build Your Own Mini Vercel AI SDK.
Back to the problem: which of the two hops is slow? The TTFT probe measured the exit of hop 2, so 20 seconds of silence can only come from upstream — hop 1.
Diagnosis: comparison sweep + single-variable conviction + lifting the raw frames
Step 1: a comparison sweep to narrow the suspects
Measure first-token latency on every path we could run:
| Access path | Model | Thinking | Input | First token |
|---|---|---|---|---|
| AiHubMix gateway | deepseek-v4-flash | Default | 8,890 chars | 2.1 s |
| AiHubMix gateway | deepseek-v4-pro | Default | 11,430 chars | 15.6 - 20 s |
| Official direct | deepseek-v4-pro | Explicitly disabled | 11,430 chars | 2.4 s |
To be honest, this table isn't a rigorous single-variable comparison — adjacent rows differ by two variables each (at the time we couldn't confirm whether the gateway passed the thinking parameter through to the upstream, so a clean matrix was impossible). But it narrows things down plenty: the gateway itself is off the hook (row 1, same gateway, plenty fast), and so is the pro tier's generation speed (row 3, same model, fast with thinking disabled). Suspicion lands on thinking mode.
Step 2: a single-variable experiment to convict
Same input, same endpoint, flipping only the thinking switch (lab experiment 02, one command to reproduce):
Convicted. This generation of DeepSeek models ships with thinking (reasoning) enabled by default. During the thinking phase it's burning tokens — but every one of them is internal monologue.
Step 3: lift the raw frames on hop 1
The thinking content was actually streaming the whole time — wrap the provider in a fetch that snoops on the raw response (full code in lab experiment 01):
Then comes the single most important fact of this incident — grep for that field in the @ai-sdk/openai source:
Why isn't this field in the standard protocol? Because OpenAI's own Chat Completions never gives you the thinking text at all (o-series reasoning is fully hidden — you only get a token count, to prevent distillation). There's no standard for "streaming thinking text," so DeepSeek invented reasoning_content and Anthropic uses thinking blocks in its own protocol — everyone speaks their own dialect.
Put the two facts together and the "freeze" explains itself completely:
The journey of a thinking token: streamed, then gone
The model is hard at work; the user sees a hang
Fix: one parameter, one fetch wrapper, and a waiting-state UI
For "summarize into this format" tasks, thinking buys very little quality — just turn it off. DeepSeek controls it via a thinking parameter in the request body; createOpenAI doesn't know this nonstandard parameter, so we inject it in a custom fetch:
const deepseek = createOpenAI({
baseURL: "https://api.deepseek.com",
apiKey: process.env.DEEPSEEK_API_KEY!,
});const deepseekFetch: typeof fetch = async (input, init) => {
const body = typeof init?.body === "string" ? init.body : null;
if (!body) return fetch(input, init);
const payload = JSON.parse(body);
return fetch(input, {
...init,
body: JSON.stringify({ ...payload, thinking: { type: "disabled" } }),
});
};
const deepseek = createOpenAI({
baseURL: "https://api.deepseek.com",
apiKey: process.env.DEEPSEEK_API_KEY!,
fetch: deepseekFetch, // ← every request through this provider gets rewritten
});The result:
Two notes. First, the lower-maintenance fix is to switch to the vendor-specific package @ai-sdk/deepseek (it understands the thinking dialect, with typed parameters); we still had the gateway path to support (the gateway only speaks the OpenAI protocol), so we injected at the fetch layer instead. Second, this investigation made the gateway's black-box cost obvious (no way to confirm parameter passthrough), and direct access was faster and cheaper anyway — so we later moved this workload entirely to the official direct connection. That decision set off the second explosion in this saga; see the end of the post.
Even at 2 seconds to first token, you can't skip the waiting-state UI
Prompt processing time on long inputs is a real, physical cost. Before the first token arrives, show a live status ("AI is reading the transcript (11,430 chars) · 3s elapsed"); once it lands, switch to progressive rendering. The user's entire judgment of "is this thing still alive" hangs on that detail.
Postmortem: why the root cause hid so well
The full causal chain, start to finish:
- Short-text testing ran on the flash tier, whose thinking phase lasts only a second or two — nobody noticed
- Long transcripts triggered the pro tier + a 10,000-char input, amplifying the thinking phase past 20 seconds
- The thinking text was streaming all along — but inside
reasoning_content, a DeepSeek dialect field - We connected to DeepSeek through the generic OpenAI adapter, which only recognizes the standard field set; the dialect was silently dropped
- So the browser received 0 bytes — every component was "working correctly," and the user saw a frozen UI
Step 4 is the structural root cause. "OpenAI-compatible" covers the contract terms: endpoint paths, request fields, SSE framing. Vendor extensions like reasoning_content sit outside the contract, and a standard adapter ignoring them is the adapter honoring the contract. To consume the dialect, either use the vendor-specific provider (like @ai-sdk/deepseek) or handle it yourself in a custom fetch, as above. The boundaries of the three approaches (generic adapter / vendor-specific / bare fetch) and how to choose between them are worked out in full in Build Your Own Mini Vercel AI SDK.
Iron rules
⚡ Iron Rule #1
Break every streaming problem into two numbers: TTFT + chunk distribution
A few lines of fetch + reader with timestamps. Slow first token with a dense tail = the model is holding back (thinking/queueing); no chunks at all = a transport layer is buffering. Quantify first, conclude second — don't eyeball your way to "it's not streaming."
⚡ Iron Rule #2
Compatible ≠ identical: generic adapters only guarantee the standard field set
When you point createOpenAI at a compatible endpoint to talk to an "OpenAI-compatible" vendor, vendor extension fields (thinking streams, cache control...) are silently dropped. If you lean on one vendor's features, use their dedicated provider.
⚡ Iron Rule #3
Reasoning models think by default, and users see dead air while they do
Either disable it explicitly (thinking: disabled), pipe the thinking stream to the frontend, or give the waiting phase a UI that visibly moves — pick one, or you've picked an incident.
Reproduce it yourself
git clone https://github.com/stanleyyylau/ai-sdk-streaming-lab
cd ai-sdk-streaming-lab && npm install
cp .env.example .env # add your DeepSeek API key
npm run 01 # prove hop 1 is standard SSE (reasoning_content itself, visible in the raw frames)
npm run 02 # first-token latency with thinking on vs. off
This incident has a second half: after switching to the official direct connection, streamObject's structured output blew up again (response_format compatibility) — see streamObject Deep Dive: Half-Finished JSON and the json_schema Trap. And to really understand the AI SDK's layered architecture — how providers unify the vendors, how the agent loop turns — see Build Your Own Mini Vercel AI SDK.