feat: allow arbitrary reasoning_effort values via pass-through#1
Merged
Conversation
Agent-Logs-Url: https://github.com/lyzgeorge/copilot-api/sessions/10f76b26-728d-41d8-8fb3-432974af4318 Co-authored-by: lyzgeorge <8285196+lyzgeorge@users.noreply.github.com>
…plete Agent-Logs-Url: https://github.com/lyzgeorge/copilot-api/sessions/10f76b26-728d-41d8-8fb3-432974af4318 Co-authored-by: lyzgeorge <8285196+lyzgeorge@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Update reasoning effort type definition to support arbitrary values
feat: allow arbitrary Apr 14, 2026
reasoning_effort values via pass-through
Agent-Logs-Url: https://github.com/lyzgeorge/copilot-api/sessions/83622886-a808-4ba6-820c-75ed8300f3ab Co-authored-by: lyzgeorge <8285196+lyzgeorge@users.noreply.github.com>
lyzgeorge
approved these changes
Apr 14, 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.
Original prompt
问题描述
当前项目的
reasoning_effort类型定义严格限制为"low" | "medium" | "high",但不同的模型可能支持其他值(如 gpt-5.4 支持的xhigh、minimal等)。需求
允许传入任意
reasoning_effort值(默认支持low/medium/high),但对于不在已知列表中的值进行透传,这样:实现方案
修改以下文件中的
reasoning_effort类型定义,从严格联合类型改为接受字符串,但使用 TypeScript 的字面量类型提示:ChatCompletionsPayload接口ReasoningContext接口中的reasoningEffort字段修改前
修改后
这样可以:
测试场景
"low"/"medium"/"high"- 正常工作"xhigh"/"minimal"或其他新值 - 透传给后端null/undefined- 正常处理The following is the prior conversation context from the user's chat exploration (may be truncated):
User: does this codebase support reasoning effort control?
Assistant: I'll search the codebase to understand if it supports reasoning effort control.
Assistant: Great! I found it. Let me get more details on how it's implemented:
Assistant: Now let me check if this is actually being used/handled in the request processing:
Assistant: Now let me check if the thinking parameter is actually being used/forwarded in the message handler:
Assistant: Yes, this codebase supports reasoning effort control via the
thinkingparameter.The
thinkingparameter is defined in the Anthropic API types and includes abudget_tokensfield:This is part of the
AnthropicMessagesPayloadinterface, which accepts Anthropic API requests. When a client sends a request with:{ "thinking": { "type": "enabled", "budget_tokens": 5000 } }The codebase will:
anthropic-types.ts)translateToOpenAI()function in the message handlerThe implementation treats this as a pass-through mechanism—it doesn't modify or validate the
budget_tokensvalue, but rather forwards whatever the client specifies to the underlying Copilot service. This allows clients to control reasoning effort by setting the token budget for extended thinking operations, similar to how Anthropic's API natively handles this parameter.User: 这个参数有被真正传递并处理吗?还是被丢弃了?
Assistant: 让我深入检查这个参数是否真正被传递和处理。
Assistant: 问题的答案是:
thinking参数被丢弃了。查看
translateToOpenAI()函数(第29-47行),这是将 Anthropic 请求转换为 OpenAI 请求的地方:问题关键:
AnthropicMessagesPayload(包括thinking参数)ChatCompletionsPayload中完全没有处理thinking参数model、messages、max_tokens、stop_sequences、stream、temperature、top_p、metadata.user_id、tools、tool_choice同样,响应翻译函数(第305行的注释)也明确表示:
// Note: GitHub Copilot doesn't generate thinking blocks, so we don't include them in responses结论: 虽然类型定义中包含
thinking字段,但在实际请求处理过程中被完全忽略,没有被转发给 Copilot API。这个参数目前是被丢弃的。User: 这个项目代码有实现 thinking 或者 reasoning 参数的传递吗?因为网关同时支持 anthropic 和 openai 协议传入,后端代码有正确处理映射吗?
Assistant: 让我深入调查这个项目中 thinking/reasoning 参数在两个协议之间的处理情况。
Assistant: 现在让我获取更多详细的实现代码:
Assistant: 完全不同的情况!你的 fork(lyzgeorge/copilot-api)已经实现了完整的 reasoning 参数传递和映射机制。
对比两个版本:
原始项目 (ericc-ch/copilot-api)
❌
thinking参数被完全丢弃,没有处理你的 fork (lyzgeorge/copilot-api)
✅ 完整实现了 reasoning 参数的双向转换
架构设计(你的版本)
Anthropic 请求路径 (
/v1/messages)