Repository navigation
Conversation
…okens A chat-completions request without max_tokens gets its default from get_config(), which looks the model up by its provider-stripped name. A proxy deployment such as `anthropic/<custom-model>` is registered under the prefixed name, so the lookup misses and the request goes upstream capped at DEFAULT_ANTHROPIC_CHAT_MAX_TOKENS (4096) even though model_info sets max_output_tokens. transform_request now uses litellm_params["model_info"]["max_output_tokens"] when the request has no max_tokens and no class-level default is set. An explicit request value and AnthropicConfig(max_tokens=...) still win; deployments without the field keep the existing lookup and 4096 fallback.
|
ujangm seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
Merging this PR will not alter performance
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
Main already uses the deployment's max_output_tokens as the default max_tokens since #49952, so closing this. Reopen if it still happens or something is missing |
Relevant issues
Fixes #46432. Related: #40363 / #40376, the same 4096 symptom for versioned Vertex Claude ids. I commented on #40376 about how the two fit together.
Problem
A chat-completions request without
max_tokensto a proxy deployment likeanthropic/<custom-model>withmodel_info.max_output_tokens: 131072goes upstream withmax_tokens: 4096.transform_requestgets the default fromget_config(model=model), andmodelis provider-stripped by then. The router registers the deployment under the prefixed name, so the lookup misses and falls back toDEFAULT_ANTHROPIC_CHAT_MAX_TOKENS. The deployment'smodel_infoalready reachestransform_requestinlitellm_params["model_info"]; nothing reads it.Change
In
AnthropicConfig.transform_request, when the request has nomax_tokensandlitellm.AnthropicConfig.max_tokensis unset, uselitellm_params["model_info"]["max_output_tokens"]if it is a positive int.Precedence after the change: request value > class-level default > deployment
max_output_tokens> existing catalog lookup > 4096.Deployments without the field behave exactly as before. It sits above the
## Load Configblock that #40376 edits, so the two PRs touch different lines.Tests
tests/unit/llms/anthropic/chat/test_anthropic_chat_transformation.py:test_transform_request_default_max_tokens_from_deployment, parametrized:model_info→ 4096;max_output_tokens: None→ 4096.test_router_sends_deployment_max_output_tokens_when_request_omits_max_tokens: goes throughlitellm.Routerwith the Anthropic endpoint mocked by respx, and asserts the outgoing bodies carry[131072, 512]for a call withoutmax_tokensand a call withmax_tokens=512.Mutation: with the
transform_requestchange reverted, the deployment case and the router test fail (assert 4096 == 131072,[4096, 512] == [131072, 512]). Restored, all pass.Local runs:
tests/unit/llms/anthropic,azure_ai,vertex_ai/vertex_ai_partner_models,bedrock/chatandrouter_utils: 5738 passed.type_check_gate,type_discipline_gateandtest_quality_gateagainstmain: OK.ruff checkandruff format: clean.Type
🐛 Bug Fix