The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
fix(cost): resolve dated openai/azure snapshots to their undated cost map entry
Devin AI67778cfe2625
diff --git a/litellm/utils.py b/litellm/utils.pyindex 734522c0c6a..33fdfcc36ba 100644--- a/litellm/utils.py+++ b/litellm/utils.py@@ -5286,6 +5286,13 @@ def _strip_stable_vertex_version(model_name) -> str:return re.sub(r"-\d+$", "", model_name)+_DATED_SNAPSHOT_SUFFIX: Final = re.compile(r"-\d{4}-\d{2}-\d{2}$")+++def _strip_dated_snapshot_suffix(model_name: str) -> str:+ return _DATED_SNAPSHOT_SUFFIX.sub("", model_name)++def _get_base_bedrock_model(model_name) -> str:"""Get the base model from the given model name.@@ -5333,7 +5340,7 @@ def _strip_model_name(model: str, custom_llm_provider: str | None) -> str:strip_finetune: Final = _strip_openai_finetune_model_name(model_name=model)return strip_finetuneelse:- return model+ return _strip_dated_snapshot_suffix(model_name=model)# Global case-insensitive lookup map for model_cost (built eagerly at module import)diff --git a/tests/test_litellm/test_cost_calculator.py b/tests/test_litellm/test_cost_calculator.pyindex 7b53d3a58df..c5bc8d80fed 100644--- a/tests/test_litellm/test_cost_calculator.py+++ b/tests/test_litellm/test_cost_calculator.py@@ -21,7 +21,9 @@ from litellm.types.llms.openai import OpenAIRealtimeStreamList, ResponseAPIUsagefrom litellm.types.rerank import RerankResponsefrom litellm.types.utils import (CallTypes,+ Choices,LiteLLMRealtimeStreamLoggingObject,+ Message,ModelInfo,ModelResponse,PromptTokensDetailsWrapper,@@ -110,6 +112,28 @@ def test_completion_cost_uses_response_model_for_dynamic_routing(_local_model_coassert cost > 0, "Cost should be calculated using response model"+def test_completion_cost_strips_dated_azure_snapshot_model(_local_model_cost_map: None) -> None:+ dated_response = ModelResponse(+ model="gpt-5.6-luna-2026-07-09",+ choices=[Choices(index=0, message=Message(role="assistant", content="hi"), finish_reason="stop")],+ usage=Usage(prompt_tokens=100, completion_tokens=50, total_tokens=150),+ )+ dated_response._hidden_params = {"custom_llm_provider": "azure"}++ undated_response = ModelResponse(+ model="gpt-5.6-luna",+ choices=[Choices(index=0, message=Message(role="assistant", content="hi"), finish_reason="stop")],+ usage=Usage(prompt_tokens=100, completion_tokens=50, total_tokens=150),+ )+ undated_response._hidden_params = {"custom_llm_provider": "azure"}++ dated_cost = litellm.completion_cost(completion_response=dated_response)+ undated_cost = litellm.completion_cost(completion_response=undated_response)++ assert dated_cost == undated_cost+ assert dated_cost > 0++def test_cost_calculator_with_response_cost_in_additional_headers():class MockResponse(BaseModel):_hidden_params = {"additional_headers": {"llm_provider-x-litellm-response-cost": 1000}}diff --git a/tests/test_litellm/test_utils.py b/tests/test_litellm/test_utils.pyindex 46149589371..2f9e27af797 100644--- a/tests/test_litellm/test_utils.py+++ b/tests/test_litellm/test_utils.py@@ -186,6 +186,25 @@ def test_get_model_info_strips_openai_finetune_ids_without_a_custom_suffix(localassert info["key"] == "ft:gpt-4o-2024-08-06"+ ("model", "custom_llm_provider", "expected_key"),+ [+ ("gpt-5.6-luna-2026-07-09", "openai", "gpt-5.6-luna"),+ ("gpt-5.6-luna-2026-07-09", "azure", "azure/gpt-5.6-luna"),+ ],+)+def test_get_model_info_falls_back_from_dated_snapshot_to_undated_entry(+ local_model_cost_map, model, custom_llm_provider, expected_key+):+ info = litellm.get_model_info(model=model, custom_llm_provider=custom_llm_provider)+ assert info["key"] == expected_key+++def test_get_model_info_prefers_exact_dated_key_over_stripped(local_model_cost_map):+ info = litellm.get_model_info(model="gpt-4o-2024-08-06", custom_llm_provider="openai")+ assert info["key"] == "gpt-4o-2024-08-06"++def test_check_provider_match_azure_ai_allows_openai_and_azure():"""Test that azure_ai provider can match openai and azure models.