Skip to content

fix(llm_http_handler): forward kwargs['model_info'] to litellm_params for /v1/messages - #29467

Merged
Sameerlite merged 6 commits into
BerriAI:litellm_oss_stagingfrom
silencedoctor:fix/anthropic-messages-router-cooldown-model-info
Jun 2, 2026
Merged

fix(llm_http_handler): forward kwargs['model_info'] to litellm_params for /v1/messages#29467
Sameerlite merged 6 commits into
BerriAI:litellm_oss_stagingfrom
silencedoctor:fix/anthropic-messages-router-cooldown-model-info

Conversation

@silencedoctor

Copy link
Copy Markdown
Contributor

Relevant issues

No existing issue — surfaced while auditing Router cooldown behavior for /v1/messages.

Changes

Router._update_kwargs_with_deployment stamps the selected deployment's model_info on kwargs[\"model_info\"] before dispatching the request (see litellm/router.py). Downstream cooldown / success callbacks read the deployment id back via kwargs[\"litellm_params\"][\"model_info\"][\"id\"]:

  • litellm/router.py:7301deployment_callback_on_failure (cooldown trigger)
  • litellm/router.py:7141 / :7262 / :7364 — success and failure deployment tracking
  • litellm/proxy/common_request_processing.py:2212 / :2227 — proxy callbacks

async_anthropic_messages_handler in llm_http_handler.py constructs its own litellm_params dict when calling logging_obj.update_from_kwargs, and never forwards model_info. As a result, /v1/messages requests dispatched through the Router land in the callbacks with an empty model_info on litellm_params — the deployment id is missing, and cooldown / success-tracking are silently skipped for this call type. Other call types are unaffected because they go through get_litellm_params (litellm/litellm_core_utils/get_litellm_params.py:120), which already plumbs model_info onto the top level of litellm_params.

This PR adds \"model_info\": kwargs.get(\"model_info\") to the litellm_params dict, mirroring how the existing handler already forwards litellm_metadata (regression test test_async_anthropic_messages_handler_passes_litellm_metadata from #23185 covers the sibling case).

Why fix it in the handler instead of update_from_kwargs?

update_from_kwargs (added in #23659 as the central kwarg-extraction helper) auto-extracts metadata and litellm_metadata but not model_info. Two reasons not to extend it here:

  1. Existing convention: the standard completion path places model_info at the top level of litellm_params via get_litellm_params, not via metadata helpers. The /v1/messages handler is the outlier because it builds its own litellm_params dict — the fix should restore parity, not change the central contract.
  2. Blast radius: update_from_kwargs is called from multiple call types (responses, google_genai, a2a, anthropic_messages). Adding model_info auto-extraction there would silently change behavior for all of them. A handler-local fix isolates the change to the path that actually has the bug.

If maintainers later prefer to consolidate, this is a clean follow-up.

Testing

  • Added `test_async_anthropic_messages_handler_forwards_router_model_info` next to the existing `*_passes_litellm_metadata` test, using the same Mock harness and `update_from_kwargs` introspection pattern
  • Verified the new test fails without this fix (drop the one-line addition, re-run — the assertion fails with `None == {'id': ..., ...}`, proving the test isn't a no-op)
  • Ran `uv run pytest tests/test_litellm/llms/custom_httpx/test_llm_http_handler.py` — 14 passed

Type

🐛 Bug Fix

shin-berri and others added 6 commits May 13, 2026 22:37
chore(ci): promote internal staging to main
chore(ci): promote internal staging to main
chore(ci): promote internal staging to main
… for /v1/messages

Router._update_kwargs_with_deployment stamps the selected deployment's
model_info on kwargs['model_info'] before dispatching the request.
Downstream cooldown / success callbacks (deployment_callback_on_failure,
deployment_callback_on_success) look up the deployment id via
kwargs['litellm_params']['model_info']['id'].

async_anthropic_messages_handler constructs its own litellm_params dict
when calling logging_obj.update_from_kwargs and never forwarded
model_info. As a result, /v1/messages requests dispatched through the
Router had an empty model_info on litellm_params, the deployment id was
not discoverable, and cooldown / success tracking were silently skipped
for this call type.

Forward kwargs['model_info'] into the litellm_params dict so the
existing Router callbacks can identify the deployment.
@greptile-apps

greptile-apps Bot commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a silent bug where /v1/messages requests dispatched through the Router were missing the deployment's model_info in litellm_params, causing cooldown and success-tracking callbacks to silently skip those requests. The one-line fix adds "model_info": kwargs.get("model_info") to the litellm_params dict built inside async_anthropic_messages_handler, restoring parity with the standard completion path.

  • Handler fix (llm_http_handler.py): Adds model_info forwarding to the litellm_params dict in logging_obj.update_from_kwargs; no collision risk since anthropic_messages_optional_request_params is typed-filtered and never contains model_info.
  • New regression test: test_async_anthropic_messages_handler_forwards_router_model_info uses an all-mock harness (consistent with the sibling *_passes_litellm_metadata test) and asserts the deployment id is present in litellm_params — confirmed to fail without the fix.

Confidence Score: 5/5

Safe to merge — the change is a single-line addition to an isolated code path with a targeted regression test that confirms the fix.

The fix touches exactly one line in the handler and one new test. No existing tests are modified, no existing behavior is altered for non-Router callers (they pass kwargs without model_info, so the value is just None as before), and the spread of **anthropic_messages_optional_request_params cannot clobber the new key because model_info is not in AnthropicMessagesRequestOptionalParams.

No files require special attention.

Important Files Changed

Filename Overview
litellm/llms/custom_httpx/llm_http_handler.py One-line addition forwarding kwargs.get("model_info") into the litellm_params dict passed to logging_obj.update_from_kwargs; correctly mirrors how get_litellm_params handles this field on standard completion paths.
tests/test_litellm/llms/custom_httpx/test_llm_http_handler.py New regression test test_async_anthropic_messages_handler_forwards_router_model_info is all-mock (no network calls), asserts the newly added model_info key lands in litellm_params, and does not weaken any existing assertion.

Reviews (1): Last reviewed commit: "fix(llm_http_handler): forward kwargs['m..." | Re-trigger Greptile

@codspeed-hq

codspeed-hq Bot commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 16 untouched benchmarks


Comparing silencedoctor:fix/anthropic-messages-router-cooldown-model-info (c59024e) with main (5be0797)

Open in CodSpeed

@codecov

codecov Bot commented Jun 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@Sameerlite Sameerlite 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, thanks!

@Sameerlite
Sameerlite changed the base branch from main to litellm_oss_staging June 2, 2026 11:29
@Sameerlite
Sameerlite merged commit b5a6cd7 into BerriAI:litellm_oss_staging Jun 2, 2026
54 of 55 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants