Skip to content

Fix HTTP 400 for BYOK Open Router reasoning models#318809

Merged
vritant24 merged 5 commits into
mainfrom
agents/create-a-unit-teat-to-repro-this-issue-4d3ce7a3
May 28, 2026
Merged

Fix HTTP 400 for BYOK Open Router reasoning models#318809
vritant24 merged 5 commits into
mainfrom
agents/create-a-unit-teat-to-repro-this-issue-4d3ce7a3

Conversation

@vritant24
Copy link
Copy Markdown
Member

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.:

thinking is enabled but reasoning_content is missing in assistant tool call message at index N

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_summary
keys, which they don't recognize.

Fix

OpenAIEndpoint now also echoes the reasoning under the field names these
providers expect when replaying history on the Chat Completions path:

  • reasoning_content — DeepSeek, Moonshot (Kimi), Minimax
  • reasoning — OpenRouter's BYOK proxy

This is gated on the model's thinking capability, so non-reasoning endpoints
receive an identical payload to before. The first-party Copilot (CAPI) path is
unaffected — it uses a separate endpoint with its own reasoning_opaque /
reasoning_text serialization.

vritant24 added 2 commits May 28, 2026 10:44
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.
Copilot AI review requested due to automatic review settings May 28, 2026 17:53
@vritant24 vritant24 self-assigned this May 28, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_content and reasoning to 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

Comment thread extensions/copilot/src/platform/thinking/common/thinkingUtils.ts
Comment thread extensions/copilot/src/extension/byok/node/openAIEndpoint.ts
vritant24 added 2 commits May 28, 2026 11:03
- 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Copilot Chat drops reasoning_content field when using DeepSeek models (OpenRouter BYOK), causing 400 Error

3 participants