Fix HTTP 400 for BYOK Open Router reasoning models#318809
Merged
vritant24 merged 5 commits intoMay 28, 2026
Merged
Conversation
Add reasoning_content (DeepSeek / Moonshot (Kimi) / Minimax) and reasoning (OpenRouter) to ThinkingDataInMessage and RawThinkingDelta, and read them when extracting reasoning text from responses.
Fixes #312746. DeepSeek / Moonshot (Kimi) / Minimax and OpenRouter reject the turn after a tool call with HTTP 400 unless the assistant message replays its reasoning. OpenAIEndpoint now emits reasoning_content and reasoning (alongside cot_id / cot_summary) on the Chat Completions path, gated on the model's thinking capability so non-reasoning endpoints are unaffected.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes BYOK Chat Completions history replay for reasoning models by preserving provider-specific reasoning fields alongside existing CAPI-style thinking fields.
Changes:
- Adds
reasoning_contentandreasoningto thinking message/delta shapes. - Parses incoming reasoning deltas from those provider-specific fields.
- Emits provider-specific reasoning fields for BYOK Chat Completions when the model supports thinking, with regression tests.
Show a summary per file
| File | Description |
|---|---|
extensions/copilot/src/platform/thinking/common/thinkingUtils.ts |
Reads provider-specific reasoning delta fields. |
extensions/copilot/src/platform/thinking/common/thinking.ts |
Adds new reasoning fields to thinking interfaces. |
extensions/copilot/src/extension/byok/node/openAIEndpoint.ts |
Emits reasoning fields for Chat Completions BYOK history replay. |
extensions/copilot/src/extension/byok/node/test/openAIEndpoint.spec.ts |
Adds OpenAIEndpoint regression coverage for reasoning fields. |
extensions/copilot/src/extension/byok/vscode-node/test/customEndpointProvider.spec.ts |
Adds custom endpoint regression coverage. |
Copilot's findings
- Files reviewed: 5/5 changed files
- Comments generated: 2
- Complete the trailing comment documenting the reasoning / reasoning_content fields. - Correct field-ownership comments in thinking.ts (reasoning_content is DeepSeek/Kimi/Minimax; reasoning is OpenRouter). - Add SSE stream-parsing regression tests for the reasoning_content and reasoning delta field names.
rzhao271
approved these changes
May 28, 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.
Fixes #312746
Problem
When a reasoning model is used via BYOK on the Chat Completions path, the turn
after a tool call is rejected with HTTP 400, e.g.:
These providers require the assistant message to replay its prior reasoning when
chat history is sent back. We only emitted the CAPI-style
cot_id/cot_summarykeys, which they don't recognize.
Fix
OpenAIEndpointnow also echoes the reasoning under the field names theseproviders expect when replaying history on the Chat Completions path:
reasoning_content— DeepSeek, Moonshot (Kimi), Minimaxreasoning— OpenRouter's BYOK proxyThis is gated on the model's
thinkingcapability, so non-reasoning endpointsreceive an identical payload to before. The first-party Copilot (CAPI) path is
unaffected — it uses a separate endpoint with its own
reasoning_opaque/reasoning_textserialization.