copilot_chat: Serialize ToolChoice::Any as "required" instead of "any"#52015
Conversation
… "required" OpenAI API does not support tool_choice: "any". The correct value is "required". This caused inline assistant to fail with 400 Bad Request when using gpt-4.1 and other models via copilot_chat provider. Fixes: tool_choice_not_supported error for gpt-4.1-2025-04-14
|
Wouldn't this need to be per model then? |
- Rename Any -> Required in copilot_chat.rs and responses.rs to match the OpenAI wire format explicitly (same as open_ai, lmstudio, open_router) - Remove the serde(rename) workaround in favour of an accurate variant name - Fix the same serialization bug in responses::ToolChoice, which was not touched by the original commit but uses the same rename_all = lowercase - Update both match arms in the language_models copilot_chat provider
|
After looking at other OpenAI-compatible providers ( Updated the PR: renamed Also added regression tests for the serialization output. |
|
Right but copilot supports anthropic models as well, correct? |
|
Yes, but Anthropic models are routed through a completely separate path. In |
Observed behavior: Inline assistant failed for GPT-4.1,
Gemini, and other non-Anthropic models. Claude worked correctly because
Anthropic's API accepts
"any"as a valid value.Fix
Renamed
ToolChoice::Any→ToolChoice::Requiredin bothcopilot_chat.rsandresponses.rs, matching the convention used byother OpenAI-compatible providers (
open_ai,lmstudio,open_router).copilot_chat::ToolChoiceis a wire type only for the/chat/completionspath — Anthropic models go through
into_anthropic()and never touch it,so no per-model logic is needed.
Also fixes the same serialization bug in
responses::ToolChoice, whichwas not covered by the original approach, and adds regression tests for
both.
Affected models
gpt-4.1via copilot_chat providergemini-*via copilot_chat providerScreenshots
Bug (only Claude works, Gemini and GPT-4.1 fail):

Fix:

Result: After the fix, all models work correctly via inline assistant.
Release Notes
non-Anthropic models via the copilot_chat provider (
tool_choicewassending
"any"instead of"required")