From 3b8ad37296f484ccf45db4d343f14ff42c1f38c9 Mon Sep 17 00:00:00 2001 From: Kerry Lu Date: Mon, 26 Oct 2026 18:54:50 -0700 Subject: [PATCH] fix(anthropic): raise DEFAULT_ANTHROPIC_CHAT_MAX_TOKENS from 4096 to 128000 (#48502) Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- litellm/constants.py | 2 +- .../test_anthropic_chat_transformation.py | 28 ++++++------------- 2 files changed, 9 insertions(+), 21 deletions(-) diff --git a/litellm/constants.py b/litellm/constants.py index d1daf2ee2d1..2901b7d8948 100644 --- a/litellm/constants.py +++ b/litellm/constants.py @@ -627,7 +627,7 @@ BEDROCK_MIN_THINKING_BUDGET_TOKENS: Final = get_env_int("BEDROCK_MIN_THINKING_BU # Anthropic's Messages API rejects thinking.budget_tokens < 1024. ANTHROPIC_MIN_THINKING_BUDGET_TOKENS: Final = 1024 REPLICATE_POLLING_DELAY_SECONDS: Final = get_env_float("REPLICATE_POLLING_DELAY_SECONDS", 0.5) -DEFAULT_ANTHROPIC_CHAT_MAX_TOKENS: Final = get_env_int("DEFAULT_ANTHROPIC_CHAT_MAX_TOKENS", 4096) +DEFAULT_ANTHROPIC_CHAT_MAX_TOKENS: Final = get_env_int("DEFAULT_ANTHROPIC_CHAT_MAX_TOKENS", 128000) DEFAULT_OCI_CHAT_MAX_TOKENS: Final = 4096 TOGETHER_AI_4_B: Final = get_env_int("TOGETHER_AI_4_B", 4) TOGETHER_AI_8_B: Final = get_env_int("TOGETHER_AI_8_B", 8) diff --git a/tests/unit/llms/anthropic/chat/test_anthropic_chat_transformation.py b/tests/unit/llms/anthropic/chat/test_anthropic_chat_transformation.py index f67e3b59cf6..b3b04440d16 100644 --- a/tests/unit/llms/anthropic/chat/test_anthropic_chat_transformation.py +++ b/tests/unit/llms/anthropic/chat/test_anthropic_chat_transformation.py @@ -2549,18 +2549,6 @@ def test_translate_system_message_preserves_cache_control(): # ============ Dynamic max_tokens Tests ============ -def test_get_max_tokens_for_model_claude_3(): - """ - Test that get_max_tokens_for_model returns correct value for Claude 3 models. - Claude 3 models have max_output_tokens of 4096. - """ - config = AnthropicConfig() - - # Claude 3 Sonnet should return 4096 - max_tokens = config.get_max_tokens_for_model("claude-3-sonnet-20240229") - assert max_tokens == 4096 - - def test_get_max_tokens_for_model_claude_35(): """ Test that get_max_tokens_for_model returns correct value for Claude 3.5 models. @@ -2581,24 +2569,24 @@ def test_get_max_tokens_for_model_claude_35(): def test_get_max_tokens_for_model_unknown(): """ - Test that get_max_tokens_for_model returns 4096 fallback for unknown models. + Test that get_max_tokens_for_model returns 128000 fallback for unknown models. """ config = AnthropicConfig() - # Unknown model should return 4096 as fallback + # Unknown model should return 128000 as fallback max_tokens = config.get_max_tokens_for_model("unknown-model-xyz") - assert max_tokens == 4096 + assert max_tokens == 128000 def test_get_max_tokens_for_model_none(): """ - Test that get_max_tokens_for_model returns 4096 fallback when model is None. + Test that get_max_tokens_for_model returns 128000 fallback when model is None. """ config = AnthropicConfig() - # None model should return 4096 as fallback + # None model should return 128000 as fallback max_tokens = config.get_max_tokens_for_model(None) - assert max_tokens == 4096 + assert max_tokens == 128000 def test_get_config_with_model_uses_dynamic_max_tokens(): @@ -2639,10 +2627,10 @@ def test_get_config_with_model_uses_dynamic_max_tokens(): def test_get_config_without_model_uses_fallback(): """ - Test that get_config without model parameter uses 4096 fallback. + Test that get_config without model parameter uses 128000 fallback. """ config = AnthropicConfig.get_config() - assert config["max_tokens"] == 4096 + assert config["max_tokens"] == 128000 def test_get_config_does_not_leak_module_constants():