Same Response, Two Code Paths

Replay testing of streaming parity in LLM SDKs

Muhammad Ahmad. mahmadmanzoor.com

Preprint, not peer reviewed.

Summary

Applications call language models through SDKs. A provider can send a response as one JSON document or as a stream of events, and the SDK has separate code for each.

This study replays the same real recorded responses both ways through four SDKs (Vercel AI SDK, LiteLLM, LangChain and Pydantic AI) and checks that the two results agree. It also checks that writing the same stream to the network in six different ways changes nothing. Nothing needs to be known about the correct result: the two results only have to equal each other. Every difference was traced to the code that causes it and then checked in a second, independent pass.

How it works

Recorded stream Replay server as a stream as one JSON body SDK streaming call SDK non-streaming call Same result?

Each recorded stream is replayed twice. Both calls go to the same SDK, and the two results are compared.

Key numbers

Stream versus non-stream

Recordings where the SDK returns two different results for the same response, out of those compared.
SDKOpenAI Chat CompletionsOpenAI ResponsesAnthropic MessagesGeminiAllCaused by the test rig
Vercel AI SDK0 / 1490 / 2805 / 6390 / 805 / 1,148 (0.4%)0
LiteLLM4 / 14920 / 2803 / 6408 / 8035 / 1,149 (3.0%)40
LangChain0 / 1491 / 28046 / 6395 / 8052 / 1,148 (4.5%)21
Pydantic AI0 / 1490 / 2791 / 6390 / 801 / 1,147 (0.1%)2

A further 63 differences were caused by the test rig, not by the SDK, and are not counted above. 23 came from settings of the original requests that the rig did not replay (beta features for Anthropic, structured output for OpenAI, one web-search option); they disappear when the setting is supplied. 40 came from streams recorded without token usage: the body derived from them has no usage either, which OpenAI's real non-streaming endpoint always sends. On those, LiteLLM reports zero tokens when not streaming and a local estimate when streaming.

Same stream, written differently

Recordings whose result differs from the one written in a single piece, summed over the four APIs.
SDKwholebytesutf8crlfcommentnospace
Vercel AI SDK000000
LiteLLM0000830
LangChain00008383
Pydantic AI00008383

whole: one write; bytes: cut at random bytes; utf8: cut inside multi-byte characters; crlf: CRLF line endings; comment: an SSE comment line before every event; nospace: no space after the field colon.

Every nonzero cell is the Gemini recordings.

Where an OpenAI refusal ends up

Where each SDK puts a refusal from the OpenAI APIs.
SDKChat Completions not streamedChat Completions streamedResponses not streamedResponses streamed
Vercel AI SDKtexttexttexttext
LiteLLMfieldlostlostlost
LangChainfieldlostfieldfield
Pydantic AIfieldfieldfieldfield

field: a refusal field of the result; text: the answer text; lost: nowhere in the result.

Replayed without the structured-output setting of the original request. With that setting supplied, LangChain's streamed Chat Completions cell becomes field. LiteLLM's cells do not change.

What was found

NS is the non-streamed result, S the streamed result of the same response.

Vercel AI SDK (ai 7.0.187, @ai-sdk/anthropic 4.0.113)

IdFormatnDescription
AI-1Anthropic3A tool-search result arrives without its call (the call was made in an earlier turn), and the BM25 search tool is declared under its wire name tool_search_tool_bm25 (with the key used in the SDK's documentation, toolSearch, both calls agree). NS: throws “Tool call not found”. S: returns the result. Both label it as the regex search tool.
AI-2Anthropic1A citation of type content_block_location has no file_id key (Anthropic's current API reference declares the key required, so current responses most likely include it). NS: throws “Invalid JSON response”. S: returns the text, without citations, and reports a validation error per chunk.
AI-3Anthropic1A tool call is cut off by max_tokens. NS: returns the call with empty arguments. S: returns no call.

LiteLLM 1.111.1

IdFormatnDescription
LL-1Gemini83Transport, comment: a comment line makes the stream reader buffer every later event without parsing it. The call returns an empty answer, finish reason stop, and no error.
LL-11Chat4The model refuses. NS: refusal text in message.refusal. S: refusal lost, content empty, finish reason stop.
LL-3Responses7The answer has url_citation annotations (web search). NS: kept. S: dropped.
LL-4Gemini7No thinking-token count is sent. NS: reasoning_tokens is null. S: it is 0 (a difference of representation only).
LL-5Responses6The answer has a file_citation or container_file_citation annotation. NS: raises. S: returns the answer.
LL-6Responses4The output holds only MCP listing or approval items, or a local shell call. NS: raises “Unknown items”. S: returns an empty answer.
LL-7Responses3The output has an apply_patch call. NS: returned as a tool call. S: dropped, and the finish reason is stop.
LL-8Anthropic2Thinking is only redacted. NS: reasoning_tokens is null. S: it is 0, although thinking took place.
LL-9Anthropic1A tool call's input arrives whole in the block-start event (programmatic tool calling). NS: arguments kept. S: arguments are {}.
LL-10Gemini1The response counts tool-use prompt tokens. NS: total_tokens is the provider's total. S: recomputed as prompt plus completion, which leaves them out.

LangChain (langchain-anthropic 1.7.13, langchain-google-genai 4.5.4, langchain-core 1.8.5)

IdFormatnDescription
LC-2Anthropic28The response wrote to the prompt cache. NS: the cache-write count sits under per-TTL keys and cache_creation is 0. S: the same count sits in cache_creation.
LC-3Anthropic18The final stream event carries only the output count (older recordings; every Claude 4 or later recording repeats the input count). NS: input tokens reported. S: input_tokens is 0.
LC-5Gemini3A text part ends in a newline. NS: trailing newlines removed. S: kept. (A fourth affected recording is counted under LC-6.)
LC-6Gemini2A later chunk reports a lower token count than an earlier one. NS: final counts. S: keeps the earlier, larger count.
LC-7Responses1A function call is cut off by max_output_tokens. NS: an invalid tool call. S: a valid call with repaired arguments.

Pydantic AI 2.66.0

IdFormatnDescription
PA-3Anthropic1The response contains a server-side model fallback block (a beta feature; the input is a test fixture). NS: raises AssertionError. S: skips the block and returns.

google-genai 3.6.1, reached through LangChain and Pydantic AI

IdFormatnDescription
GG-1Gemini83Transport, comment and nospace: the stream reader accepts only lines that start with data: and a space, so the streamed call raises on every recording.

If you build on these SDKs

Limits

Reproduce

python3.12 -m venv .venv && .venv/bin/pip install -r requirements.txt
(cd js && npm ci)
.venv/bin/python harness/server.py corpus 8787 results/logs/requests.jsonl &
./run_all.sh
.venv/bin/python harness/core_compare.py corpus results
.venv/bin/python harness/usage_conventions.py corpus results
.venv/bin/python harness/analyze.py corpus results paper/tables
(cd paper && tectonic -X compile main.tex)
.venv/bin/python harness/make_site.py

Cite

@misc{ahmad2026streamparity,
  title  = {Same Response, Two Code Paths: Replay Testing of Streaming Parity in LLM SDKs},
  author = {Ahmad, Muhammad},
  year   = {2026},
  note   = {Preprint},
  doi    = {10.5281/zenodo.24734123},
  url    = {https://doi.org/10.5281/zenodo.24734123}
}