From caa97eea224cb31199f9c2a64c379e3bb64a9da9 Mon Sep 17 00:00:00 2001 From: mateo-berri <277851410+mateo-berri@users.noreply.github.com> Date: Wed, 26 Aug 2026 14:00:39 -0700 Subject: [PATCH] fix(cost-map): correct prompt_cache_min_tokens for Claude Fable 5 and backfill Anthropic re-export entries --- ...odel_prices_and_context_window_backup.json | 95 ++++++++++++------- model_prices_and_context_window.json | 95 ++++++++++++------- tests/test_litellm/test_utils.py | 88 +++++++++++++++-- 3 files changed, 204 insertions(+), 74 deletions(-) diff --git a/litellm/model_prices_and_context_window_backup.json b/litellm/model_prices_and_context_window_backup.json index d9a13ef1b98..e7ce9d57452 100644 --- a/litellm/model_prices_and_context_window_backup.json +++ b/litellm/model_prices_and_context_window_backup.json @@ -1428,7 +1428,7 @@ "supports_output_config": true, "bedrock_output_config_effort_ceiling": "xhigh", "supports_parallel_tool_use_config": true, - "prompt_cache_min_tokens": 1024 + "prompt_cache_min_tokens": 512 }, "global.anthropic.claude-fable-5": { "cache_creation_input_token_cost": 1.25e-05, @@ -1465,7 +1465,7 @@ "supports_output_config": true, "bedrock_output_config_effort_ceiling": "xhigh", "supports_parallel_tool_use_config": true, - "prompt_cache_min_tokens": 1024 + "prompt_cache_min_tokens": 512 }, "us.anthropic.claude-fable-5": { "cache_creation_input_token_cost": 1.375e-05, @@ -1502,7 +1502,7 @@ "supports_output_config": true, "bedrock_output_config_effort_ceiling": "xhigh", "supports_parallel_tool_use_config": true, - "prompt_cache_min_tokens": 1024 + "prompt_cache_min_tokens": 512 }, "eu.anthropic.claude-fable-5": { "cache_creation_input_token_cost": 1.375e-05, @@ -1539,7 +1539,7 @@ "supports_output_config": true, "bedrock_output_config_effort_ceiling": "xhigh", "supports_parallel_tool_use_config": true, - "prompt_cache_min_tokens": 1024 + "prompt_cache_min_tokens": 512 }, "anthropic.claude-opus-5": { "bedrock_converse_supports_strict_tools": false, @@ -2933,7 +2933,8 @@ "supports_reasoning": true, "supports_response_schema": true, "supports_tool_choice": true, - "supports_vision": true + "supports_vision": true, + "prompt_cache_min_tokens": 4096 }, "azure_ai/claude-opus-4-5": { "deprecation_date": "2026-10-19", @@ -2956,7 +2957,8 @@ "supports_response_schema": true, "supports_tool_choice": true, "supports_vision": true, - "supports_output_config": true + "supports_output_config": true, + "prompt_cache_min_tokens": 4096 }, "azure_ai/claude-opus-4-6": { "deprecation_date": "2027-02-02", @@ -2987,7 +2989,8 @@ "supports_tool_choice": true, "supports_vision": true, "supports_output_config": true, - "supports_max_reasoning_effort": true + "supports_max_reasoning_effort": true, + "prompt_cache_min_tokens": 4096 }, "azure_ai/claude-opus-4-7": { "deprecation_date": "2027-04-06", @@ -3018,7 +3021,8 @@ "supports_tool_choice": true, "supports_vision": true, "supports_xhigh_reasoning_effort": true, - "supports_max_reasoning_effort": true + "supports_max_reasoning_effort": true, + "prompt_cache_min_tokens": 2048 }, "azure_ai/claude-fable-5": { "supports_mid_conversation_system": true, @@ -3050,7 +3054,8 @@ "supports_tool_choice": true, "supports_vision": true, "supports_xhigh_reasoning_effort": true, - "supports_max_reasoning_effort": true + "supports_max_reasoning_effort": true, + "prompt_cache_min_tokens": 512 }, "azure_ai/claude-opus-5": { "supports_mid_conversation_system": true, @@ -3113,7 +3118,8 @@ "supports_tool_choice": true, "supports_vision": true, "supports_xhigh_reasoning_effort": true, - "supports_max_reasoning_effort": true + "supports_max_reasoning_effort": true, + "prompt_cache_min_tokens": 1024 }, "azure_ai/claude-opus-4-1": { "deprecation_date": "2026-08-05", @@ -3135,7 +3141,8 @@ "supports_reasoning": true, "supports_response_schema": true, "supports_tool_choice": true, - "supports_vision": true + "supports_vision": true, + "prompt_cache_min_tokens": 1024 }, "azure_ai/claude-sonnet-4-5": { "deprecation_date": "2026-10-19", @@ -3157,7 +3164,8 @@ "supports_reasoning": true, "supports_response_schema": true, "supports_tool_choice": true, - "supports_vision": true + "supports_vision": true, + "prompt_cache_min_tokens": 1024 }, "azure_ai/claude-sonnet-5": { "supports_mid_conversation_system": true, @@ -3188,7 +3196,8 @@ "supports_tool_choice": true, "supports_vision": true, "supports_xhigh_reasoning_effort": true, - "supports_max_reasoning_effort": true + "supports_max_reasoning_effort": true, + "prompt_cache_min_tokens": 1024 }, "azure_ai/claude-sonnet-4-6": { "deprecation_date": "2027-02-10", @@ -3214,7 +3223,8 @@ "supports_max_reasoning_effort": true, "supports_tool_choice": true, "supports_vision": true, - "supports_output_config": true + "supports_output_config": true, + "prompt_cache_min_tokens": 1024 }, "azure/computer-use-preview": { "input_cost_per_token": 3e-06, @@ -33881,7 +33891,8 @@ "supports_prompt_caching": true, "supports_reasoning": true, "supports_tool_choice": true, - "supports_vision": true + "supports_vision": true, + "prompt_cache_min_tokens": 1024 }, "openrouter/anthropic/claude-sonnet-4": { "input_cost_per_image": 0.0048, @@ -33904,7 +33915,8 @@ "supports_prompt_caching": true, "supports_reasoning": true, "supports_tool_choice": true, - "supports_vision": true + "supports_vision": true, + "prompt_cache_min_tokens": 1024 }, "openrouter/anthropic/claude-sonnet-4.6": { "supports_adaptive_thinking": true, @@ -33930,7 +33942,8 @@ "supports_reasoning": true, "supports_max_reasoning_effort": true, "supports_tool_choice": true, - "supports_vision": true + "supports_vision": true, + "prompt_cache_min_tokens": 1024 }, "openrouter/anthropic/claude-opus-4.5": { "cache_creation_input_token_cost": 6.25e-06, @@ -33949,7 +33962,8 @@ "supports_reasoning": true, "supports_tool_choice": true, "supports_vision": true, - "supports_output_config": true + "supports_output_config": true, + "prompt_cache_min_tokens": 4096 }, "openrouter/anthropic/claude-opus-4.6": { "supports_adaptive_thinking": true, @@ -33970,7 +33984,8 @@ "supports_reasoning": true, "supports_max_reasoning_effort": true, "supports_tool_choice": true, - "supports_vision": true + "supports_vision": true, + "prompt_cache_min_tokens": 4096 }, "openrouter/anthropic/claude-sonnet-4.5": { "input_cost_per_image": 0.0048, @@ -33993,7 +34008,8 @@ "supports_prompt_caching": true, "supports_reasoning": true, "supports_tool_choice": true, - "supports_vision": true + "supports_vision": true, + "prompt_cache_min_tokens": 1024 }, "openrouter/anthropic/claude-haiku-4.5": { "cache_creation_input_token_cost": 1.25e-06, @@ -34011,7 +34027,8 @@ "supports_prompt_caching": true, "supports_reasoning": true, "supports_tool_choice": true, - "supports_vision": true + "supports_vision": true, + "prompt_cache_min_tokens": 4096 }, "openrouter/anthropic/claude-opus-4.7": { "supports_adaptive_thinking": true, @@ -34034,7 +34051,8 @@ "supports_max_reasoning_effort": true, "supports_tool_choice": true, "supports_vision": true, - "supports_xhigh_reasoning_effort": true + "supports_xhigh_reasoning_effort": true, + "prompt_cache_min_tokens": 2048 }, "openrouter/anthropic/claude-opus-5": { "prompt_cache_min_tokens": 512, @@ -39687,7 +39705,8 @@ "supports_reasoning": true, "supports_response_schema": true, "supports_tool_choice": true, - "supports_vision": true + "supports_vision": true, + "prompt_cache_min_tokens": 4096 }, "vercel_ai_gateway/anthropic/claude-opus-4": { "cache_creation_input_token_cost": 1.875e-05, @@ -39725,7 +39744,8 @@ "supports_reasoning": true, "supports_response_schema": true, "supports_tool_choice": true, - "supports_vision": true + "supports_vision": true, + "prompt_cache_min_tokens": 1024 }, "vercel_ai_gateway/anthropic/claude-opus-4.5": { "cache_creation_input_token_cost": 6.25e-06, @@ -39745,7 +39765,8 @@ "supports_response_schema": true, "supports_tool_choice": true, "supports_vision": true, - "supports_output_config": true + "supports_output_config": true, + "prompt_cache_min_tokens": 4096 }, "vercel_ai_gateway/anthropic/claude-opus-4.6": { "supports_adaptive_thinking": true, @@ -39767,7 +39788,8 @@ "supports_response_schema": true, "supports_tool_choice": true, "supports_vision": true, - "supports_output_config": true + "supports_output_config": true, + "prompt_cache_min_tokens": 4096 }, "vercel_ai_gateway/anthropic/claude-sonnet-4": { "cache_creation_input_token_cost": 3.75e-06, @@ -39786,7 +39808,8 @@ "supports_reasoning": true, "supports_response_schema": true, "supports_tool_choice": true, - "supports_vision": true + "supports_vision": true, + "prompt_cache_min_tokens": 1024 }, "vercel_ai_gateway/anthropic/claude-sonnet-4.5": { "cache_creation_input_token_cost": 3.75e-06, @@ -39804,7 +39827,8 @@ "supports_prompt_caching": true, "supports_reasoning": true, "supports_tool_choice": true, - "supports_vision": true + "supports_vision": true, + "prompt_cache_min_tokens": 1024 }, "vercel_ai_gateway/cohere/command-a": { "input_cost_per_token": 2.5e-06, @@ -41169,7 +41193,8 @@ "supports_tool_choice": true, "supports_vision": true, "supports_xhigh_reasoning_effort": true, - "supports_max_reasoning_effort": true + "supports_max_reasoning_effort": true, + "prompt_cache_min_tokens": 512 }, "vertex_ai/claude-fable-5@default": { "deprecation_date": "2027-06-08", @@ -41203,7 +41228,8 @@ "supports_tool_choice": true, "supports_vision": true, "supports_xhigh_reasoning_effort": true, - "supports_max_reasoning_effort": true + "supports_max_reasoning_effort": true, + "prompt_cache_min_tokens": 512 }, "vertex_ai/claude-opus-5": { "deprecation_date": "2027-01-24", @@ -50107,7 +50133,8 @@ "supports_vision": true, "supports_prompt_caching": true, "supports_system_messages": true, - "supports_response_schema": true + "supports_response_schema": true, + "prompt_cache_min_tokens": 1024 }, "snowflake/claude-sonnet-4-6": { "supports_adaptive_thinking": true, @@ -50124,7 +50151,8 @@ "supports_vision": true, "supports_prompt_caching": true, "supports_system_messages": true, - "supports_response_schema": true + "supports_response_schema": true, + "prompt_cache_min_tokens": 1024 }, "snowflake/claude-4-sonnet": { "max_tokens": 16384, @@ -50170,7 +50198,8 @@ "supports_vision": true, "supports_prompt_caching": true, "supports_system_messages": true, - "supports_response_schema": true + "supports_response_schema": true, + "prompt_cache_min_tokens": 4096 }, "snowflake/claude-3-7-sonnet": { "max_tokens": 16384, diff --git a/model_prices_and_context_window.json b/model_prices_and_context_window.json index d9a13ef1b98..e7ce9d57452 100644 --- a/model_prices_and_context_window.json +++ b/model_prices_and_context_window.json @@ -1428,7 +1428,7 @@ "supports_output_config": true, "bedrock_output_config_effort_ceiling": "xhigh", "supports_parallel_tool_use_config": true, - "prompt_cache_min_tokens": 1024 + "prompt_cache_min_tokens": 512 }, "global.anthropic.claude-fable-5": { "cache_creation_input_token_cost": 1.25e-05, @@ -1465,7 +1465,7 @@ "supports_output_config": true, "bedrock_output_config_effort_ceiling": "xhigh", "supports_parallel_tool_use_config": true, - "prompt_cache_min_tokens": 1024 + "prompt_cache_min_tokens": 512 }, "us.anthropic.claude-fable-5": { "cache_creation_input_token_cost": 1.375e-05, @@ -1502,7 +1502,7 @@ "supports_output_config": true, "bedrock_output_config_effort_ceiling": "xhigh", "supports_parallel_tool_use_config": true, - "prompt_cache_min_tokens": 1024 + "prompt_cache_min_tokens": 512 }, "eu.anthropic.claude-fable-5": { "cache_creation_input_token_cost": 1.375e-05, @@ -1539,7 +1539,7 @@ "supports_output_config": true, "bedrock_output_config_effort_ceiling": "xhigh", "supports_parallel_tool_use_config": true, - "prompt_cache_min_tokens": 1024 + "prompt_cache_min_tokens": 512 }, "anthropic.claude-opus-5": { "bedrock_converse_supports_strict_tools": false, @@ -2933,7 +2933,8 @@ "supports_reasoning": true, "supports_response_schema": true, "supports_tool_choice": true, - "supports_vision": true + "supports_vision": true, + "prompt_cache_min_tokens": 4096 }, "azure_ai/claude-opus-4-5": { "deprecation_date": "2026-10-19", @@ -2956,7 +2957,8 @@ "supports_response_schema": true, "supports_tool_choice": true, "supports_vision": true, - "supports_output_config": true + "supports_output_config": true, + "prompt_cache_min_tokens": 4096 }, "azure_ai/claude-opus-4-6": { "deprecation_date": "2027-02-02", @@ -2987,7 +2989,8 @@ "supports_tool_choice": true, "supports_vision": true, "supports_output_config": true, - "supports_max_reasoning_effort": true + "supports_max_reasoning_effort": true, + "prompt_cache_min_tokens": 4096 }, "azure_ai/claude-opus-4-7": { "deprecation_date": "2027-04-06", @@ -3018,7 +3021,8 @@ "supports_tool_choice": true, "supports_vision": true, "supports_xhigh_reasoning_effort": true, - "supports_max_reasoning_effort": true + "supports_max_reasoning_effort": true, + "prompt_cache_min_tokens": 2048 }, "azure_ai/claude-fable-5": { "supports_mid_conversation_system": true, @@ -3050,7 +3054,8 @@ "supports_tool_choice": true, "supports_vision": true, "supports_xhigh_reasoning_effort": true, - "supports_max_reasoning_effort": true + "supports_max_reasoning_effort": true, + "prompt_cache_min_tokens": 512 }, "azure_ai/claude-opus-5": { "supports_mid_conversation_system": true, @@ -3113,7 +3118,8 @@ "supports_tool_choice": true, "supports_vision": true, "supports_xhigh_reasoning_effort": true, - "supports_max_reasoning_effort": true + "supports_max_reasoning_effort": true, + "prompt_cache_min_tokens": 1024 }, "azure_ai/claude-opus-4-1": { "deprecation_date": "2026-08-05", @@ -3135,7 +3141,8 @@ "supports_reasoning": true, "supports_response_schema": true, "supports_tool_choice": true, - "supports_vision": true + "supports_vision": true, + "prompt_cache_min_tokens": 1024 }, "azure_ai/claude-sonnet-4-5": { "deprecation_date": "2026-10-19", @@ -3157,7 +3164,8 @@ "supports_reasoning": true, "supports_response_schema": true, "supports_tool_choice": true, - "supports_vision": true + "supports_vision": true, + "prompt_cache_min_tokens": 1024 }, "azure_ai/claude-sonnet-5": { "supports_mid_conversation_system": true, @@ -3188,7 +3196,8 @@ "supports_tool_choice": true, "supports_vision": true, "supports_xhigh_reasoning_effort": true, - "supports_max_reasoning_effort": true + "supports_max_reasoning_effort": true, + "prompt_cache_min_tokens": 1024 }, "azure_ai/claude-sonnet-4-6": { "deprecation_date": "2027-02-10", @@ -3214,7 +3223,8 @@ "supports_max_reasoning_effort": true, "supports_tool_choice": true, "supports_vision": true, - "supports_output_config": true + "supports_output_config": true, + "prompt_cache_min_tokens": 1024 }, "azure/computer-use-preview": { "input_cost_per_token": 3e-06, @@ -33881,7 +33891,8 @@ "supports_prompt_caching": true, "supports_reasoning": true, "supports_tool_choice": true, - "supports_vision": true + "supports_vision": true, + "prompt_cache_min_tokens": 1024 }, "openrouter/anthropic/claude-sonnet-4": { "input_cost_per_image": 0.0048, @@ -33904,7 +33915,8 @@ "supports_prompt_caching": true, "supports_reasoning": true, "supports_tool_choice": true, - "supports_vision": true + "supports_vision": true, + "prompt_cache_min_tokens": 1024 }, "openrouter/anthropic/claude-sonnet-4.6": { "supports_adaptive_thinking": true, @@ -33930,7 +33942,8 @@ "supports_reasoning": true, "supports_max_reasoning_effort": true, "supports_tool_choice": true, - "supports_vision": true + "supports_vision": true, + "prompt_cache_min_tokens": 1024 }, "openrouter/anthropic/claude-opus-4.5": { "cache_creation_input_token_cost": 6.25e-06, @@ -33949,7 +33962,8 @@ "supports_reasoning": true, "supports_tool_choice": true, "supports_vision": true, - "supports_output_config": true + "supports_output_config": true, + "prompt_cache_min_tokens": 4096 }, "openrouter/anthropic/claude-opus-4.6": { "supports_adaptive_thinking": true, @@ -33970,7 +33984,8 @@ "supports_reasoning": true, "supports_max_reasoning_effort": true, "supports_tool_choice": true, - "supports_vision": true + "supports_vision": true, + "prompt_cache_min_tokens": 4096 }, "openrouter/anthropic/claude-sonnet-4.5": { "input_cost_per_image": 0.0048, @@ -33993,7 +34008,8 @@ "supports_prompt_caching": true, "supports_reasoning": true, "supports_tool_choice": true, - "supports_vision": true + "supports_vision": true, + "prompt_cache_min_tokens": 1024 }, "openrouter/anthropic/claude-haiku-4.5": { "cache_creation_input_token_cost": 1.25e-06, @@ -34011,7 +34027,8 @@ "supports_prompt_caching": true, "supports_reasoning": true, "supports_tool_choice": true, - "supports_vision": true + "supports_vision": true, + "prompt_cache_min_tokens": 4096 }, "openrouter/anthropic/claude-opus-4.7": { "supports_adaptive_thinking": true, @@ -34034,7 +34051,8 @@ "supports_max_reasoning_effort": true, "supports_tool_choice": true, "supports_vision": true, - "supports_xhigh_reasoning_effort": true + "supports_xhigh_reasoning_effort": true, + "prompt_cache_min_tokens": 2048 }, "openrouter/anthropic/claude-opus-5": { "prompt_cache_min_tokens": 512, @@ -39687,7 +39705,8 @@ "supports_reasoning": true, "supports_response_schema": true, "supports_tool_choice": true, - "supports_vision": true + "supports_vision": true, + "prompt_cache_min_tokens": 4096 }, "vercel_ai_gateway/anthropic/claude-opus-4": { "cache_creation_input_token_cost": 1.875e-05, @@ -39725,7 +39744,8 @@ "supports_reasoning": true, "supports_response_schema": true, "supports_tool_choice": true, - "supports_vision": true + "supports_vision": true, + "prompt_cache_min_tokens": 1024 }, "vercel_ai_gateway/anthropic/claude-opus-4.5": { "cache_creation_input_token_cost": 6.25e-06, @@ -39745,7 +39765,8 @@ "supports_response_schema": true, "supports_tool_choice": true, "supports_vision": true, - "supports_output_config": true + "supports_output_config": true, + "prompt_cache_min_tokens": 4096 }, "vercel_ai_gateway/anthropic/claude-opus-4.6": { "supports_adaptive_thinking": true, @@ -39767,7 +39788,8 @@ "supports_response_schema": true, "supports_tool_choice": true, "supports_vision": true, - "supports_output_config": true + "supports_output_config": true, + "prompt_cache_min_tokens": 4096 }, "vercel_ai_gateway/anthropic/claude-sonnet-4": { "cache_creation_input_token_cost": 3.75e-06, @@ -39786,7 +39808,8 @@ "supports_reasoning": true, "supports_response_schema": true, "supports_tool_choice": true, - "supports_vision": true + "supports_vision": true, + "prompt_cache_min_tokens": 1024 }, "vercel_ai_gateway/anthropic/claude-sonnet-4.5": { "cache_creation_input_token_cost": 3.75e-06, @@ -39804,7 +39827,8 @@ "supports_prompt_caching": true, "supports_reasoning": true, "supports_tool_choice": true, - "supports_vision": true + "supports_vision": true, + "prompt_cache_min_tokens": 1024 }, "vercel_ai_gateway/cohere/command-a": { "input_cost_per_token": 2.5e-06, @@ -41169,7 +41193,8 @@ "supports_tool_choice": true, "supports_vision": true, "supports_xhigh_reasoning_effort": true, - "supports_max_reasoning_effort": true + "supports_max_reasoning_effort": true, + "prompt_cache_min_tokens": 512 }, "vertex_ai/claude-fable-5@default": { "deprecation_date": "2027-06-08", @@ -41203,7 +41228,8 @@ "supports_tool_choice": true, "supports_vision": true, "supports_xhigh_reasoning_effort": true, - "supports_max_reasoning_effort": true + "supports_max_reasoning_effort": true, + "prompt_cache_min_tokens": 512 }, "vertex_ai/claude-opus-5": { "deprecation_date": "2027-01-24", @@ -50107,7 +50133,8 @@ "supports_vision": true, "supports_prompt_caching": true, "supports_system_messages": true, - "supports_response_schema": true + "supports_response_schema": true, + "prompt_cache_min_tokens": 1024 }, "snowflake/claude-sonnet-4-6": { "supports_adaptive_thinking": true, @@ -50124,7 +50151,8 @@ "supports_vision": true, "supports_prompt_caching": true, "supports_system_messages": true, - "supports_response_schema": true + "supports_response_schema": true, + "prompt_cache_min_tokens": 1024 }, "snowflake/claude-4-sonnet": { "max_tokens": 16384, @@ -50170,7 +50198,8 @@ "supports_vision": true, "supports_prompt_caching": true, "supports_system_messages": true, - "supports_response_schema": true + "supports_response_schema": true, + "prompt_cache_min_tokens": 4096 }, "snowflake/claude-3-7-sonnet": { "max_tokens": 16384, diff --git a/tests/test_litellm/test_utils.py b/tests/test_litellm/test_utils.py index b283d777524..dc859be617a 100644 --- a/tests/test_litellm/test_utils.py +++ b/tests/test_litellm/test_utils.py @@ -4452,14 +4452,86 @@ def test_get_prompt_cache_min_tokens_resolves_per_model( assert get_prompt_cache_min_tokens(model=model) == expected_min_tokens -def test_get_prompt_cache_min_tokens_differs_per_platform_for_same_model(local_model_cost_map: None) -> None: - """The same model can carry a different minimum per platform, so the threshold must come from - the platform's own cost-map entry rather than being derived from the model family name.""" - assert get_prompt_cache_min_tokens(model="claude-fable-5") == 512 - assert get_prompt_cache_min_tokens(model="anthropic.claude-fable-5") == 1024 - assert get_prompt_cache_min_tokens(model="claude-fable-5") != get_prompt_cache_min_tokens( - model="anthropic.claude-fable-5" - ) +def test_get_prompt_cache_min_tokens_uniform_for_fable_5_across_platforms(local_model_cost_map: None) -> None: + """Anthropic removed the Amazon Bedrock override for Claude Fable 5, so its 512-token minimum + now applies on every platform. The Bedrock entries carried the old 1024 and the re-export + entries carried nothing, so the router judged 512-1023-token prefixes uncacheable and skipped + prompt-cache-affinity routing for prompts the provider demonstrably caches (issue #35011).""" + wrong: Final = { + model: get_prompt_cache_min_tokens(model=model) + for model, info in litellm.model_cost.items() + if "fable-5" in model + and info.get("supports_prompt_caching") + and get_prompt_cache_min_tokens(model=model) != 512 + } + assert not wrong, f"every Claude Fable 5 entry must carry prompt_cache_min_tokens 512: {wrong}" + + +ANTHROPIC_REEXPORT_CACHE_MIN: Final = { + "azure_ai/claude-fable-5": 512, + "azure_ai/claude-haiku-4-5": 4096, + "azure_ai/claude-opus-4-1": 1024, + "azure_ai/claude-opus-4-5": 4096, + "azure_ai/claude-opus-4-6": 4096, + "azure_ai/claude-opus-4-7": 2048, + "azure_ai/claude-opus-4-8": 1024, + "azure_ai/claude-sonnet-4-5": 1024, + "azure_ai/claude-sonnet-4-6": 1024, + "azure_ai/claude-sonnet-5": 1024, + "openrouter/anthropic/claude-haiku-4.5": 4096, + "openrouter/anthropic/claude-opus-4.1": 1024, + "openrouter/anthropic/claude-opus-4.5": 4096, + "openrouter/anthropic/claude-opus-4.6": 4096, + "openrouter/anthropic/claude-opus-4.7": 2048, + "openrouter/anthropic/claude-sonnet-4": 1024, + "openrouter/anthropic/claude-sonnet-4.5": 1024, + "openrouter/anthropic/claude-sonnet-4.6": 1024, + "snowflake/claude-haiku-4-5": 4096, + "snowflake/claude-sonnet-4-5": 1024, + "snowflake/claude-sonnet-4-6": 1024, + "vercel_ai_gateway/anthropic/claude-haiku-4.5": 4096, + "vercel_ai_gateway/anthropic/claude-opus-4.1": 1024, + "vercel_ai_gateway/anthropic/claude-opus-4.5": 4096, + "vercel_ai_gateway/anthropic/claude-opus-4.6": 4096, + "vercel_ai_gateway/anthropic/claude-sonnet-4": 1024, + "vercel_ai_gateway/anthropic/claude-sonnet-4.5": 1024, + "vertex_ai/claude-fable-5": 512, + "vertex_ai/claude-fable-5@default": 512, +} + + +def test_anthropic_reexport_entries_carry_explicit_prompt_cache_min_tokens(local_model_cost_map: None) -> None: + """Regression for issue #35011: these re-export entries carried no prompt_cache_min_tokens, so + they silently inherited the 1024 default. That skipped cache-affinity routing for Fable 5's + 512-1023-token prefixes and reported 1024-4095-token prompts as cacheable on the 2048/4096 + models. The entry must be explicit so a default change can never re-break them, which is why + this asserts the cost-map value itself and not just the resolver's answer.""" + wrong: Final = { + model: (litellm.model_cost[model].get("prompt_cache_min_tokens"), get_prompt_cache_min_tokens(model=model)) + for model, expected in ANTHROPIC_REEXPORT_CACHE_MIN.items() + if litellm.model_cost[model].get("prompt_cache_min_tokens") != expected + or get_prompt_cache_min_tokens(model=model) != expected + } + assert not wrong, f"(cost-map value, resolved value) diverge from Anthropic's published minimums: {wrong}" + + +def test_anthropic_reexport_cache_minimums_present_in_root_cost_map() -> None: + """The root map ships to the CDN independently of the bundled backup, so both must carry the + minimum or proxies reading one of them regress to the 1024 default.""" + root_map_path: Final = os.path.join(os.path.dirname(__file__), "..", "..", "model_prices_and_context_window.json") + with open(root_map_path) as f: + root_map: Final = json.load(f) + wrong: Final = { + model: root_map[model].get("prompt_cache_min_tokens") + for model, expected in ANTHROPIC_REEXPORT_CACHE_MIN.items() + if root_map[model].get("prompt_cache_min_tokens") != expected + } + fable_5_wrong: Final = { + model: info.get("prompt_cache_min_tokens") + for model, info in root_map.items() + if "fable-5" in model and info.get("supports_prompt_caching") and info.get("prompt_cache_min_tokens") != 512 + } + assert not wrong and not fable_5_wrong, f"root cost map diverges: {wrong | fable_5_wrong}" GEMINI_4096_CACHE_MIN_MODELS: Final = tuple(