You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: anthropic adapter returns empty content (adapter_eof / 0 tokens) for streaming requests against upstreams that emit reasoning blocks (Kimi k3) #312
Custom providers using adapter: anthropic work fine for non-streaming requests, but streaming requests (the default for both Claude Code /v1/messages and Codex App /v1/responses) return empty content with 0 tokens, or response.incomplete with incomplete_details.reason: "adapter_eof".
The issue appears to be in the Responses SSE -> Anthropic SSE back-translation: upstreams that emit reasoning-type output blocks (Kimi k3) lose subsequent content_block events. Upstreams that do not emit reasoning blocks (Volcengine GLM) work on the same path.
Environment
opencodex: 2.7.33
macOS, Apple Silicon
Upstream: Kimi Coding API (https://api.kimi.com/coding), model k3
The same config shape against Volcengine Ark GLM (adapter: anthropic, https://ark.cn-beijing.volces.com/api/coding) works fully, including streaming. GLM does not emit the same reasoning output block shape.
makes proxy /v1/responses streaming and non-streaming, plus proxy /v1/messages streaming, return 200 with correct visible text and usage.
Kimi Coding API supports Chat Completions but does not natively implement Responses (/v1/responses returns 404).
Expected behavior
Reasoning output blocks from anthropic-adapter upstreams should be translated, or at minimum skipped without aborting or dropping the visible text stream. The proxy should not yield empty content, zero-token usage, or adapter_eof when the upstream SSE stream completed successfully.
Confirmed on current dev with a Kimi-compatible Anthropic SSE reproduction. The core failure is in OpenCodex's stream framing, not in Kimi's documented Anthropic endpoint.
The Anthropic adapter currently processes only newline-terminated buffer lines. If a valid terminal message_stop frame is the final SSE line without a trailing newline, it remains stranded in the buffer at EOF. A pending usage snapshot sometimes masks this by synthesizing done; when the compatible upstream omits that snapshot, the adapter emits visible deltas but no terminal event, and the bridge correctly reports adapter_eof / zero terminal usage.
I am fixing this by:
making the SSE event state survive arbitrary reader chunk boundaries;
flushing the final decoded buffer at EOF, including a terminal frame without a trailing newline;
preserving compatible reasoning/thinking blocks without letting an unknown reasoning block suppress later visible text;
adding regressions for split event:/data: chunks, reasoning followed by text, no usage snapshot, and no final newline;
verifying both Responses streaming and Claude Messages translation paths plus the full suite.
I will post the merged commit and validation results here, then close this issue once the fix is on dev.
Fixed and merged into dev via #316 (merge commit af973e54).
The Anthropic-compatible stream parser now uses a proper SSE decoder that preserves event/data state across arbitrary fetch chunks and dispatches the final record at EOF even when there is no trailing newline or blank delimiter. Compatible reasoning / reasoning_delta blocks are retained without suppressing later visible text. Both Responses and Claude Messages paths now receive a terminal completion instead of adapter_eof for the reproduced Kimi-style stream.
Validation: 3,616 tests passed with 0 failures; focused adversarial SSE/Anthropic/bridge tests, typecheck, privacy scan, and all Linux/macOS/Windows CI checks passed. Closing as completed.
Activity
Ingwannu commentedon Jul 23, 2026
Confirmed on current
devwith a Kimi-compatible Anthropic SSE reproduction. The core failure is in OpenCodex's stream framing, not in Kimi's documented Anthropic endpoint.The Anthropic adapter currently processes only newline-terminated buffer lines. If a valid terminal
message_stopframe is the final SSE line without a trailing newline, it remains stranded in the buffer at EOF. A pending usage snapshot sometimes masks this by synthesizingdone; when the compatible upstream omits that snapshot, the adapter emits visible deltas but no terminal event, and the bridge correctly reportsadapter_eof/ zero terminal usage.I am fixing this by:
event:/data:chunks, reasoning followed by text, no usage snapshot, and no final newline;I will post the merged commit and validation results here, then close this issue once the fix is on
dev.Ingwannu commentedon Jul 23, 2026
Fixed and merged into
devvia #316 (merge commitaf973e54).The Anthropic-compatible stream parser now uses a proper SSE decoder that preserves
event/datastate across arbitrary fetch chunks and dispatches the final record at EOF even when there is no trailing newline or blank delimiter. Compatiblereasoning/reasoning_deltablocks are retained without suppressing later visible text. Both Responses and Claude Messages paths now receive a terminal completion instead ofadapter_eoffor the reproduced Kimi-style stream.Validation: 3,616 tests passed with 0 failures; focused adversarial SSE/Anthropic/bridge tests, typecheck, privacy scan, and all Linux/macOS/Windows CI checks passed. Closing as completed.