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 |
zed-industries#52015) **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::Required` in both `copilot_chat.rs` and `responses.rs`, matching the convention used by other OpenAI-compatible providers (`open_ai`, `lmstudio`, `open_router`). `copilot_chat::ToolChoice` is a wire type only for the `/chat/completions` path — 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`, which was not covered by the original approach, and adds regression tests for both. ## Affected models - `gpt-4.1` via copilot_chat provider - `gemini-*` via copilot_chat provider - Likely affects all OpenAI-compatible models routed through copilot_chat ## Screenshots **Bug (only Claude works, Gemini and GPT-4.1 fail):** <img width="598" height="209" alt="image" src="https://github.com/user-attachments/assets/bbd418d9-7de3-4191-9ca9-fd1961534e23" /> **Fix:** <img width="532" height="154" alt="image" src="https://github.com/user-attachments/assets/86bb0f8e-67e6-4417-9b78-b1b7ad328e9e" /> **Result:** After the fix, all models work correctly via inline assistant. ## Release Notes - Fix inline assistant 400 errors for GPT-4.1, Gemini, and other non-Anthropic models via the copilot_chat provider (`tool_choice` was sending `"any"` instead of `"required"`)
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")