AIStudio2API icon indicating copy to clipboard operation
AIStudio2API copied to clipboard

[Bug] Claude Code WebSearch returns HTTP 400 when Anthropic tool_choice forces web_search

Open stphamz621 opened this issue 1 week ago • 0 comments

发生了什么 / What happened

Claude Code 2.1.328 on Windows can chat through AIStudio2API at http://127.0.0.1:2048 with gemini-4-argon, but its built-in WebSearch fails. Claude Code sends a second, streaming request to POST /v1/messages?beta=true with the hosted tool web_search_20250305 and tool_choice set to {"type":"tool","name":"web_search"}.

The proxy returns HTTP 400:

AI Studio request parameters are invalid: tool choice references undeclared function "web_search"

Minimal reproduction

Send the following JSON to POST /v1/messages with Content-Type: application/json and anthropic-version: 2023-06-01. Include your proxy API key if required.

{
  "model": "gemini-4-argon",
  "max_tokens": 400,
  "messages": [
    {"role": "user", "content": "Use web search to find the IANA Example Domains page and cite the source."}
  ],
  "tools": [
    {"type": "web_search_20250305", "name": "web_search", "max_uses": 1}
  ],
  "tool_choice": {"type": "tool", "name": "web_search"}
}

This also returns HTTP 400. Changing only tool_choice to {"type":"auto"} returns HTTP 200 with server_tool_use and web_search_tool_result blocks. Ordinary Messages requests work. Claude Code's built-in WebFetch also successfully reads a public page in the same session.

Expected behavior

The proxy accepts the hosted web_search selection, runs Google Search, and returns Anthropic-compatible search events and results to Claude Code.

The adapter appears to map web_search_20250305 to Google Search while mapping the named tool_choice to AllowedFunctionNames. The hosted tool is then treated as an undeclared client function. Please check the forced hosted-tool path and add regression coverage for the streaming request that Claude Code sends.

版本 / Version

v0.3.13 (running binary reports v0.3.13+dirty, revision c77dd89)

stphamz621 avatar Nov 21 '26 03:11 stphamz621