fix(llm_http_handler): forward kwargs['model_info'] to litellm_params for /v1/messages - #29467
Conversation
[Infra] Promote internal staging to main
[Infra] Promote internal staging to main
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 SummaryThis PR fixes a silent bug where
Confidence Score: 5/5Safe 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 No files require special attention.
|
| 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
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
b5a6cd7
into
BerriAI:litellm_oss_staging
Relevant issues
No existing issue — surfaced while auditing Router cooldown behavior for
/v1/messages.Changes
Router._update_kwargs_with_deploymentstamps the selected deployment'smodel_infoonkwargs[\"model_info\"]before dispatching the request (seelitellm/router.py). Downstream cooldown / success callbacks read the deployment id back viakwargs[\"litellm_params\"][\"model_info\"][\"id\"]:litellm/router.py:7301—deployment_callback_on_failure(cooldown trigger)litellm/router.py:7141/:7262/:7364— success and failure deployment trackinglitellm/proxy/common_request_processing.py:2212/:2227— proxy callbacksasync_anthropic_messages_handlerinllm_http_handler.pyconstructs its ownlitellm_paramsdict when callinglogging_obj.update_from_kwargs, and never forwardsmodel_info. As a result,/v1/messagesrequests dispatched through the Router land in the callbacks with an emptymodel_infoonlitellm_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 throughget_litellm_params(litellm/litellm_core_utils/get_litellm_params.py:120), which already plumbsmodel_infoonto the top level oflitellm_params.This PR adds
\"model_info\": kwargs.get(\"model_info\")to thelitellm_paramsdict, mirroring how the existing handler already forwardslitellm_metadata(regression testtest_async_anthropic_messages_handler_passes_litellm_metadatafrom #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-extractsmetadataandlitellm_metadatabut notmodel_info. Two reasons not to extend it here:model_infoat the top level oflitellm_paramsviaget_litellm_params, not via metadata helpers. The/v1/messageshandler is the outlier because it builds its ownlitellm_paramsdict — the fix should restore parity, not change the central contract.update_from_kwargsis called from multiple call types (responses, google_genai, a2a, anthropic_messages). Addingmodel_infoauto-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
Type
🐛 Bug Fix