litellm/tests/test_litellm_rust/messages
drewv19 e23fa5ba6d
feat(anthropic-messages): per-deployment deferred_tools handling on the /v1/messages bridge (#54183)
* feat(anthropic-messages): per-deployment deferred_tools handling on the /v1/messages bridge

model_info.deferred_tools picks passthrough, native or drop for tools Claude Code sends with defer_loading. native routes through the Responses API with client tool search so a tool load keeps the prompt cache. drop stays the default and no longer leaks defer_loading into the tool schema

* feat(anthropic-messages): emulate deferred tools with a dispatcher on chat-only backends

* fix(anthropic-messages): import deferred tool emulation lazily and restore only deferred tools

* fix(anthropic-messages): tighten deferred_tools native routing and tool search replay

native now needs a provider with client tool search (azure, fireworks_ai, openai) and wins over the
global chat completions flag. ToolSearch results keep their text and is_error state, a forced
ToolSearch tool_choice answers 400 or drops, emulate forces a deferred tool through the dispatcher,
sync emulate streams work, and an unknown deferred_tools value is refused on every route

* fix(anthropic-messages): refuse deferred_tools values a route cannot apply and quote tool search text

A provider served through its own /v1/messages API now answers 400 for any
deferred_tools value but passthrough, and passthrough on OpenAI answers 400
since OpenAI rejects defer_loading without its own tool search. Both fall
back under drop_params. count_tokens routes a native deployment the way its
messages call goes. A ToolSearch result's text replays as a quoted string
labeled as tool output

* fix(anthropic-messages): drop native on Fireworks, refuse passthrough on Azure, and name loaded tools under passthrough

Fireworks' Responses tool search still bills deferred tools as prompt
input, so native now answers 400 there like any provider without client
tool search. passthrough answers 400 on Azure as it does on OpenAI,
since both reject defer_loading outside their own tool search.

Every deferred_tools fallback under drop_params now logs one warning
naming the setting, because Claude Code requests get drop_params on by
default and never see the 400.

Under passthrough a ToolSearch result's tool_reference blocks reach a
chat backend as text naming each loaded tool, instead of an empty tool
result. drop keeps main's handling.

* fix(anthropic-messages): keep emulate calls to the forced or loaded tool, close sync streams, and refuse passthrough on Mistral

Under emulate, a CallLoadedTool call now comes back to the client only when it names a deferred tool that a ToolSearch result in the request loaded, or the tool that tool_choice forced. A forced deferred tool also limits the dispatcher's name to that tool. Any other call stays a CallLoadedTool call, so the client never runs a tool it did not load or force

The dispatcher takes the first CallLoadedTool name the caller's tools do not use, and closing a restored sync stream closes the provider stream too, before or during iteration

passthrough on mistral answers 400 naming the setting, or falls back to drop under drop_params, since Mistral's chat API answers 422 on deferred tools

* fix(anthropic-messages): answer 400 for strict deferred tools under emulate

Under emulate a loaded tool's arguments reach the model as the dispatcher's free-form input, so the provider cannot enforce strict input for it. A deferred tool with strict set now answers 400 naming the setting, or goes without strict under drop_params with the fallback warning, the way an unsupported strict already drops elsewhere. Claude Code sends no strict, so its sessions are unaffected

* fix(anthropic): bill a dropped emulate stream on the Responses route

The emulate stream wrapper forwarded attributes through __getattr__, which the
proxy's runtime-checkable disconnect billing protocol does not see, so a client
that dropped a streamed /v1/messages request on an openai/ deployment set to
emulate logged no spend. The wrapper now passes on the inner stream's
partial_response_on_disconnect

* fix(anthropic): refuse deferred_tools passthrough where the provider request drops defer_loading

* fix(anthropic): treat Bedrock native chat as Converse for deferred_tools passthrough and fall back to drop there

Under drop_params, passthrough on Bedrock Converse, Bedrock native chat, Gemini and Vertex Gemini (vertex_ai_beta included) now sends the same request drop sends

* fix(anthropic): read base_model and api_base when routing deferred_tools passthrough on Vertex

A Vertex deployment that reaches Gemini through base_model or a numeric PSC endpoint with api_base now gets the same passthrough refusal and drop_params fallback as a gemini model name

* fix(anthropic): check the provider-local model for Vertex PSC and keep non-string tool names out of set lookups

* fix(anthropic): load each tool once per tool search result and mark loop locals final

* fix(anthropic): skip defer_loading in tool token counts and ignore a non-object tool_choice on deferred tool routes

* fix(anthropic): answer 400 when native deferred tools meet stop_sequences instead of silently dropping tool search

The Responses API has no stop_sequences, so a native request carrying them went to chat completions with deferred tools sent the drop way. It now answers 400 naming the way out, and under drop_params falls back with a warning

* fix(anthropic): refuse native stop_sequences only when the request carries ToolSearch

Without the ToolSearch tool, native sends deferred tools the drop way on the Responses API too, so a stop_sequences request has no tool search to lose and goes to chat completions as before

* fix(anthropic): keep deferred tools usable through cache injection, guardrails, native replays and emulate

The tool_config cache point now skips tools with defer_loading, since Anthropic refuses a deferred tool
that carries cache_control. When a guardrail removes the tool search tool, the tools it kept go up without
defer_loading, so they stay callable. A native replay sends a tool's schema only in the first
tool_search_output that loads it. Emulate restores a CallLoadedTool call to any tool the client declared
without deferring it. native with stop_sequences refuses only when the request has tool search and at
least one deferred tool

* fix(anthropic): keep strict tools out of emulate's dispatcher restore

A CallLoadedTool call carries free-form input, so restoring it to a strict tool would skip that tool's
schema. Such a call now goes back unchanged, like a call naming an unknown tool, and the model retries
with the tool itself. The tool_config cache point test now records the request at the wire instead of
replacing the handler

---------

Co-authored-by: mateo-berri <277851410+mateo-berri@users.noreply.github.com>
2026-11-25 17:14:28 +00:00
..
__init__.py
bedrock_claude_platform_python_wire.json feat(messages): serve bedrock claude_platform messages on rust only (#52681) 2026-11-19 14:34:02 -08:00
bedrock_invoke_python_wire.json test(rust): update rust-wheel messages tests to main's current behaviour (#54223) 2026-11-24 12:24:37 -08:00
bedrock_mantle_python_wire.json feat(messages): serve bedrock mantle messages on rust only (#52328) 2026-11-18 17:36:06 -08:00
conftest.py test(rust-bridge): select native routes per test without LITELLM_RUST (#46620) 2026-10-15 09:12:08 -07:00
data.py feat(messages): serve anthropic messages on rust only (#51119) 2026-11-12 00:07:20 +00:00
test_bedrock.py test(rust): update rust-wheel messages tests to main's current behaviour (#54223) 2026-11-24 12:24:37 -08:00
test_body_hooks.py feat(messages): serve azure ai foundry messages on rust only (#51721) 2026-11-14 13:40:38 -08:00
test_callbacks.py test(rust): update rust-wheel messages tests to main's current behaviour (#54223) 2026-11-24 12:24:37 -08:00
test_dispatch.py feat(anthropic-messages): per-deployment deferred_tools handling on the /v1/messages bridge (#54183) 2026-11-25 17:14:28 +00:00
test_requests.py fix(proxy): resolve admin oidc api_key references on batch cancel, fine-tuning listing, OCR, /v1/messages and cache prediction (#53678) 2026-11-23 10:11:10 -08:00
test_streaming.py perf(rust): stop re-serializing the Messages request body in Python logging callbacks (#51440) 2026-11-12 17:13:55 -08:00
test_workload_identity.py feat(messages): serve anthropic messages on rust only (#51119) 2026-11-12 00:07:20 +00:00