fix(claude): use canonical reasoning_content in non-stream response - #193
Open
warelik wants to merge 2 commits into
Open
fix(claude): use canonical reasoning_content in non-stream response#193warelik wants to merge 2 commits into
warelik wants to merge 2 commits into
Conversation
Align non-streaming Claude-to-OpenAI Chat Completions translator with streaming path by writing message.reasoning_content instead of message.reasoning. Refs router-for-me/CLIProxyAPI#5104
This was referenced Aug 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When translating non-streaming Claude responses to OpenAI Chat Completions (
ConvertClaudeResponseToOpenAINonStream), thinking blocks were written to the non-canonical fieldchoices.0.message.reasoning. In contrast, the streaming converter in the same file (ConvertClaudeResponseToOpenAI) outputs reasoning deltas using the canonicalchoices.0.delta.reasoning_content.Because downstream OpenAI clients and multi-turn request adapters expect
choices.0.message.reasoning_content, non-streaming responses failed to preserve thinking tokens across subsequent turns.Fix
internal/translator/claude/openai/chat-completions/claude_openai_response.go:437: UpdatedConvertClaudeResponseToOpenAINonStreamto serialize reasoning content tochoices.0.message.reasoning_content.Tests
TestConvertClaudeResponseToOpenAINonStream_ReasoningContent: Verifiesreasoning_contentis properly populated and legacyreasoningfield is omitted.TestConvertClaudeResponseToOpenAINonStream_OmitsReasoningContentWhenAbsent: Verifies reasoning fields are omitted when responses lack thinking blocks.TestConvertClaudeResponseToOpenAI_StreamAndNonStreamParity: Verifies stream and non-stream parity for thinking content, visible text, and finish reason.TestConvertClaudeResponseToOpenAI_RedactedThinkingIgnored: Verifiesredacted_thinkingblocks are never leaked intoreasoning_contentin streaming or non-streaming mode.Reverse bite-check
Reverting
internal/translator/claude/openai/chat-completions/claude_openai_response.goto the pre-fix state reproduces the failure wherereasoning_contentis missing:Verification
Output:
Tooling note
The
jbcontextsemantic-search CLI is installed but non-functional in this environment(
jbcontext searchfails withthe OS keychain is not accessible). The equivalentreview passes were performed with the repository's own tooling and manual inspection
instead; this is disclosed for transparency about how the change was reviewed.