Skip to content

fix(responses): translate OpenAI tool_search to Anthropic tool search for Claude models - #45882

Merged
mateo-berri merged 23 commits into
mainfrom
litellm_responses_tool_search_anthropic
Oct 15, 2026
Merged

mateo-berri merged 23 commits into
mainfrom
litellm_responses_tool_search_anthropic

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

TLDR

Problem this solves:

  • /v1/responses dropped OpenAI's tool_search tool on Claude models
  • With every function tool deferred, Anthropic then answered 400
  • With one tool not deferred, Claude never saw the deferred tools

How it solves it:

  • A server tool_search tool becomes Anthropic's regex tool search tool
  • Only where the cost map says the route runs tool search
  • Claude's search comes back as a tool_search_call item, streaming too
  • Namespace member tools keep their defer_loading flag
  • Claude routes keep defer_loading as sent when no server search tool is sent
  • A native Anthropic search tool passes through and goes out once
  • Malformed defer_loading, allowed_callers, or execution answers 400, or drops under drop_params
  • Chat completions drops an unanswered replayed srvtoolu_ search call instead of 400
  • Claude on azure_ai gets the search tool too, since Microsoft Foundry runs it
  • Follow-ups sent to a model that is not Claude leave the stored search out
  • Search items never carry a null created_by, so replays to OpenAI work
  • Output guardrails scan and rewrite a tool_search_call's arguments

User Flow

Before: a developer sends OpenAI's tool search shape to a Claude model and gets a 400 back from Anthropic

  1. They send POST https://litellm-domain/v1/responses with "model": "claude-sonnet-5-5", a {"type": "tool_search"} tool, and three function tools with "defer_loading": true
  2. They get HTTP 400 At least one tool must have defer_loading=false. All tools cannot be deferred.
  3. With one tool left undeferred they get HTTP 200, no tool_search_call, and a message saying there is no weather tool
  4. The step 1 request to an OpenAI model group that falls back to claude-sonnet-5-5 fails, and the fallback fails with All tools cannot be deferred.
  5. In their own Python app with no proxy, they call await litellm.Router(...).aresponses(model="gpt-primary", ...) with the step 1 tools, where gpt-primary is an OpenAI deployment that falls back to anthropic/claude-sonnet-5-5, and get litellm.AuthenticationError saying the fallback to Claude also failed with litellm.BadRequestError

After: the same request reaches Claude with its tool search tool, and the output carries the search call and the function call

  1. They send POST https://litellm-domain/v1/responses with "model": "claude-sonnet-5-5", a {"type": "tool_search"} tool, and three function tools with "defer_loading": true
  2. They get HTTP 200 with a tool_search_call item, then a function_call for get_weather with {"city": "Paris"}, streamed in the same order with "stream": true
  3. They answer get_weather with previous_response_id and a function_call_output, to Claude or to gemini-flash, and get HTTP 200 using the result
  4. The step 1 request to an OpenAI model group that falls back to claude-sonnet-5-5 answers HTTP 200 with the tool_search_call and the get_weather call
  5. In their own Python app with no proxy, they call await litellm.Router(...).aresponses(model="gpt-primary", ...) with the step 1 tools, where gpt-primary is an OpenAI deployment that falls back to anthropic/claude-sonnet-5-5, and get the tool_search_call and the get_weather call from Claude, streamed in the same order with stream=True

Linear ticket

Resolves LIT-9579

Decisions

  • OpenAI's tool_search becomes Anthropic's regex tool (tool_search_tool_regex_20251119), not bm25. The regex tool is what Anthropic documents first and what the native control call used. A bm25 tool the caller sends natively is recognized as a search tool and passed through
  • Support comes from the cost map's supports_tool_search flag through a new litellm.supports_tool_search(model, custom_llm_provider). Models without it keep today's drop plus warning, so a provider that would reject the tool is never sent it
  • A tool_search tool with no execution counts as server execution. Client execution ("execution": "client") is out of scope and stays dropped as before
  • The tool_search_call item's call_id is Anthropic's srvtoolu_ id, and its id is tsc_ plus that id, the same shape as fc_ function call ids
  • No tool_search_output item is synthesized. OpenAI fills it with the full tool definitions, which the caller already has
  • tool_search_call and tool_search_output input items are left out of the Anthropic request, like the stored search call in the next bullet. On a follow-up turn Claude sees the tool calls and results that came after the search but not the search itself, so its answer can say it called a tool without searching first (case 10). Replaying the search with its result was the alternative, tested live on claude-sonnet-5-5, where Anthropic answers 400 Tool reference 'get_weather' not found in available tools once a later turn drops a loaded tool or sends no tools. Replaying it safely needs a tool_search_output item the bridge does not emit yet, so it is a follow-up
  • Search arguments that do not parse as a JSON object produce a tool_search_call with "status": "incomplete" and empty arguments instead of an error
  • The non-streaming tool_search_call status is always completed, since the chat tool call carries no status
  • The gate for sending the search tool is whether the route builds an Anthropic request (provider_builds_anthropic_request): Bedrock Converse builds its own request and has no tool search, so the bridge drops the tool there with a warning, while Bedrock invoke, Anthropic, and Vertex keep it
  • Claude on azure_ai gets the search tool. The cost map's claude-tool-search rule fills supports_tool_search for anthropic, azure_ai, bedrock, bedrock_converse, and vertex_ai, since Microsoft Foundry runs Anthropic's tool search for Claude (Foundry blog, 2026-08-17). Case 27 sends case 1 to azure_ai/claude-sonnet-4-6
  • A replayed tool_search_call whose result was not stored (a previous_response_id follow-up) is dropped from the Anthropic request instead of echoed back, since Anthropic answers 400 to a server tool use with no result
  • A chat tool call counts as a search call only when its id starts with srvtoolu_ and its name is one of Anthropic's search tools, so a caller's own function named tool_search_tool_regex stays a function_call
  • A defer_loading that is not a boolean, or an allowed_callers that is not a list of strings, answers 400 (litellm.BadRequestError) on every bridge route the way OpenAI's own validation does (invalid_type, checked live 2026-10-12), instead of the 500 the bridge answered before. With drop_params on, the malformed flag is dropped from that tool and the request goes through, the way litellm drops other unsupported values (case 9b). A tool_search execution other than "server" or "client" gets the same treatment where the route runs the search, so drop_params leaves a server search, matching OpenAI's 400 invalid_value (checked live 2026-10-14, case 34). A route that cannot run tool search drops the whole tool first, as the base does
  • The tool_search_call output item is litellm's own model (litellm.types.responses.main.OutputToolSearchCall) with the OpenAI SDK's field set, since openai 2.20.0, the lowest SDK litellm supports, has no such class. Its name differs from the SDK's ResponseToolSearchCall so the OpenAPI schema never has two components under one name
  • The srvtoolu_ detection lives in the shared chat factory, so /v1/chat/completions also drops a replayed search call that no tool message answers, while one the caller answered the OpenAI-SDK way (a tool message per tool_calls entry) stays paired with its tool_result. Before, a two-turn chat replay answered 400 tool_use ids were found without tool_result blocks. Dropping the answered pair too was tried at c3c38ba and reverted, since Claude then said it called get_weather without searching in 4 of 6 runs, while with the kept pair it never said so in 6 of 6 runs on either leg (case 28). A turn holding only the search could not be dropped anyway, since Anthropic answers 400 This model does not support assistant message prefill to a conversation that ends on an assistant turn
  • A mid-conversation system message whose next assistant turn holds only an unanswered search call converts to a user turn, the same as one before an empty assistant turn, since that turn is dropped and the system block would otherwise reach Anthropic in a spot it answers 400 to (case 29). The placement takes one pass over the history
  • Output guardrails scan a tool_search_call the way they scan a function call. The guardrail sees a call named tool_search with the search arguments as JSON text, and its rewrite goes back as a JSON object on a copy of the item. A stream is rewritten only through a guardrail policy pipeline, so a plain post-call guardrail leaves a streamed tool_search_call alone, as it leaves a streamed function_call on the base (case 31). The pipeline finds OpenAI's own streamed tool_search_call, whose call_id is null, by its item id (case 33). A rewrite that is not a JSON object goes out as {} with "status": "incomplete", so the original arguments never go out after a guardrail changed them. This also covers OpenAI's own tool_search_call on native routes, which the base never scanned. The base returned Anthropic's native search as a scanned function_call, so skipping tool_search_call would let a search pattern past a post-call filter (case 31)
  • When the caller sends no server tool_search (none at all, or only "execution": "client"), a Claude route gets every tool's defer_loading as sent, as on the base (cases 32a, 32c, 32d). OpenAI's own API answers 400 Deferred tools require tools.tool_search. to the same request (case 32b). The flag is stripped only when the bridge drops a server tool_search the route cannot run, or on a route with no deferral (Gemini, Bedrock Converse, Mistral), where a deferred tool could never load and Mistral answered 422 to the flag (case 32e). 333a5e8 stripped it on Claude routes too, which loaded every deferred tool up front where the base kept them hidden
  • A tool_search_call input item whose id is not a tsc_ id is replayed to OpenAI's native Responses API without that id, the same treatment function_call items with a foreign fc_ id get. A bridge-minted tsc_srvtoolu_ id keeps the genuine prefix and goes out as is, which case 13 exercises
  • A /v1/messages request whose guardrail rewrites the history (structured_messages) now reaches Anthropic without an assistant srvtoolu_ block the caller never answered, so it answers 200 where Anthropic answered 400 to that unanswerable block
  • The new validation 400s (malformed defer_loading, allowed_callers, or execution) fail before routing, so their spend rows carry the public model alias like the existing unknown-model rows, not the deployment name
  • tool_search_call and tool_search_output items never carry a null created_by, on any route. The response serializer drops the key when it is null, as it does for null reasoning fields, so a response-cache hit (rebuilt through the SDK's class) and OpenAI's own items match a fresh bridge answer. OpenAI answers 400 Unknown parameter: 'input[2].created_by' when an item with it is replayed, which the proxy's own gpt-5.5 items hit before this PR (case 23). Ordering the output union so litellm's model wins was the alternative, but list invariance carried that type change into two other modules
  • A native Anthropic search tool the caller sends (tool_search_tool_regex_20251119 or tool_search_tool_bm25_20251119) is not the bridge's to gate: it passes through on every route as it did before this PR, and the other tools keep defer_loading whenever any Anthropic search tool goes out. Only the OpenAI tool_search shape is dropped on a route that cannot run it, and that happens before translation
  • A previous_response_id follow-up routed to a model whose route does not build an Anthropic request (Gemini, Mistral, OpenAI-compatible providers) gets the stored history without the Claude search call (srvtoolu_ id), and an assistant turn that held only that call is dropped, since Mistral answers 400 Unexpected tool call id to it. The Anthropic route keeps it for the chat factory to pair or drop
  • A custom tool ("type": "custom") carries its defer_loading to the chat tool the way a function tool does, so a deferred custom tool is loaded through the search tool too
  • When the caller sends Anthropic's native search tool and OpenAI's tool_search together, only the native tool goes out. Both would reach Anthropic as tool_search_tool_regex, and Anthropic answers 400 tools: Tool names must be unique. (case 18). Two OpenAI tool_search tools get that 400 too, where the base dropped both, and OpenAI answers 400 Only one tool_search tool is allowed (checked live 2026-10-14), so the bridge does not merge them
  • The Responses guardrail handler leaves malformed defer_loading and allowed_callers flags out of the tools it translates for the guardrail to scan, so the guardrail step never raises on a flag the route drops under drop_params or refuses with 400 without it (case 19, 500 before and 200 after)
  • The Responses guardrail handler does not hand OpenAI's tool_search tool to the guardrail, the same as before this PR. It carries no caller text, so a guardrail that hands back only function tools keeps tool_search on every route
  • A Claude search call the client replays itself, a function_call whose call_id starts with srvtoolu_ (case 22's turn 2), is left out of the history sent to a route that does not build an Anthropic request, the same as a stored one
  • On a previous_response_id follow-up the bridge drops the stored Claude search call first and then applies main's cache_control marks and cap from fix(responses): propagate cache_control through responses->chat completion bridge #32511, so a dropped message never counts toward the cap. The request's drop_params, a named argument here, still reaches that cap (case 36)
  • Databricks counts as a route that does not build an Anthropic request. DatabricksConfig also extends the OpenAI chat config and sends OpenAI-shaped messages, so the search tool and a stored search call are dropped there

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have added meaningful tests
  • The handful of test files covering my change pass locally, e.g. uv run pytest tests/unit/<your_test_file>.py -v. Leave the suites (make test-unit-*, make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or more
  • My PR passes all required CI/CD checks (e.g., lint, schema.d.ts sync check, etc.)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • Every automated review on my PR's latest commit has finished, and I have addressed or replied to each of its findings before requesting a maintainer review

Delays in PR merge?

If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).

Screenshots / Proof of Fix

Last updated at 86ed5be on 2026-10-15 UTC. Cases 1 to 32 ran at 85bee09, 33 and 34 at 2e331ea, 35 and 36 at e250d78 (the first merge of main), and 37 and 38 at 86ed5be, the merge carrying #46440, whose factory.py resolution is the only product diff since

Both legs ran on the shared GCE test box as one remote rig, each leg in its own worktree with its own .venv and a fresh Postgres, and no Redis. Every proxy booted with --num_workers 2 --timeout_worker_healthcheck 60 on a random free port, one instance per config, with store_prompts_in_spend_logs: true so previous_response_id works. The before leg ran the merge base 7fa52b2, and the after leg ran every case again at 85bee09, all on 2026-10-14 UTC. Both legs sent the same cases with real Anthropic, OpenAI, Bedrock, Vertex AI, Gemini, and Mistral credentials (real $$$). Case 19 went to a second proxy on each leg, booted from config_guard.yaml, which is this config plus a default_on pre-call litellm_content_filter guardrail and litellm_settings.drop_params: true. Case 26 went to a third, booted from config_guard2.yaml, which is this config plus the default_on pre-call custom guardrail below. Case 25 runs the SDK's Router.aresponses in-process with no proxy. gpt-5.6 is the OpenAI control, the newest GPT model in the cost map

model_list:
  - model_name: claude-sonnet-5-5
    litellm_params:
      model: anthropic/claude-sonnet-5-5
      api_key: os.environ/ANTHROPIC_API_KEY
  - model_name: gpt-5.6
    litellm_params:
      model: openai/gpt-5.6
      api_key: os.environ/OPENAI_API_KEY
  - model_name: bedrock-claude-converse
    litellm_params:
      model: bedrock/converse/us.anthropic.claude-sonnet-5-5
      aws_region_name: us-east-1
  - model_name: bedrock-claude-invoke
    litellm_params:
      model: bedrock/invoke/us.anthropic.claude-sonnet-5-5
      aws_region_name: us-east-1
  - model_name: vertex-claude
    litellm_params:
      model: vertex_ai/claude-sonnet-4-5
      vertex_project: os.environ/VERTEXAI_PROJECT
      vertex_location: os.environ/VERTEXAI_LOCATION
  - model_name: gpt-broken
    litellm_params:
      model: openai/gpt-5.6
      api_key: sk-deliberately-invalid-to-force-the-fallback
  - model_name: mistral-small
    litellm_params:
      model: mistral/mistral-small-latest
      api_key: os.environ/MISTRAL_API_KEY
  - model_name: gemini-flash
    litellm_params:
      model: gemini/gemini-3.8-flash
      api_key: os.environ/GEMINI_API_KEY

router_settings:
  fallbacks: [{"gpt-broken": ["claude-sonnet-5-5"]}]

general_settings:
  master_key: os.environ/LITELLM_MASTER_KEY
  store_model_in_db: false
  store_prompts_in_spend_logs: true

req_claude.json, the request an OpenAI Responses API caller sends today:

{
  "model": "claude-sonnet-5-5",
  "input": "What is the weather in Paris right now? Use the right tool.",
  "tools": [
    {"type": "tool_search", "execution": "server"},
    {"type": "function", "name": "get_weather", "description": "Get the current weather for a city", "parameters": {"type": "object", "properties": {"city": {"type": "string"}}, "required": ["city"]}, "defer_loading": true},
    {"type": "function", "name": "get_stock_price", "description": "Get the current stock price for a ticker", "parameters": {"type": "object", "properties": {"ticker": {"type": "string"}}, "required": ["ticker"]}, "defer_loading": true},
    {"type": "function", "name": "send_email", "description": "Send an email to a recipient", "parameters": {"type": "object", "properties": {"to": {"type": "string"}, "body": {"type": "string"}}, "required": ["to", "body"]}, "defer_loading": true}
  ]
}

Cases 1 to 26, the same on both legs, with cases 27 to 31 listed further down. Every curl passes "${H[@]}", set with H=(-H "Authorization: Bearer $LITELLM_MASTER_KEY" -H "Content-Type: application/json"), with -N for the streaming cases, and the 200 bodies below are trimmed to their output items

  1. req_claude.json as above, every function tool deferred
  2. req_claude_v2.json, the same with defer_loading removed from send_email
  3. req_claude_stream.json, case 1 with "stream": true
  4. req_gpt.json, case 1 with "model": "gpt-5.6", the OpenAI passthrough control
  5. OpenAI Python SDK (openai 2.33.0), client.responses.create(**case1) non-streaming and with stream=True
  6. req_bedrock_claude_converse.json, case 1 with "model": "bedrock-claude-converse"
  7. req_bedrock_claude_invoke.json, case 1 with "model": "bedrock-claude-invoke"
  8. req_fn_named_like_search.json, one plain function tool named tool_search_tool_regex and no tool_search tool
  9. req_defer_false_string.json, case 1 with "defer_loading": "false" (a string) on get_weather, and 9b, req_defer_false_string_drop.json, the same with "drop_params": true
  10. req_turn2_prev.json, the follow-up turn: previous_response_id set to case 1's response id and a function_call_output of {"temp_c": 18, "condition": "cloudy"} for its get_weather call
  11. POST /v1/chat/completions with req_chat_turn1.json: the same question with Anthropic's native tool_search_tool_regex_20251119 tool and the three deferred function tools, then turn 2 replays its assistant message two ways, 2a answering only the get_weather call and 2b answering the search call too
  12. req_vertex_claude.json, case 1 with "model": "vertex-claude" (vertex_ai/claude-sonnet-4-5, since 5.5 on Vertex answered 429)
  13. req_gpt_replay_claude.json, an after-leg case 1 turn (ids tsc_srvtoolu_ and fc_toolu_) replayed to gpt-5.6 with the same tools and a function_call_output for get_weather
  14. req_fallback_to_claude.json, case 1 with "model": "gpt-broken", an OpenAI deployment with an invalid key whose router fallback is claude-sonnet-5-5, the customer's OpenAI-first setup
  15. req_turn2_gemini.json, case 10's follow-up sent to "model": "gemini-flash" (gemini/gemini-3.8-flash) with a fresh case 1's previous_response_id
  16. req_turn2_mistral_plain.json, a control with no tool search: a Claude turn 1 with one plain get_weather tool (req_claude_plain.json), then its follow-up sent to "model": "mistral-small" with previous_response_id
  17. req_namespace.json, tool_search with two namespaces, weather holding get_current and crm holding get_customer, each member deferred
  18. req_native_plus_search.json, Anthropic's native tool_search_tool_regex_20251119 tool and OpenAI's tool_search in one request, with case 1's deferred function tools
  19. req_guard_malformed.json, case 1 with "defer_loading": "false" on get_weather, sent to a proxy booted with config_guard.yaml (a default_on pre-call guardrail and litellm_settings.drop_params: true)
  20. req_namespace_junk_drop.json, tool_search with a weather namespace whose members are the string "not a tool", get_current with "defer_loading": "false", and a deferred get_stock_price, with "drop_params": true
  21. req_allowed_callers_string.json, one function tool with "allowed_callers": "direct" and no drop_params
  22. req_replay_t1.json with "store": true, then turn 2 replays turn 1 the way a chat-style client does, the srvtoolu_ search call as a plain function_call, and turn 3 sends turn 2's previous_response_id to mistral-small
  23. req_gpt.json (case 4), then a turn 2 that replays every output item exactly as the proxy returned it, with a function_call_output for get_weather
  24. req_gpt.json with "stream": true, the streaming control for case 23
  25. case25.py req_claude.json, the SDK client with no proxy. A litellm.Router whose gpt-primary (openai/gpt-5.6, invalid key) falls back to anthropic/claude-sonnet-5-5 runs aresponses with case 1's input and tools, plain and with stream=True, and 25b calls litellm.responses(model="anthropic/claude-sonnet-5-5")
  26. 26a req_gpt.json and 26b req_claude.json, sent to a proxy booted with config_guard2.yaml, whose guardrail hands back only the tools of type function it is given

case25.py and function_only_guardrail.py are in this gist

Raw command and output follow for the cases the User Flow narrates (1, 2, 3, 10, 14, 15, and the SDK case 25, with case 2 on the before leg only, since its after run matches case 1), trimmed to the output items, with long ids cut and $PORT standing in for each leg's random port. Every case's result is in the table after them

Before (7fa52b2)

Case 1, every function tool deferred

$ curl -sS http://localhost:$PORT/v1/responses "${H[@]}" -d @req_claude.json -w '\nHTTP %{http_code}\n'
# 2026-10-14T06:25:32Z at 7fa52b2d21
{"error": {"message": "litellm.BadRequestError: AnthropicException - {"type":"error","error":{"type":"invalid_request_error","message":"At least one tool must have defer_loading=false. All tools cannot be deferred."},"request_id":"req_011Cg1eoRGCRLp9k1CKyx6dy"}\n\nLiteLLM: model group 'claude-sonnet-5-5' failed with the error above and no fallback model...", "code": "400"}}
HTTP 400

Case 2, send_email left undeferred

$ curl -sS http://localhost:$PORT/v1/responses "${H[@]}" -d @req_claude_v2.json -w '\nHTTP %{http_code}\n'
# 2026-10-14T06:25:36Z at 7fa52b2d21
{"id": "resp_o4mVl9PraLaqh5JFaiQ...", "model": "claude-sonnet-5-5", "status": "completed",
  "output": [
    {"type": "reasoning", "id": "rs_d487650a-07b7-4703-86aa-8d411c173e89", "summary": "..."},
    {"type": "message", "role": "assistant", "content": [{"type": "output_text", "text": "I can't check the weather in Paris because I don't have a weather tool. The only tool I have is one for sending emails, and it can't look up current conditions. I don't want to guess or make up a forecast.  To get the cu..."}]}
  ]}
HTTP 200

Case 3, case 1 streamed

$ curl -sS -N http://localhost:$PORT/v1/responses "${H[@]}" -d @req_claude_stream.json -w '\nHTTP %{http_code}\n'
# 2026-10-14T06:25:39Z at 7fa52b2d21
{"error": {"message": "litellm.BadRequestError: AnthropicException - b\'{...\"message\":\"At least one tool must have defer_loading=false. All tools cannot be deferred.\"}...", "code": "400"}}
HTTP 400

Case 14, an OpenAI group falling back to Claude

$ curl -sS http://localhost:$PORT/v1/responses "${H[@]}" -d @req_fallback_to_claude.json -w '\nHTTP %{http_code}\n'
# 2026-10-14T06:27:10Z at 7fa52b2d21
{"error": {"message": "litellm.AuthenticationError: AuthenticationError: OpenAIException - {\n  "error": {\n    "message": "Incorrect API key provided: sk-delib*********************************back. You can find your API key at https://platform.openai.com/account/api-keys.",\n    "type": "invalid_request_error",\n    "code": "invalid_api_key",\n    "param"...
  ... Fallback to claude-sonnet-5-5 also failed: litellm.BadRequestError: AnthropicException - {"type":"error","error":{"type":"invalid_request_error","message":"At least one tool must have defer_loading=false. All tools cannot be deferred.", "code": "401"}}
HTTP 401

Case 15, the follow-up turn sent to gemini-flash

# Turn 1 is case 1 again on claude-sonnet-5-5, at 2026-10-14T06:27:11Z, and it answered the same HTTP 400
# Turn 2 (req_turn2_gemini.json to gemini-flash with this turn 1 id) not sent: turn 1 answered HTTP 400 with no response id and no get_weather call to answer

Case 25, the SDK client with no proxy, an OpenAI deployment falling back to Claude

$ $ROOT/.venv/bin/python case25.py req_claude.json
# 2026-10-14T06:31:07Z at 7fa52b2d21
06:31:22 - LiteLLM:WARNING: transformation.py:2060 - Dropping Responses API tool of type 'tool_search': it has no Chat Completions equivalent and the target provider would reject the request.
litellm <leg root>/base/litellm/__init__.py
=== 25 router.aresponses(model='gpt-primary') non-streaming ===
EXCEPTION AuthenticationError litellm.AuthenticationError: AuthenticationError: OpenAIException - {
LiteLLM: model group 'gpt-primary' failed with the error above. Fallback to claude also failed: litellm.BadRequestError: AnthropicException
=== 25 router.aresponses(model='gpt-primary', stream=True) ===
EXCEPTION RouterRateLimitError No deployments available for selected model, Try again in 5 seconds. All deployments for selected model are in cooldown. Passed model=gpt-primary. pre-call-checks=False, cooldown_list=['64742fe5130fee4c6aef5464ba27cd5eeeb7bd7a6abb494360a1c249968911f3']
=== 25b litellm.responses(model='anthropic/claude-sonnet-5-5') non-streaming ===
EXCEPTION BadRequestError litellm.BadRequestError: AnthropicException - {"type":"error","error":{"type":"invalid_request_error","message":"At least one tool must have defer_loading=false. All tools cannot be deferred."},"request_id":"req_011Cg1fF6EBFBcA6srd2281B"}
exit 0

Case 10 was not sent on the before leg, since its turn 1 is case 1, which answered 400 with no response id and no get_weather call to answer

After (85bee09)

Case 1, every function tool deferred

$ curl -sS http://localhost:$PORT/v1/responses "${H[@]}" -d @req_claude.json -w '\nHTTP %{http_code}\n'
# 2026-10-14T09:32:33Z at 85bee0905c
{"id": "resp_-KLzyySF-qgUeBzQH2...", "model": "claude-sonnet-5-5", "status": "completed",
  "output": [
    {"id": "tsc_srvtoolu_01Psr2pSeP1RityR8JxTVX27", "arguments": {"pattern": "weather|forecast|temperature"}, "call_id": "srvtoolu_01Psr2pSeP1RityR8JxTVX27", "execution": "server", "status": "completed", "type": "tool_search_call"},
    {"arguments": "{\"city\": \"Paris\"}", "call_id": "toolu_01PesPStw88Cp9Vjq7vXP4yX", "name": "get_weather", "type": "function_call", "id": "fc_toolu_01PesPStw88Cp9Vjq7vXP4yX", "namespace": null, "status": "completed"}
  ]}
HTTP 200

Case 3, case 1 streamed

$ curl -sS -N http://localhost:$PORT/v1/responses "${H[@]}" -d @req_claude_stream.json -w '\nHTTP %{http_code}\n'
# 2026-10-14T09:32:37Z at 85bee0905c
data: {"type":"response.created","response":{"id":"resp_ILYFPOeFXG0O..."...
data: {"type":"response.in_progress","response":{"id":"resp_ILYFPOeFXG0O..."...
data: {"type":"response.output_item.added","output_index":0,"item":{"id":"tsc_srvtoolu_01J7U8KHaggJjqMzEZ5rwicU","arguments":{},"call_id"...
data: {"type":"response.output_item.added","output_index":1,"item":{"type":"function_call","id":"fc_toolu_01X37RWYbDS2d6a3bhRR9HBJ","call...
data: {"type":"response.function_call_arguments.delta","item_id":"fc_toolu_01X37RWYbDS2d6a3bhRR9HBJ","output_index":1,"delta":"{\"city\""...
data: {"type":"response.function_call_arguments.delta","item_id":"fc_toolu_01X37RWYbDS2d6a3bhRR9HBJ","output_index":1,"delta":": \"Pari",...
data: {"type":"response.function_call_arguments.delta","item_id":"fc_toolu_01X37RWYbDS2d6a3bhRR9HBJ","output_index":1,"delta":"s\"}","mod...
data: {"type":"response.output_item.done","output_index":0,"sequence_number":9,"item":{"id":"tsc_srvtoolu_01J7U8KHaggJjqMzEZ5rwicU","argu...
data: {"type":"response.function_call_arguments.done","item_id":"fc_toolu_01X37RWYbDS2d6a3bhRR9HBJ","output_index":1,"arguments":"{\"city...
data: {"type":"response.output_item.done","output_index":1,"sequence_number":11,"item":{"type":"function_call","id":"fc_toolu_01X37RWYbDS...
data: {"type":"response.completed","response":{"id":"resp_ILYFPOeFXG0O..."...
data: [DONE]
HTTP 200

Case 10, the follow-up turn with previous_response_id

$ curl -sS http://localhost:$PORT/v1/responses "${H[@]}" -d @req_turn2_prev_head.json -w '\nHTTP %{http_code}\n'
# 2026-10-14T09:32:51Z at 85bee0905c
{"id": "resp_AXtshc5Wj53eIY4WLF...", "model": "claude-sonnet-5-5", "status": "completed",
  "output": [
    {"type": "reasoning", "status": "completed", "role": "assistant", "content": [], "encrypted_content": "..."},
    {"type": "message", "status": "completed", "role": "assistant", "content": [{"type": "output_text", "text": "It's currently 18°C (about 64°F) and cloudy in Paris.\n\nI should mention that `get_weather` wasn't in my list of available tools, and I called it without searching for it first. The call returned a result, but I can't confirm how current the data is.", "annotations": []}]}
  ]}
HTTP 200

Case 14, an OpenAI group falling back to Claude

$ curl -sS http://localhost:$PORT/v1/responses "${H[@]}" -d @req_fallback_to_claude.json -w '\nHTTP %{http_code}\n'
# 2026-10-14T09:33:01Z at 85bee0905c
{"id": "resp_JtFUXet4VxiIcH6n4l...", "model": "claude-sonnet-5-5", "status": "completed",
  "output": [
    {"arguments": {"pattern": "weather|forecast|temperature"}, "execution": "server", "status": "completed", "type": "tool_search_call"},
    {"arguments": "{\"city\": \"Paris\"}", "name": "get_weather", "type": "function_call", "status": "completed"}
  ]}
HTTP 200
x-litellm-attempted-fallbacks: 1

Case 15, the follow-up turn sent to gemini-flash

# Turn 1
$ curl -sS http://localhost:$PORT/v1/responses "${H[@]}" -d @req_claude.json -w '\nHTTP %{http_code}\n'
# 2026-10-14T09:33:02Z at 85bee0905c
{"id": "resp_kyVV3MDEE3-qyMmW1l...", "model": "claude-sonnet-5-5", "status": "completed",
  "output": [
    {"arguments": {"pattern": "weather"}, "execution": "server", "status": "completed", "type": "tool_search_call"},
    {"arguments": "{\"city\": \"Paris\"}", "name": "get_weather", "type": "function_call", "status": "completed"}
  ]}
HTTP 200
# Turn 2
$ curl -sS http://localhost:$PORT/v1/responses "${H[@]}" -d @req_turn2_gemini_head.json -w '\nHTTP %{http_code}\n'
# 2026-10-14T09:33:04Z at 85bee0905c
{"id": "resp_wAhoPY8ZEKs5tAat7J...", "model": "gemini-flash", "status": "completed",
  "output": [
    {"type": "message", "status": "completed", "role": "assistant", "content": [{"type": "output_text", "text": "The current weather in Paris is cloudy with a temperature of 18°C.", "annotations": []}]}
  ]}
HTTP 200

Case 25, the SDK client with no proxy, an OpenAI deployment falling back to Claude

$ $ROOT/.venv/bin/python case25.py req_claude.json
# 2026-10-14T09:33:21Z at 85bee0905c
litellm <leg root>/head/litellm/__init__.py
=== 25 router.aresponses(model='gpt-primary') non-streaming ===
model: claude-sonnet-5-5
output types: ['tool_search_call', 'function_call']
  item: {"arguments": {"pattern": "weather|forecast|temperature"}, "execution": "server", "status": "completed", "type": "tool_search_call"}
  item: {"arguments": "{\"city\": \"Paris\"}", "name": "get_weather", "type": "function_call", "status": "completed"}
=== 25 router.aresponses(model='gpt-primary', stream=True) ===
response.created
response.in_progress
response.output_item.added item.type=tool_search_call
response.output_item.added item.type=function_call
response.function_call_arguments.delta
response.function_call_arguments.delta
response.function_call_arguments.delta
response.output_item.done item.type=tool_search_call
response.function_call_arguments.done
response.output_item.done item.type=function_call
response.completed
  completed output types: ['tool_search_call', 'function_call']
=== 25b litellm.responses(model='anthropic/claude-sonnet-5-5') non-streaming ===
model: claude-sonnet-5-5
output types: ['tool_search_call', 'function_call']
  item: {"arguments": {"pattern": "weather|forecast|temperature"}, "execution": "server", "status": "completed", "type": "tool_search_call"}
  item: {"arguments": "{\"city\": \"Paris\"}", "name": "get_weather", "type": "function_call", "status": "completed"}

Cases 27 to 32

These came from the caveats rounds. The before leg ran cases 27 to 30 at 7fa52b2 through a fourth proxy booted from config_r3.yaml, which is the config above plus one Microsoft Foundry deployment, and case 31 through a fifth booted from config_r4.yaml, which is config_r3.yaml plus the mask-weather guardrail. Case 32 ran on the before leg through that fifth proxy. The after leg ran every case at 85bee09 through one proxy booted from config_r4.yaml, and the guardrail is default_on: false, so only case 31 calls it

  - model_name: azure-claude
    litellm_params:
      model: azure_ai/claude-sonnet-4-6
      api_base: os.environ/E2E_CLAUDE_FOUNDRY_API_BASE
      api_key: os.environ/E2E_CLAUDE_FOUNDRY_API_KEY
guardrails:
  - guardrail_name: mask-weather
    litellm_params:
      guardrail: litellm_content_filter
      mode: post_call
      default_on: false
      blocked_words:
        - keyword: weather
          action: MASK
  1. req_azure_claude.json, case 1 with "model": "azure-claude"
  2. POST /v1/chat/completions with req_chat_turn2_all.json (case 11's turn 2b, the search call answered beside get_weather), and req_chat_turn2_err.json, the same with the search answered by an error string, each sampled three times
  3. POST /v1/chat/completions with req_chat_system_before_search_turn.json: user, a system message, an assistant turn holding only an unanswered srvtoolu_ search call, then user
  4. POST /v1/chat/completions with req_chat_search_only_answered.json: an assistant turn holding only the search call, with the caller's tool answer last
  5. req_native_plus_search_guard.json, case 18 with "guardrails": ["mask-weather"], then req_native_plus_search_guard_stream.json, the same with "stream": true. The question has "weather" in it, so Claude's search pattern does too
  6. Case 2's tools with no search tool, so get_weather and get_stock_price stay deferred and send_email does not: 32a req_nosearch_claude.json to claude-sonnet-5-5, 32b req_nosearch_gpt.json to gpt-5.6, 32c req_client_search_claude.json, which is 32a plus {"type": "tool_search", "execution": "client"}, 32d req_nosearch_bedrock_invoke.json to bedrock-claude-invoke, and 32e req_nosearch_mistral.json to mistral-small

Before (7fa52b2)

$ curl -sS http://localhost:$PORT/v1/responses "${H[@]}" -d @req_azure_claude.json -w '\nHTTP %{http_code}\n'
{"error": {"message": "litellm.BadRequestError: Azure_aiException - {\"type\":\"error\",\"error\":{\"type\":\"invalid_request_error\",\"message\":\"At least one tool must have defer_loading=false. All tools cannot be deferred.\"}, ...
HTTP 400

$ curl -sS http://localhost:$PORT/v1/chat/completions "${H[@]}" -d @req_chat_system_before_search_turn.json -w '\nHTTP %{http_code}\n'
{"error": {"message": "litellm.BadRequestError: AnthropicException - ... messages.2: `tool_use` ids were found without `tool_result` blocks immediately after: srvtoolu_01MWehAZSCG557P2p2sFp7QK. ...
HTTP 400

Case 30 answered 200 with the same get_weather call on the base (2026-10-14T07:26:52Z)

Case 31, the masking guardrail on the search pattern, trimmed to each item's type, name, arguments, and status

$ curl -sS http://localhost:$PORT/v1/responses "${H[@]}" -d @req_native_plus_search_guard.json -w '\nHTTP %{http_code}\n'
# 2026-10-14T08:22:06Z at 7fa52b2d21
{"model": "claude-sonnet-5-5", "status": "completed",
  "output": [
    {"arguments": "{\"pattern\": \"[KEYWORD_REDACTED]|forecast|temperature\"}", "name": "tool_search_tool_regex", "type": "function_call", "status": "completed"},
    {"arguments": "{\"city\": \"Paris\"}", "name": "get_weather", "type": "function_call", "status": "completed"}
  ]}
HTTP 200
$ curl -sS -N http://localhost:$PORT/v1/responses "${H[@]}" -d @req_native_plus_search_guard_stream.json -w '\nHTTP %{http_code}\n'
# 2026-10-14T08:22:09Z at 7fa52b2d21
data: {"type": "response.output_item.done", "output_index": 0, "item": {"type": "function_call", "name": "tool_search_tool_regex", "status": "completed", "arguments": "{\"pattern\": \"weather|forecast|temperature\"}"}}
data: {"type": "response.output_item.done", "output_index": 1, "item": {"type": "function_call", "name": "get_weather", "status": "completed", "arguments": "{\"city\": \"Paris\"}"}}
data: [DONE]
HTTP 200

After (85bee09)

Case 27, Claude on azure_ai

$ curl -sS http://localhost:$PORT/v1/responses "${H[@]}" -d @req_azure_claude.json -w '\nHTTP %{http_code}\n'
# 2026-10-14T09:33:38Z at 85bee0905c
{"id": "resp_wNVcP-uD11aEBw-2Zm...", "model": "azure-claude", "status": "completed",
  "output": [
    {"type": "message", "status": "completed", "role": "assistant", "content": [{"type": "output_text", "text": "Let me search for a weather tool..."}]},
    {"arguments": {"pattern": "weather"}, "execution": "server", "status": "completed", "type": "tool_search_call"},
    {"arguments": "{\"city\": \"Paris\"}", "name": "get_weather", "type": "function_call", "status": "completed"}
  ]}
HTTP 200
x-litellm-model-group: azure-claude

Case 28, the search call answered with an error beside get_weather

$ curl -sS http://localhost:$PORT/v1/chat/completions "${H[@]}" -d @req_chat_turn2_err.json -w '\nHTTP %{http_code}\n'
# 2026-10-14T09:33:40Z at 85bee0905c
{"id": "chatcmpl-acc7ff59-9401-...", "model": "claude-sonnet-5-5", "choices": [{"finish_reason": "stop", "message": {"content": "It's currently 18°C (about 64°F) and cloudy in Paris.", "role": "assistant"}}]}
HTTP 200

Case 29, a system message before a search-only turn

$ curl -sS http://localhost:$PORT/v1/chat/completions "${H[@]}" -d @req_chat_system_before_search_turn.json -w '\nHTTP %{http_code}\n'
# 2026-10-14T09:33:41Z at 85bee0905c
{"id": "chatcmpl-497207fd-83c1-...", "model": "claude-sonnet-5-5", "choices": [{"finish_reason": "tool_calls", "message": {"role": "assistant", "tool_calls": [{"function": {"arguments": "{\"pattern\": \"weather\"}", "name": "tool_search_tool_regex"}, "id": "srvtoolu_01QmzLtoDKwBmPqAR1wYidqb", "type": "function"}, {"function": {"arguments": "{\"city\": \"Paris\"}", "name": "get_weather"}, "id": "toolu_01C8qi6VU8HVrwNRFmf67Gwj", "type": "function"}]}}]}
HTTP 200

Case 30, a search-only turn the caller answered

$ curl -sS http://localhost:$PORT/v1/chat/completions "${H[@]}" -d @req_chat_search_only_answered.json -w '\nHTTP %{http_code}\n'
# 2026-10-14T09:33:43Z at 85bee0905c
{"id": "chatcmpl-fd90db89-aefc-...", "model": "claude-sonnet-5-5", "choices": [{"finish_reason": "tool_calls", "message": {"role": "assistant", "tool_calls": [{"function": {"arguments": "{\"location\": \"Paris\"}", "name": "get_weather"}, "id": "toolu_01DtqfiA65UEuoj8Ptckn7ue", "type": "function"}]}}]}
HTTP 200

Case 31, the masking guardrail on the search pattern, trimmed to each item's type, name, arguments, and status

$ curl -sS http://localhost:$PORT/v1/responses "${H[@]}" -d @req_native_plus_search_guard.json -w '\nHTTP %{http_code}\n'
# 2026-10-14T09:33:43Z at 85bee0905c
{"model": "claude-sonnet-5-5", "status": "completed",
  "output": [
    {"arguments": {"pattern": "[KEYWORD_REDACTED]|forecast|temperature"}, "status": "completed", "type": "tool_search_call"},
    {"arguments": "{\"city\": \"Paris\"}", "name": "get_weather", "type": "function_call", "status": "completed"}
  ]}
HTTP 200
$ curl -sS -N http://localhost:$PORT/v1/responses "${H[@]}" -d @req_native_plus_search_guard_stream.json -w '\nHTTP %{http_code}\n'
# 2026-10-14T09:33:45Z at 85bee0905c
data: {"type": "response.output_item.done", "output_index": 0, "item": {"arguments": {"pattern": "weather|forecast|temperature"}, "status": "completed", "type": "tool_search_call"}}
data: {"type": "response.output_item.done", "output_index": 1, "item": {"type": "function_call", "name": "get_weather", "status": "completed", "arguments": "{\"city\": \"Paris\"}"}}
data: [DONE]
HTTP 200
Case 28, every sampled answer
# head 85bee0905c, 2026-10-14T09:34:41Z
-- answered with search result
It's currently 18 °C (64 °F) and cloudy in Paris.
It's currently 18 °C (about 64 °F) and cloudy in Paris.
It's currently 18 °C (about 64 °F) and cloudy in Paris.
-- answered with error
It's currently 18°C (about 64°F) and cloudy in Paris.
It's currently about 18 °C (64 °F) and cloudy in Paris.  My search for a weather tool returned an error. The `get_weather` call still worked, and that's where these numbers come from.
It's currently 18 °C (about 64 °F) and cloudy in Paris.

# base 7fa52b2d21, 2026-10-14T07:31Z
-- answered with search result
It's currently 18 °C (about 64 °F) and cloudy in Paris.
It's 18 °C and cloudy in Paris right now.
It's currently 18 °C (about 64 °F) and cloudy in Paris.
-- answered with error
It's currently 18°C (about 64°F) and cloudy in Paris.
The weather in Paris right now is cloudy, with a temperature of 18 °C (about 64 °F).
It's currently 18 °C (about 64 °F) and cloudy in Paris.

# reverted attempt c3c38ba836, which dropped the answered search pair, 2026-10-14T07:31Z
-- answered with search result
It's currently 18°C (about 64°F) and cloudy in Paris.  I called `get_weather` directly, even thou...
It's currently 18°C (64°F) and cloudy in Paris.  I should mention that `get_weather` wasn't in my...
It's currently 18°C (about 64°F) and cloudy in Paris.  I called `get_weather` directly without se...
-- answered with error
It's currently 18°C (about 64°F) and cloudy in Paris.  I should mention that `get_weather` wasn't...
It's currently 18°C (64°F) and cloudy in Paris.
It's currently 18°C (about 64°F) and cloudy in Paris.

Case 32 on both legs, trimmed to each output item's type, the message text's first 45 characters, the function call, and the input token count

$ curl -sS http://localhost:$PORT/v1/responses "${H[@]}" -d @req_nosearch_claude.json -w '\nHTTP %{http_code}\n'
# base 7fa52b2d21, 2026-10-14T09:31:45Z
{"output": ["reasoning", {"type": "message", "text": "I can't check the current weather in Paris. T..."}], "input_tokens": 491}
HTTP 200
# head 85bee0905c, 2026-10-14T09:32:22Z
{"output": ["reasoning", {"type": "message", "text": "I can't check the weather in Paris right now...."}], "input_tokens": 491}
HTTP 200

$ curl -sS http://localhost:$PORT/v1/responses "${H[@]}" -d @req_nosearch_gpt.json -w '\nHTTP %{http_code}\n'
# base 7fa52b2d21, 2026-10-14T09:31:49Z
{"error": {"message": "...Deferred tools require tools.tool_search. ...", "code": "400"}}
HTTP 400
# head 85bee0905c, 2026-10-14T09:32:26Z
{"error": {"message": "...Deferred tools require tools.tool_search. ...", "code": "400"}}
HTTP 400

$ for f in req_client_search_claude.json req_nosearch_bedrock_invoke.json; do curl -sS http://localhost:$PORT/v1/responses "${H[@]}" -d @$f -w '\nHTTP %{http_code}\n'; done
# base 7fa52b2d21, 2026-10-14T09:31:52Z, and head 85bee0905c, 2026-10-14T09:32:27Z, each answered both files with
{"output": ["reasoning", {"type": "message", "text": "I can't check the weather in Paris ..."}], "input_tokens": 491}
HTTP 200

$ curl -sS http://localhost:$PORT/v1/responses "${H[@]}" -d @req_nosearch_mistral.json -w '\nHTTP %{http_code}\n'
# base 7fa52b2d21, 2026-10-14T09:32:00Z
{"error": {"message": "...\"defer_loading\"],\"msg\":\"Extra inputs are not permitted ...", "code": "422"}}
HTTP 422
# head 85bee0905c, 2026-10-14T09:32:32Z
{"output": [{"type": "function_call", "name": "get_weather", "arguments": "{\"city\": \"Paris\"}"}], "input_tokens": 223}
HTTP 200

Cases 33 and 34

Both went to a fourth proxy on each leg, booted from this config plus a mask-paris post-call litellm_content_filter that masks Paris and a mask-pipe policy attached to a gpt-pipe group (openai/gpt-5.6) whose post_call pipeline runs that one guardrail. Case 33 streams a gpt-pipe request with tool_search and a deferred get_weather. Case 34 sends case 1 with "execution": "" on its tool_search tool, then adds "drop_params": true

$ curl -sS -N http://localhost:$PORT/v1/responses "${H[@]}" -d @req_pipe_native_stream.json -w '\nHTTP %{http_code}\n'
# base 7fa52b2d21, 2026-10-14T10:40:32Z
data: {"type":"response.output_item.done","item":{"type":"tool_search_call","arguments":{"paths":["weather"]}}}
data: {"type":"response.function_call_arguments.done","arguments":"{\"city\": \"[KEYWORD_REDACTED]\"}"}
# 85bee0905c, 2026-10-14T10:08:31Z
data: {"type":"response.function_call_arguments.done","arguments":"{\"city\":\"Paris\"}"}
# head 2e331eaee0, 2026-10-14T11:03:26Z
data: {"type":"response.output_item.done","item":{"type":"tool_search_call","arguments":{"paths":["weather"]}}}
data: {"type":"response.function_call_arguments.done","arguments":"{\"city\": \"[KEYWORD_REDACTED]\"}"}

$ curl -sS http://localhost:$PORT/v1/responses "${H[@]}" -d @req_exec_empty_claude.json -w '\nHTTP %{http_code}\n'
# base 7fa52b2d21, 2026-10-14T11:02:32Z
{"error": {"message": "...All tools cannot be deferred. ...", "code": "400"}}
# head 2e331eaee0, 2026-10-14T11:02:35Z
{"error": {"message": "...tool_search execution must be 'server' or 'client' ...", "code": "400"}}

$ curl -sS http://localhost:$PORT/v1/responses "${H[@]}" -d @req_exec_empty_claude_drop.json -w '\nHTTP %{http_code}\n'
# head 2e331eaee0, 2026-10-14T11:02:36Z
{"output": [{"type": "tool_search_call", "arguments": {"pattern": "weather|forecast|temperature"}}, {"type": "function_call", "name": "get_weather", "arguments": "{\"city\": \"Paris\"}"}]}
HTTP 200

Every case 33 run answered HTTP 200, and at 85bee09 the proxy logged the rewrite could not be written back ... 1 of the stream's 2 tool call items carry no call_id. In case 34 "execution": 5 answered the same 400s, the base gave the drop_params request its same 400, and the head's 400s made no upstream call. The streamed drop_params request streamed the same two items, and gemini-flash answered 200 with get_weather on both legs

Cases 35 and 36

These ran at e250d78, after main's #32511 started carrying cache_control through a previous_response_id replay, on one proxy from the merged tree with the config's claude-sonnet-5-5 and bedrock-claude-converse and a fresh Postgres. The base has neither change, so they ran on the merged tree only. Case 35 sends case 1 with "store": true and "cache_control": {"type": "ephemeral"} on its input message, then a follow-up to bedrock-claude-converse with that previous_response_id, the get_weather output, and a marked message. Case 36 sends bedrock-claude-converse five marked messages, with and without "drop_params": true

Raw command and output for both cases are in this gist as cases_35_36_raw.txt

The proxy's debug log shows case 35's Converse request with two cachePoint blocks (turn 1's mark and the new one) and the toolu_ call with its result, and without the srvtoolu_ search call. Case 36 sent 4 cachePoint blocks with drop_params and 5 without. Before the merge fix, this PR's named drop_params argument hid the flag from #32511's cap, and main's unit test for that cap failed on the merged tree

Cases 37 and 38

At 86ed5be, whose factory.py resolution puts the unanswered-search drop beside #46440's client-answered rule: cases 1, 3, 10, 11, 22 and 28 again, plus 11's turn 2c, the assistant message as returned with its tool_search_tool_result and get_weather answered. Two --num_workers 2 proxies with a worker-pid CustomLogger, this tip and main 7b7604f, real Anthropic claude-sonnet-5-5, a fresh Postgres, every turn 2 on the other worker. Scripts and raw output in this gist

Case main tip
37 case 1, and case 3 streamed 400 All tools cannot be deferred 200, tool_search_call then get_weather, streamed in the same order
37 case 10 follow-up not reached 200
38 case 11 turn 2a, search unanswered 400 tool_use ids were found without tool_result 200
38 turn 2b, search answered by the client, 3 of 3, and by an error string, 3 of 3 (case 28) 200 200
38 turn 2c, tool_search_tool_result kept (#46440) 200 200
38 case 22 turns 1 to 3 not reached 200, 200, then Mistral 422 on provider_specific_fields, as before

Every case

Case Before After
1 all deferred 400 all deferred 200 search, then call
2 one undeferred 200, no weather tool 200 search, then call
3 streamed 400 all deferred 200, events in order
4 gpt-5.6 control 200 native search 200 native search
5 OpenAI SDK 400 both modes 200 both modes
6 Bedrock Converse 200, no search 200, no search
7 Bedrock Invoke 400 all deferred 200 search, then call
8 search-like name 200 function call 200 function call
9 string defer_loading 500 400
9b same, drop_params 500 200
10 follow-up turn not sent 200, uses result
11 chat replay 2a 400 200
11 chat replay 2b 200 200
12 Vertex Claude 4.5 400 all deferred 200 search, then call
13 Claude turn to gpt-5.6 200 200
14 fallback to Claude 401, fallback 400 200 via fallback
15 Claude then Gemini 400 at turn 1 200 both turns
16 Claude then Mistral 200, then 422 200, then 422
17 namespaces 200, no search 200 search, then call
18 native plus tool_search search as function_call tool_search_call
19 guardrail, drop_params 500 200
20 junk namespace, drop_params 200 200
21 string allowed_callers 500 400
22 turns 1 and 2 400, then 400 200 both turns
22 turn 3 to Mistral not sent 422
23 replay gpt-5.6 items 200, then 400 200 both turns
24 gpt-5.6 streamed 200 200
25 SDK Router fallback 401, fallback 400 200 via fallback
25 SDK Router streamed cooldown, fallback 400 200, events in order
25b SDK litellm.responses 400 all deferred 200 search, then call
26a guardrail, gpt-5.6 200 native search 200 native search
26b guardrail, Claude 400 all deferred 200 search, then call
27 azure_ai Claude 400 all deferred 200 search, then call
28 answered search, chat 200, no skip claim 6 of 6 200, no skip claim 6 of 6
29 system before search turn 400 200
30 answered search-only turn 200 200
31 masking guardrail function_call masked tool_search_call masked
31 masking guardrail, streamed not masked not masked
32a, 32c, 32d Claude, no server search 200, deferred hidden 200, deferred hidden
32b no search, gpt-5.6 400 needs tool_search 400 needs tool_search
32e no search, Mistral 422 on defer_loading 200 function call
33 pipeline mask, gpt-5.6 streamed masked masked
34 execution: "", Claude 400 all deferred 400 on execution
34 same, drop_params 400 all deferred 200 search, then call
34 same, Gemini 200 function call 200 function call
35 Claude turn, then Converse replay not run 200, marks kept, no srvtoolu_
36 five marks, Converse, drop_params not run 200, 4 marks sent
36 same, no drop_params not run 400 from Bedrock

Audit round 3 of 3 (later commits fix caveats and /live-pr-risk findings past the cap, two of them High)

Round 3 ran at ba49b20 against the merge base f97d3df on a remote rig, each leg with its own Postgres, Redis response cache, and scripted upstream. The changed cells ran once on the base and twice on the head, and a control leg ran the cells this PR keeps

File Changed cells Base Head, 2 runs Controls
test_responses_bridge_tool_search_wire.py 60 red 58 green 12 green
test_responses_bridge_tool_search_undeferred_wire.py 25 red 25 green 12 green
test_responses_bridge_tool_search_chaos.py 12 red 12 green 2 green
test_responses_bridge_tool_search_replay_wire.py 8 red 8 green 9 green

The two head reds were real and are fixed past the cap at 67fe21b, where a string allowed_callers on a function tool answers 400 instead of 500 and a cache hit of a search turn no longer carries created_by: null. At 67fe21b the four files passed 138 of 140 cells, both of those included, and the other 2 hit the harness's 15-second client timeout while the box sat at load 58. The schema cell passes in-process at 67fe21b and fails at the base, so that timeout comes from the box. The Mistral 422 and the response cache key that ignores drop_params come from the base and are listed under Caveats with follow-up tickets

The commits after 67fe21b are merges of main, d9da2df (keeps tool_search out of the guardrail tool scan), the caveats fixes c3c38ba, 8c5409d, 681bd09, 333a5e8, and 85bee09, the /live-pr-risk fixes 7d1fc80 and 2e331ea, 6800449, which moves three wire cells to the new execution 400, and the merges of main at 2ae3d06 and e250d78. The QA above covers all of them, and at 299f63f the four files passed 149 of 149 cells on the rig

  • 299f63f passes /audit (cap: 3 of 3 rounds, the two failing cells fixed past the cap and green at 67fe21b, later fixes and the main merge covered by the QA above, the two inherited caveats shipped with fixes on follow-up tickets)

/live-pr-risk at 2e331ea

Two findings needed a fix, and both are fixed. At 85bee09 a policy pipeline mask let gpt-5.6's streamed function call arguments out unmasked when OpenAI's own search was in the stream, fixed at 7d1fc80 (case 33). 85bee09 also sent "execution": "" to Claude as a server search where OpenAI answers 400, fixed at 2e331ea (case 34). The other client-visible changes below ship on purpose, approved by mateo-berri at merge, with the reasons in Decisions

Base 7fa52b2 and the head ran side by side on the GCE box with 2 workers per side, and each leg compared status, body, the upstream requests a recording proxy saw (count, keys, size), and what a logging callback got. Four scouts and an agent that saw only the diff built the target list, HTTP routes first, then the SDK, then background paths

Breaking

Path Before After Disposition
Pipeline mask, native stream masked leaked at 85bee09 fixed, 7d1fc80
Post-call block, native search 200 400 code owner at merge
Post-call mask, native search not masked masked code owner at merge
defer_loading 0 or "" 200 400 code owner at merge
defer_loading list or "true" 500 after 5 s 400 code owner at merge
Bad allowed_callers, Mistral 422 400 code owner at merge
execution "" or 5, Claude tool dropped 400 code owner at merge
Two tool_search tools, Claude 200 400 code owner at merge

Backward incompatible

Contract Before After Disposition
Native search created_by: null kept key left out code owner at merge
azure_ai supports_tool_search null true code owner at merge
Foreign search id to OpenAI sent, 400 left out, 200 code owner at merge
Unanswered srvtoolu_ call, chat sent, 400 dropped, 200 code owner at merge

Regression risk. The complexity router's compaction converts tools without the route gate, so a malformed flag raises the same 400 there, read in code and not driven. Guardrails that read response tool calls (generic_guardrail_api, model_armor, tool_policy) now also get a search call named tool_search, and only the content filter and a custom guardrail were driven

Dependency graph. Verified live on both sides: /v1/responses on Anthropic, azure_ai, Vertex AI, Bedrock Invoke and Converse, OpenAI, Gemini, and Mistral, streamed and not, previous_response_id follow-ups, Router fallbacks from OpenAI to Claude and from Claude to Gemini, /v1/chat/completions replays on four Claude routes, /v1/messages, the content filter as a post-call guardrail and in a policy pipeline, a custom pre-call guardrail, spend logs with message redaction, and /v1/model/info. Tested by unit and integration suites only: the response cache, the OpenAPI schema, and litellm.supports_tool_search. No dashboard page reads supports_tool_search. The legacy integration and e2e suites ran on both legs at 85bee09. The accounting, management, cost and database lanes lost to a box outage there, the guardrail files the later fixes touch, and the open MCP and security reds ran again at 6800449. Every head red also fails on the base 7fa52b2 or passes when run again on the head, so none comes from this PR. One Vertex AI e2e case got a 429 from Google, Quota exceeded for aiplatform.googleapis.com/online_prediction_input_tokens_per_minute_per_base_model with base model: anthropic-claude-fable-5-1, which is a project quota and not a code failure

Not verified. Batch, the complexity router, shadow evaluation, background response polling, Presidio streaming, cold-storage spend log replay, OpenRouter, Databricks, and the generic_guardrail_api, model_armor, and tool_policy guardrails were not driven

  • 299f63f passes /live-pr-risk (both findings fixed, the main merge's replay and cache cap run again on the merged tree in cases 35 and 36, every other client-visible change approved at merge by the code owner the cost-map files require, mateo-berri or ryan-crabbe-berri)

Type

🐛 Bug Fix

Caveats (if any)

Medium

  • tool_search on /v1/chat/completions still raises Unsupported tool type, tracked on LIT-9580
  • Output guardrails now scan OpenAI's own tool_search_call on native routes, where the base passed it through
    • The release note should say a search pattern can now trip a post-call guardrail
  • Default Bedrock (Converse) drops tool_search and loads every tool
    • AWS answers that Converse does not support the tool search beta (live 2026-10-14)
    • Workaround is bedrock/invoke/ for tool search on Bedrock
  • Follow-up turns drop the stored search call, so Claude searches again
    • Its text can say it called get_weather without searching (case 10)
    • Replaying the search 400s once a later turn changes tools, follow-up ticket
  • Malformed defer_loading, allowed_callers, or execution answers 400 without drop_params
    • A Gemini or Mistral route that ignored 0 or "direct" before now answers 400 too, as OpenAI does
    • With drop_params it answers 200 (cases 9b, 19, 20, 34)
    • The release note should say requests that got 200 with these values now get 400
  • Claude routes the cost map cannot name drop tool_search with only a server warning
    • The other tools then lose defer_loading and load up front
    • A custom-named azure_ai deployment needs model_info.supports_tool_search: true
    • An application inference profile ARN needs model_id, since model_info cannot mark it as Claude
    • A Bedrock batch record drops it unless its model starts with bedrock/invoke/

Low

  • OpenRouter drops tool_search and loads every tool, follow-up ticket
  • A deferred MCP tool loses defer_loading on the Anthropic request, not checked live
  • A streamed search item finishes after the function call starts (case 3)
  • On Vertex and azure_ai, text written after the search comes first (cases 12, 27)
  • The chat path's own defer_loading check still answers 500, pre-existing
  • /v1/messages guardrail rewrites now drop an unanswered srvtoolu_ block
  • Validation 400 spend rows carry the public alias, not the deployment
  • The complexity router's compaction converts tools without the route gate
  • Claude-to-Mistral follow-ups answer 422 on stored fields, pre-existing, follow-up ticket
  • Output guardrails leave a streamed tool_search_call unscanned, like a streamed function_call on the base (case 31)
  • A guardrail that rewrites a tool returns it without its malformed flag
  • The response cache key ignores drop_params, pre-existing, follow-up ticket
  • A chat replay that answers the search with an error can make Claude mention it, pre-existing
  • A tool_search_call is litellm's OutputToolSearchCall on a fresh answer, the SDK's class on a cache hit
  • A deferred tool with no search tool loads up front on Gemini, Converse, and Mistral, which have no deferral, and Mistral answered 422 to the flag before (case 32e)

Final Attestation

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR

Note

High Risk
Touches Responses API translation, Anthropic message shaping, session replay, guardrails, and model capability gating—incorrect pairing or dropping of tool-search calls could break multi-turn tool flows or change client-visible 400/200 behavior.

Overview
Adds end-to-end support for OpenAI Responses API tool_search on Claude routes: server tool_search tools translate to Anthropic’s regex tool-search tool when the model registry says supports_tool_search, and provider srvtoolu_ search uses surface as tool_search_call output items (including streaming).

The Responses↔chat bridge gains tool_search.py, stricter validation for defer_loading, allowed_callers, and execution (400 or strip under drop_params), and strips unsupported server search on non-Anthropic follow-ups. Chat/Anthropic prompt conversion drops unanswered replayed tool-search uses while keeping caller-answered pairs; mid-conversation system placement treats unanswered search-only assistant turns as non-rendering.

litellm.supports_tool_search is exposed via lazy imports; azure_ai is included in the claude-tool-search cost-map rule. Output guardrails scan and rewrite tool_search_call items (keyed by call_id or item id when streaming). OpenAPI adds OutputToolSearchCall and defer_loading on chat tools.

Reviewed by Cursor Bugbot for commit 86ed5be. Bugbot is set up for automated code reviews on this repo. Configure here.

@devin-ai-integration

devin-ai-integration Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor Author

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@codspeed

codspeed Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

⚠️ 1 benchmark spent significant time in system calls

System calls cannot be consistently instrumented, so they are not included in the measure, which understates the real cost. Please switch to the Walltime instrument to accurately measure system calls.

Measurement and system calls

✅ 31 untouched benchmarks


Comparing litellm_responses_tool_search_anthropic (86ed5be) with main (6c78089)

Open in CodSpeed

@codecov

codecov Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

devin-ai-integration[bot]

This comment was marked as resolved.

… validate deferred tool fields

Bedrock Converse builds its own request and has no tool search, so the bridge now drops the tool_search tool there with a warning instead of sending a tool the transport loses, while Bedrock invoke, Anthropic, and Vertex keep it. A replayed tool_search_call with no stored result is dropped from the Anthropic request so a previous_response_id follow-up no longer answers 400. Only srvtoolu_ ids whose name is one of Anthropic's search tools count as search calls, so a caller function named like one stays a function call. A non-boolean defer_loading or a non-list allowed_callers now answers 400 instead of 500
… undeferred when no search tool goes out

A replayed Claude tool search call that the caller answered with a tool message kept its
tool_result in the user turn while its tool_use was dropped from the assistant turn, so
Anthropic answered 400 on the OpenAI-SDK tool loop. The search call is now dropped only when
no tool message answers it.

The Responses bridge now strips defer_loading from every tool whenever no tool search tool is
sent, whether the caller sent none or the route cannot run it, since a deferred tool with no
search tool can never be loaded. Namespace members had started carrying the flag to every
bridge provider, which providers that reject unknown tool keys answered 422.

The audit round-1 integration cells for the bridge wire and chaos paths ride in this commit.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Devin Review found 1 new potential issue.

Devin Review

assistant_tool_calls,
web_search_results=_web_search_results_tc,
tool_results=_tool_results_tc,
answered_tool_ids=answered_tool_call_ids(messages, msg_i),

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

🟡 Tool-heavy histories incur quadratic copies

For each assistant turn with tool calls, answered_tool_call_ids copies the remaining message history. A history with many tool turns therefore allocates quadratically while formatting one request

Learn more

The Anthropic formatter walks every assistant turn in a conversation. Each call slices messages[assistant_index:] in answered_tool_call_ids. List slicing copies the entire suffix before dropwhile and takewhile stop at the nearby tool results. When many assistant turns contain tool calls, total copied elements grow quadratically, even if there are no search calls.

Example: In an illustrative history of 1,000 assistant/tool exchanges, calls near the start copy almost 2,000 messages each. Calls near the end copy fewer, totaling roughly one million copied references for one request instead of a local scan per exchange

Recommended fix: Make answered_tool_call_ids iterate with itertools.islice(messages, assistant_index, None) or integer indexing from assistant_index. Stop after the immediately following run of tool results, without slicing the rest of the history

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The helper now walks lazily, skipping the assistant run and reading only the tool answers right after it, so each turn costs its own length

…e Anthropic search tools intact

A native tool_search_tool_regex_20251119 or tool_search_tool_bm25_20251119 tool the caller sends through /v1/responses passes through the bridge on every route as before, and the other tools keep defer_loading whenever any Anthropic search tool goes out. The route gate now drops the OpenAI tool_search item before translation instead of filtering the translated regex tool, so bm25 counts as a search tool. answered_tool_call_ids walks the history with islice instead of a slice copy. The tool_search_call output item drops its created_by field, which OpenAI rejects on a replayed input item and the streaming item never carried
…l_search_anthropic

# Conflicts:
#	tests/unit/responses/litellm_completion_transformation/test_litellm_completion_responses.py
@mateo-berri

Copy link
Copy Markdown
Contributor

@litereview code-review

@litereview

litereview Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

✅ code-review

5/5 · Ready for human review

Scope: full · Full PR review.

Completed · Some checks not run.

No correctness findings.

Checks and execution details
  • Passed · Real testing evidence (required): The PR changes translation code in the scoped paths: litellm/litellm_core_utils/prompt_templates/factory.py, mid_conversation_system.py, and litellm/llms/anthropic/chat/transformation.py (it drops unanswered srvtoolu_ search uses and adds strict defer_loading validation). It also changes Responses↔chat tool translation.

The new integration files in tests/integration/providers/test_responses_bridge_tool_search_*.py replay hand-built Anthropic payloads through a scripted upstream. I found no capture provenance for those payloads, so they do not satisfy the rule alone.

The manual E2E evidence does satisfy it:

  • The PR lists cases 37 and 38, run at head 86ed5be8c7.

  • They used two --num_workers 2 proxies and real Anthropic claude-sonnet-5-5, with main 7b7604f0ed as the control.

  • Gist c3e3a553acbcfaad86a98e6613d2df45 holds the scripts (responses_cases.sh, chat_cases.sh, config.yaml) and raw output.

  • I fetched out_responses_tip.txt. Case 1 returns HTTP 200 with tool_search_call then get_weather, and the case 10 follow-up returns 200.

  • I fetched out_chat_tip.txt. Turns 2a, 2b and 2c each return 200, including the unanswered-search drop in factory.py.

  • Earlier cases 1 to 36 ran live against Anthropic, Bedrock, Vertex, azure_ai, Gemini and Mistral, at commits the PR names.

  • Passed · Unit tests for changed modules (optional): I ran uv run pytest -n 8 on tests/unit/responses/litellm_completion_transformation/, the prompt_templates factory and mid_conversation_system tests, the responses guardrail handler tests, test_types_llms_openai.py, test_anthropic_chat_transformation.py, and test_fallback_generalizations.py. Result: 1679 passed.

  • Passed · Local translation reproducer (optional): /tmp/repro.py sends transform_responses_api_request_to_chat_completion_request a tool_search tool plus a deferred function, then runs AnthropicConfig.transform_request.

  • anthropic/claude-sonnet-4-5: the request carries tool_search_tool_regex_20251119, and the function keeps defer_loading: true.

  • gemini-2.5-flash, claude-3-haiku, and openrouter Claude: the bridge drops tool_search with a warning and strips defer_loading.

  • Not run · Gateway integration suites (tool_search wire/chaos/replay) (optional): These suites need the owned Postgres, Redis and scripted upstream rig from tests/integration/run.py, which I did not start. The PR reports 149 of 149 cells passing at 299f63fdb3.


View review · Reviewed 86ed5be8c73e

…stored search calls off non-Anthropic follow-ups

With drop_params on, a non-boolean defer_loading or a non-list allowed_callers on a Responses API tool (or a namespace member) is dropped before the bridge instead of answering 400, so only a request without drop_params gets the 400. A custom tool now carries defer_loading to the chat tool like a function tool does

A previous_response_id follow-up routed to a provider that does not build an Anthropic request no longer replays the stored Claude search call (srvtoolu_ id) as a client tool call. Mistral answered that history 400 "Unexpected tool call id". An assistant turn that held only the search call is dropped there. The Anthropic route keeps the call, since its factory pairs it with the stored result

The tool_search_call output model is renamed OutputToolSearchCall so the proxy's OpenAPI schema keeps the OpenAI SDK's ResponseToolSearchCall name. answered_tool_call_ids reads the history by index, so the lookup is linear in the history length. The streaming done event reads the response it is given, which is the same object it used to read from the iterator
@mateo-berri

Copy link
Copy Markdown
Contributor

@litereview code-review

@litereview

litereview Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

@mateo-berri

Copy link
Copy Markdown
Contributor

@litereview code-review

@litereview

litereview Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

@veria-ai

veria-ai Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

PR overview

All previously flagged issues have been addressed. No open security concerns remain on this pull request.

Security review

No open security issues remain on this pull request.

Fixed/addressed: 3 · PR risk: 0/10

…ol, and keep replays clean off Anthropic

A function tool whose allowed_callers is not a list of strings now answers 400
instead of 500. The guardrail scan reads tools without malformed flags, so the
route decides between a 400 and a drop under drop_params. When the caller sends
a native Anthropic search tool beside tool_search, only the native one goes out.
Databricks Claude no longer counts as an Anthropic request route.

A previous_response_id follow-up off Anthropic also drops a search call the
client replayed as a function_call with a srvtoolu_ id, and its output. The
answered tool id scan in the Anthropic message factory runs once per assistant
run instead of once per message. A null created_by on tool_search_call and
tool_search_output output items is left out of the serialized response, so a
cache hit returns the same keys as the first call.
@mateo-berri

Copy link
Copy Markdown
Contributor

@litereview code-review

@mateo-berri

Copy link
Copy Markdown
Contributor

bugbot run

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

…l_search_anthropic

# Conflicts:
#	litellm/llms/anthropic/chat/transformation.py
@mateo-berri

Copy link
Copy Markdown
Contributor

@litereview code-review

…il tool scan

The scan translated tool_search into Anthropic's regex search tool on every
route, so a guardrail returning only function tools removed tool_search from
native OpenAI requests and OpenAI answered 400 for the deferred tools
@mateo-berri

Copy link
Copy Markdown
Contributor

@litereview code-review

@mateo-berri

Copy link
Copy Markdown
Contributor

@litellm-stampbot

@litellm-stampbot

Copy link
Copy Markdown

litellm-stampbot: risk high

Not approved at 6800449. risk is high, a human reviewer is needed.

Rules (stampbot/risk_rules.yml):

  • high: 1097 source lines in 19 source files is over the 400 line / 10 file cap (tests, docs, cookbook and markdown are not counted)

Judge: skipped, the rules alone decided.

Pushes do not re-run this check. Comment @litellm-stampbot again to re-check the new head.

@litellm-stampbot litellm-stampbot Bot added the risk:high Sensitive, broad, or high-risk change label Oct 14, 2026
@mateo-berri
mateo-berri enabled auto-merge (squash) October 14, 2026 23:16
@greptile-apps

greptile-apps Bot commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

Automatic reviews are disabled for this repository.

@mateo-berri

Copy link
Copy Markdown
Contributor

bugbot run

@mateo-berri

Copy link
Copy Markdown
Contributor

@litereview code-review

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Stale Bugbot comment from a previous run.

's client-answered replay beside the unanswered search-call drop

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@mateo-berri

Copy link
Copy Markdown
Contributor

@litereview code-review

1 similar comment
@mateo-berri

Copy link
Copy Markdown
Contributor

@litereview code-review

@mateo-berri

Copy link
Copy Markdown
Contributor

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 86ed5be. Configure here.

@mateo-berri mateo-berri left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@mateo-berri
mateo-berri merged commit 314f179 into main Oct 15, 2026
108 of 109 checks passed
@mateo-berri
mateo-berri deleted the litellm_responses_tool_search_anthropic branch October 15, 2026 03:42
devin-ai-integration Bot added a commit that referenced this pull request Oct 15, 2026
…45882 landed

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
devin-ai-integration Bot added a commit that referenced this pull request Oct 15, 2026
…landed

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
mateo-berri added a commit that referenced this pull request Oct 15, 2026
…er a system message after the search turn

The malformed kept result cells now expect the unanswered search call to be dropped, as main does since #45882.
The stream cut cell checks streamed tool call names, since the kept search result names get_weather as a tool
reference. The streamed response cache hit cell runs again because #46104 fixed it. The modify_params cap cell
expects the four client marks, since the placeholder answer sends the search call as a plain tool_use with its
mark, and a new cell covers a system message after the trailing search turn in both stream modes
mateo-berri added a commit that referenced this pull request Oct 15, 2026
…y modify_params sends it (#46591)

* fix(anthropic): count a replayed server tool call's cache mark the way modify_params sends it

With modify_params on, a trailing tool search turn whose call has a kept result
got a placeholder answer from the factory and went out as a marked tool_use,
but the cache control hook counted marks before that placeholder existed and
skipped the mark, so a request at the cap reached Anthropic with 5 marks and
failed with a 400. The hook now finds client answers on the sanitized messages,
the same list the factory reads.

Also make the replay checks cheaper (prefix check before validation, early
return without provider_specific_fields, and look up client answers only when
a tool call carries cache_control), drop the two audit cells that cover old
gaps outside the tool search fix, and derive the pass-through test timeout
from the graceful stop budget.

* fix(anthropic): keep the duplicate tool result warning out of the cache control hook

The hook finds client answers with only the step of the modify_params sanitize
pass that pairs tool calls with their results, so a request with a duplicate
tool result logs the warning once again instead of once per mark count.

Also restore the Snowflake non-stream and cached-stream tool search cells as
known bugs with pytest.skip instead of deleting them, and put the Anthropic
pass-through test timeout back to 240 seconds.

* fix(anthropic): count cache marks next to a message the pairing step cannot read

With modify_params on and a marked tool call, the cache control hook paired tool
calls with their results before counting. A message without a get method (a
stray string or null in extra_body.messages, or an openai SDK
ChatCompletionMessage) made that pairing raise AttributeError before any
provider call, where main counted the marks and let the request through.

The hook now pairs only when every message can be read the way the pairing
step reads it, and otherwise counts on the messages as sent, like main did.

* fix(anthropic): count cache marks after placing a later system message the way the request builder does

* test(anthropic): cover a leading system prompt and a system message before the answer in the cache mark census

* test(anthropic): align the tool search replay cells with main and cover a system message after the search turn

The malformed kept result cells now expect the unanswered search call to be dropped, as main does since #45882.
The stream cut cell checks streamed tool call names, since the kept search result names get_weather as a tool
reference. The streamed response cache hit cell runs again because #46104 fixed it. The modify_params cap cell
expects the four client marks, since the placeholder answer sends the search call as a plain tool_use with its
mark, and a new cell covers a system message after the trailing search turn in both stream modes

* fix(anthropic): count marks on the raw messages when they cannot be placed, and find client answers once per request

* test(anthropic): cover marked tool calls next to a malformed tool id and a later system message

* perf(anthropic): look up client tool answers only when a marked tool call is a server tool call

Answered ids only decide whether a marked srvtoolu_ call is rebuilt as server_tool_use, so a request whose marked
tool calls are all client calls no longer places system messages or runs the modify_params pairing step to count
marks

* test(anthropic): reach the client answer lookup with a marked search call in the malformed tool id cell

* perf(anthropic): place mid-conversation system messages in linear time for models that keep them

* fix(anthropic): count cache marks with the model's own system message placement and pair tool results in linear time

* test(anthropic): cover modify_params dropping a tool answer that answers no call of the latest assistant turn

* fix(anthropic): count marks with in-place system placement when the model lookup cannot confirm the flag

* test(anthropic): cover a bare model with custom_llm_provider filling the cache mark budget through litellm.completion and Router

* fix(anthropic): give unmapped models the request builder's converting placement and survive any model lookup failure

* test(anthropic): cover an unmapped model name counting cache marks with the request builder's converting placement

* fix(anthropic): count server tool call cache marks the request builder's way only on routes that build Anthropic Messages requests

Databricks, OpenRouter and Bedrock Converse send every marked tool call as is, so the hook keeps the census main uses there. The seeding step carries custom_llm_provider on the injection points when a server tool call is marked, so a bare model name still resolves its route.

* test(anthropic): cover two answered marked server tool calls before a system message on Databricks, OpenRouter and Bedrock Converse

* fix(anthropic): keep main's cache mark count on GitHub Copilot and ChatGPT routes without resolving them, so a sync call with no stored login never starts the device flow

* test(anthropic): cover a marked server tool call reaching the GitHub Copilot and ChatGPT login hosts like an unmarked one
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk:high Sensitive, broad, or high-risk change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant