Skip to content

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]

[Test Fix] fix gov pricing tests (#25022)

David Chenb7ccc5b691d9
diff --git a/litellm/cost_calculator.py b/litellm/cost_calculator.py
index 29d28b8c896..3b73b853eca 100644
--- a/litellm/cost_calculator.py
+++ b/litellm/cost_calculator.py
@@ -545,8 +545,8 @@ def cost_per_token( # noqa: PLR0915
)
if (
- model_info.get("input_cost_per_token", 0) > 0
- or model_info.get("output_cost_per_token", 0) > 0
+ (model_info.get("input_cost_per_token") or 0.0) > 0
+ or (model_info.get("output_cost_per_token") or 0.0) > 0
):
return generic_cost_per_token(
model=model,
diff --git a/litellm/litellm_core_utils/llm_request_utils.py b/litellm/litellm_core_utils/llm_request_utils.py
index a2292d6e00f..dc70069ac5a 100644
--- a/litellm/litellm_core_utils/llm_request_utils.py
+++ b/litellm/litellm_core_utils/llm_request_utils.py
@@ -56,9 +56,8 @@ def pick_cheapest_chat_models_from_llm_provider(custom_llm_provider: str, n=1):
continue
if model_info.get("mode") != "chat":
continue
- _cost = model_info.get("input_cost_per_token", 0) + model_info.get(
- "output_cost_per_token", 0
- )
+ _cost = (model_info.get("input_cost_per_token") or 0.0) + (model_info.get(
+ "output_cost_per_token") or 0.0)
model_costs.append((model, _cost))
# Sort by cost (ascending)
diff --git a/litellm/llms/azure_ai/cost_calculator.py b/litellm/llms/azure_ai/cost_calculator.py
index 3cca61b2186..067181b946a 100644
--- a/litellm/llms/azure_ai/cost_calculator.py
+++ b/litellm/llms/azure_ai/cost_calculator.py
@@ -54,7 +54,7 @@ def calculate_azure_model_router_flat_cost(model: str, prompt_tokens: int) -> fl
model_info = get_model_info(model="model_router", custom_llm_provider="azure_ai")
router_flat_cost_per_token = model_info.get("input_cost_per_token", 0)
- if router_flat_cost_per_token > 0:
+ if router_flat_cost_per_token and router_flat_cost_per_token > 0:
return prompt_tokens * router_flat_cost_per_token
return 0.0
diff --git a/litellm/llms/vertex_ai/cost_calculator.py b/litellm/llms/vertex_ai/cost_calculator.py
index e7ac453e949..4ca3d29e7d2 100644
--- a/litellm/llms/vertex_ai/cost_calculator.py
+++ b/litellm/llms/vertex_ai/cost_calculator.py
@@ -203,7 +203,7 @@ def _handle_128k_pricing(
):
prompt_cost = prompt_tokens * input_cost_per_token_above_128k_tokens
else:
- prompt_cost = prompt_tokens * model_info["input_cost_per_token"]
+ prompt_cost = prompt_tokens * (model_info["input_cost_per_token"] or 0.0)
## CALCULATE OUTPUT COST
output_cost_per_token_above_128k_tokens = model_info.get(
@@ -215,7 +215,7 @@ def _handle_128k_pricing(
):
completion_cost = completion_tokens * output_cost_per_token_above_128k_tokens
else:
- completion_cost = completion_tokens * model_info["output_cost_per_token"]
+ completion_cost = completion_tokens * (model_info["output_cost_per_token"] or 0.0)
return prompt_cost, completion_cost
diff --git a/litellm/model_prices_and_context_window_backup.json b/litellm/model_prices_and_context_window_backup.json
index d4f986edd9b..51b7b56a285 100644
--- a/litellm/model_prices_and_context_window_backup.json
+++ b/litellm/model_prices_and_context_window_backup.json
@@ -7643,13 +7643,13 @@
"cache_creation_input_token_cost": 3.75e-07
},
"bedrock/us-gov-east-1/claude-sonnet-4-5-20250929-v1:0": {
- "input_cost_per_token": 3.3e-06,
+ "input_cost_per_token": 3.6e-06,
"litellm_provider": "bedrock",
"max_input_tokens": 200000,
"max_output_tokens": 4096,
"max_tokens": 4096,
"mode": "chat",
- "output_cost_per_token": 1.65e-05,
+ "output_cost_per_token": 1.8e-05,
"supports_assistant_prefill": true,
"supports_computer_use": true,
"supports_function_calling": true,
@@ -7659,8 +7659,8 @@
"supports_response_schema": true,
"supports_tool_choice": true,
"supports_vision": true,
- "cache_read_input_token_cost": 3.3e-07,
- "cache_creation_input_token_cost": 4.125e-06
+ "cache_read_input_token_cost": 3.6e-07,
+ "cache_creation_input_token_cost": 4.5e-06
},
"bedrock/us-gov-east-1/meta.llama3-70b-instruct-v1:0": {
"input_cost_per_token": 2.65e-06,
@@ -7794,13 +7794,13 @@
"cache_creation_input_token_cost": 3.75e-07
},
"bedrock/us-gov-west-1/claude-sonnet-4-5-20250929-v1:0": {
- "input_cost_per_token": 3.3e-06,
+ "input_cost_per_token": 3.6e-06,
"litellm_provider": "bedrock",
"max_input_tokens": 200000,
"max_output_tokens": 4096,
"max_tokens": 4096,
"mode": "chat",
- "output_cost_per_token": 1.65e-05,
+ "output_cost_per_token": 1.8e-05,
"supports_assistant_prefill": true,
"supports_computer_use": true,
"supports_function_calling": true,
@@ -7810,8 +7810,8 @@
"supports_response_schema": true,
"supports_tool_choice": true,
"supports_vision": true,
- "cache_read_input_token_cost": 3.3e-07,
- "cache_creation_input_token_cost": 4.125e-06
+ "cache_read_input_token_cost": 3.6e-07,
+ "cache_creation_input_token_cost": 4.5e-06
},
"bedrock/us-gov-west-1/meta.llama3-70b-instruct-v1:0": {
"input_cost_per_token": 2.65e-06,
@@ -31164,7 +31164,9 @@
"mode": "chat",
"output_cost_per_token": 3.2e-06,
"source": "https://cloud.google.com/vertex-ai/generative-ai/pricing#glm-models",
- "supported_regions": ["global"],
+ "supported_regions": [
+ "global"
+ ],
"supports_function_calling": true,
"supports_prompt_caching": true,
"supports_reasoning": true,
@@ -37473,5 +37475,51 @@
]
}
]
+ },
+ "bedrock/us-gov-east-1/anthropic.claude-haiku-4-5-20251001-v1:0": {
+ "cache_creation_input_token_cost": 1.5e-06,
+ "cache_read_input_token_cost": 1.2e-07,
+ "input_cost_per_token": 1.2e-06,
+ "litellm_provider": "bedrock",
+ "max_input_tokens": 200000,
+ "max_output_tokens": 64000,
+ "max_tokens": 64000,
+ "mode": "chat",
+ "output_cost_per_token": 6e-06,
+ "source": "https://aws.amazon.com/about-aws/whats-new/2025/10/claude-4-5-haiku-anthropic-amazon-bedrock",
+ "supports_assistant_prefill": true,
+ "supports_computer_use": true,
+ "supports_function_calling": true,
+ "supports_prompt_caching": true,
+ "supports_reasoning": true,
+ "supports_response_schema": true,
+ "supports_tool_choice": true,
+ "supports_vision": true,
+ "tool_use_system_prompt_tokens": 346,
+ "supports_native_structured_output": true,
+ "supports_pdf_input": true
+ },
+ "bedrock/us-gov-west-1/anthropic.claude-haiku-4-5-20251001-v1:0": {
+ "cache_creation_input_token_cost": 1.5e-06,
+ "cache_read_input_token_cost": 1.2e-07,
+ "input_cost_per_token": 1.2e-06,
+ "litellm_provider": "bedrock",
+ "max_input_tokens": 200000,
+ "max_output_tokens": 64000,
+ "max_tokens": 64000,
+ "mode": "chat",
+ "output_cost_per_token": 6e-06,
+ "source": "https://aws.amazon.com/about-aws/whats-new/2025/10/claude-4-5-haiku-anthropic-amazon-bedrock",
+ "supports_assistant_prefill": true,
+ "supports_computer_use": true,
+ "supports_function_calling": true,
+ "supports_prompt_caching": true,
+ "supports_reasoning": true,
+ "supports_response_schema": true,
+ "supports_tool_choice": true,
+ "supports_vision": true,
+ "tool_use_system_prompt_tokens": 346,
+ "supports_native_structured_output": true,
+ "supports_pdf_input": true
}
}
diff --git a/litellm/router.py b/litellm/router.py
index 586d5961b94..1b8f7c91761 100644
--- a/litellm/router.py
+++ b/litellm/router.py
@@ -7856,16 +7856,16 @@ class Router:
model_group_info.max_output_tokens = model_info["max_output_tokens"]
if model_info.get("input_cost_per_token", None) is not None and (
model_group_info.input_cost_per_token is None
- or model_info["input_cost_per_token"]
- > model_group_info.input_cost_per_token
+ or (model_info["input_cost_per_token"] or 0.0)
+ > (model_group_info.input_cost_per_token or 0.0)
):
model_group_info.input_cost_per_token = model_info[
"input_cost_per_token"
]
if model_info.get("output_cost_per_token", None) is not None and (
model_group_info.output_cost_per_token is None
- or model_info["output_cost_per_token"]
- > model_group_info.output_cost_per_token
+ or (model_info["output_cost_per_token"] or 0.0)
+ > (model_group_info.output_cost_per_token or 0.0)
):
model_group_info.output_cost_per_token = model_info[
"output_cost_per_token"
diff --git a/model_prices_and_context_window.json b/model_prices_and_context_window.json
index d4f986edd9b..51b7b56a285 100644
--- a/model_prices_and_context_window.json
+++ b/model_prices_and_context_window.json
@@ -7643,13 +7643,13 @@
"cache_creation_input_token_cost": 3.75e-07
},
"bedrock/us-gov-east-1/claude-sonnet-4-5-20250929-v1:0": {
- "input_cost_per_token": 3.3e-06,
+ "input_cost_per_token": 3.6e-06,
"litellm_provider": "bedrock",
"max_input_tokens": 200000,
"max_output_tokens": 4096,
"max_tokens": 4096,
"mode": "chat",
- "output_cost_per_token": 1.65e-05,
+ "output_cost_per_token": 1.8e-05,
"supports_assistant_prefill": true,
"supports_computer_use": true,
"supports_function_calling": true,
@@ -7659,8 +7659,8 @@
"supports_response_schema": true,
"supports_tool_choice": true,
"supports_vision": true,
- "cache_read_input_token_cost": 3.3e-07,
- "cache_creation_input_token_cost": 4.125e-06
+ "cache_read_input_token_cost": 3.6e-07,
+ "cache_creation_input_token_cost": 4.5e-06
},
"bedrock/us-gov-east-1/meta.llama3-70b-instruct-v1:0": {
"input_cost_per_token": 2.65e-06,
@@ -7794,13 +7794,13 @@
"cache_creation_input_token_cost": 3.75e-07
},
"bedrock/us-gov-west-1/claude-sonnet-4-5-20250929-v1:0": {
- "input_cost_per_token": 3.3e-06,
+ "input_cost_per_token": 3.6e-06,
"litellm_provider": "bedrock",
"max_input_tokens": 200000,
"max_output_tokens": 4096,
"max_tokens": 4096,
"mode": "chat",
- "output_cost_per_token": 1.65e-05,
+ "output_cost_per_token": 1.8e-05,
"supports_assistant_prefill": true,
"supports_computer_use": true,
"supports_function_calling": true,
@@ -7810,8 +7810,8 @@
"supports_response_schema": true,
"supports_tool_choice": true,
"supports_vision": true,
- "cache_read_input_token_cost": 3.3e-07,
- "cache_creation_input_token_cost": 4.125e-06
+ "cache_read_input_token_cost": 3.6e-07,
+ "cache_creation_input_token_cost": 4.5e-06
},
"bedrock/us-gov-west-1/meta.llama3-70b-instruct-v1:0": {
"input_cost_per_token": 2.65e-06,
@@ -31164,7 +31164,9 @@
"mode": "chat",
"output_cost_per_token": 3.2e-06,
"source": "https://cloud.google.com/vertex-ai/generative-ai/pricing#glm-models",
- "supported_regions": ["global"],
+ "supported_regions": [
+ "global"
+ ],
"supports_function_calling": true,
"supports_prompt_caching": true,
"supports_reasoning": true,
@@ -37473,5 +37475,51 @@
]
}
]
+ },
+ "bedrock/us-gov-east-1/anthropic.claude-haiku-4-5-20251001-v1:0": {
+ "cache_creation_input_token_cost": 1.5e-06,
+ "cache_read_input_token_cost": 1.2e-07,
+ "input_cost_per_token": 1.2e-06,
+ "litellm_provider": "bedrock",
+ "max_input_tokens": 200000,
+ "max_output_tokens": 64000,
+ "max_tokens": 64000,
+ "mode": "chat",
+ "output_cost_per_token": 6e-06,
+ "source": "https://aws.amazon.com/about-aws/whats-new/2025/10/claude-4-5-haiku-anthropic-amazon-bedrock",
+ "supports_assistant_prefill": true,
+ "supports_computer_use": true,
+ "supports_function_calling": true,
+ "supports_prompt_caching": true,
+ "supports_reasoning": true,
+ "supports_response_schema": true,
+ "supports_tool_choice": true,
+ "supports_vision": true,
+ "tool_use_system_prompt_tokens": 346,
+ "supports_native_structured_output": true,
+ "supports_pdf_input": true
+ },
+ "bedrock/us-gov-west-1/anthropic.claude-haiku-4-5-20251001-v1:0": {
+ "cache_creation_input_token_cost": 1.5e-06,
+ "cache_read_input_token_cost": 1.2e-07,
+ "input_cost_per_token": 1.2e-06,
+ "litellm_provider": "bedrock",
+ "max_input_tokens": 200000,
+ "max_output_tokens": 64000,
+ "max_tokens": 64000,
+ "mode": "chat",
+ "output_cost_per_token": 6e-06,
+ "source": "https://aws.amazon.com/about-aws/whats-new/2025/10/claude-4-5-haiku-anthropic-amazon-bedrock",
+ "supports_assistant_prefill": true,
+ "supports_computer_use": true,
+ "supports_function_calling": true,
+ "supports_prompt_caching": true,
+ "supports_reasoning": true,
+ "supports_response_schema": true,
+ "supports_tool_choice": true,
+ "supports_vision": true,
+ "tool_use_system_prompt_tokens": 346,
+ "supports_native_structured_output": true,
+ "supports_pdf_input": true
}
}
diff --git a/tests/llm_translation/test_bedrock_govcloud.py b/tests/llm_translation/test_bedrock_govcloud.py
index 4dbfa45a7de..456eac84a3f 100644
--- a/tests/llm_translation/test_bedrock_govcloud.py
+++ b/tests/llm_translation/test_bedrock_govcloud.py
@@ -198,35 +198,38 @@ class TestBedrockGovCloudSupport:
from litellm.utils import Usage
# Mock completion response for base model
+ # Use us.* inference profile ID to match us.* pricing ($1.10/$5.50 per MTok)
base_model_response = ModelResponse(
id="test-base",
choices=[Choices(finish_reason="stop", index=0, message=Message(content="Hello", role="assistant"))],
created=1234567890,
- model="anthropic.claude-haiku-4-5-20251001-v1:0",
+ model="us.anthropic.claude-haiku-4-5-20251001-v1:0",
object="chat.completion",
system_fingerprint=None,
usage=Usage(prompt_tokens=10, completion_tokens=5, total_tokens=15),
)
base_model_response._hidden_params = {"custom_llm_provider": "bedrock", "region_name": "us-east-1"}
-
+
# Mock completion response for gov model
+ # GovCloud responses use base anthropic.* model ID; pricing is looked up
+ # via bedrock/us-gov-east-1/anthropic.* entries in model_cost
gov_model_response = ModelResponse(
id="test-gov",
choices=[Choices(finish_reason="stop", index=0, message=Message(content="Hello", role="assistant"))],
created=1234567890,
- model="anthropic.claude-haiku-4-5-20251001-v1:0", # Same base model name
+ model="anthropic.claude-haiku-4-5-20251001-v1:0",
object="chat.completion",
system_fingerprint=None,
usage=Usage(prompt_tokens=10, completion_tokens=5, total_tokens=15),
)
gov_model_response._hidden_params = {"custom_llm_provider": "bedrock", "region_name": "us-gov-east-1"}
-
+
# Mock completion response for gov-west model
gov_west_model_response = ModelResponse(
id="test-gov-west",
choices=[Choices(finish_reason="stop", index=0, message=Message(content="Hello", role="assistant"))],
created=1234567890,
- model="anthropic.claude-haiku-4-5-20251001-v1:0", # Same base model name
+ model="anthropic.claude-haiku-4-5-20251001-v1:0",
object="chat.completion",
system_fingerprint=None,
usage=Usage(prompt_tokens=10, completion_tokens=5, total_tokens=15),
@@ -237,25 +240,27 @@ class TestBedrockGovCloudSupport:
messages = [{"role": "user", "content": "Hello, how are you?"}]
# Calculate costs using the standard Bedrock format with region parameter
+ # Base model uses us.* inference profile — no region_name needed since
+ # the response model already contains the us.* prefix for pricing lookup.
base_cost = completion_cost(
model="bedrock/us.anthropic.claude-haiku-4-5-20251001-v1:0",
completion_response=base_model_response,
messages=messages,
- region_name="us-east-1", # Standard region
)
-
+
+ # GovCloud models use region_name to look up bedrock/us-gov-*/anthropic.* pricing
gov_east_cost = completion_cost(
- model="bedrock/us.anthropic.claude-haiku-4-5-20251001-v1:0",
+ model="bedrock/anthropic.claude-haiku-4-5-20251001-v1:0",
completion_response=gov_model_response,
messages=messages,
- region_name="us-gov-east-1", # Gov region
+ region_name="us-gov-east-1",
)
-
+
gov_west_cost = completion_cost(
- model="bedrock/us.anthropic.claude-haiku-4-5-20251001-v1:0",
+ model="bedrock/anthropic.claude-haiku-4-5-20251001-v1:0",
completion_response=gov_west_model_response,
messages=messages,
- region_name="us-gov-west-1", # Gov region
+ region_name="us-gov-west-1",
)
# Expected costs based on pricing:
@@ -278,20 +283,19 @@ class TestBedrockGovCloudSupport:
id="test-large",
choices=[Choices(finish_reason="stop", index=0, message=Message(content="A longer response", role="assistant"))],
created=1234567890,
- model="anthropic.claude-haiku-4-5-20251001-v1:0",
+ model="us.anthropic.claude-haiku-4-5-20251001-v1:0",
object="chat.completion",
system_fingerprint=None,
usage=Usage(prompt_tokens=100, completion_tokens=50, total_tokens=150),
)
large_response._hidden_params = {"custom_llm_provider": "bedrock", "region_name": "us-east-1"}
-
+
large_base_cost = completion_cost(
model="bedrock/us.anthropic.claude-haiku-4-5-20251001-v1:0",
completion_response=large_response,
messages=messages,
- region_name="us-east-1",
)
-
+
# Create large response for gov model
large_gov_response = ModelResponse(
id="test-large-gov",
@@ -303,9 +307,9 @@ class TestBedrockGovCloudSupport:
usage=Usage(prompt_tokens=100, completion_tokens=50, total_tokens=150),
)
large_gov_response._hidden_params = {"custom_llm_provider": "bedrock", "region_name": "us-gov-east-1"}
-
+
large_gov_cost = completion_cost(
- model="bedrock/us.anthropic.claude-haiku-4-5-20251001-v1:0",
+ model="bedrock/anthropic.claude-haiku-4-5-20251001-v1:0",
completion_response=large_gov_response,
messages=messages,
region_name="us-gov-east-1",
@@ -379,15 +383,16 @@ class TestBedrockGovCloudSupport:
)
# Test gov-east model completion
+ # GovCloud users specify the base anthropic.* model ID with the gov region
gov_east_result = completion(
- model="bedrock/us.anthropic.claude-haiku-4-5-20251001-v1:0",
+ model="bedrock/anthropic.claude-haiku-4-5-20251001-v1:0",
messages=[{"role": "user", "content": "Hello"}],
aws_region_name="us-gov-east-1"
)
-
+
# Test gov-west model completion
gov_west_result = completion(
- model="bedrock/us.anthropic.claude-haiku-4-5-20251001-v1:0",
+ model="bedrock/anthropic.claude-haiku-4-5-20251001-v1:0",
messages=[{"role": "user", "content": "Hello"}],
aws_region_name="us-gov-west-1"
)
diff --git a/tests/logging_callback_tests/langfuse_expected_request_body/completion_with_bedrock_call.json b/tests/logging_callback_tests/langfuse_expected_request_body/completion_with_bedrock_call.json
index b22336aecf7..dd49d9751f1 100644
--- a/tests/logging_callback_tests/langfuse_expected_request_body/completion_with_bedrock_call.json
+++ b/tests/logging_callback_tests/langfuse_expected_request_body/completion_with_bedrock_call.json
@@ -62,7 +62,7 @@
"input": 10,
"output": 10,
"unit": "TOKENS",
- "totalCost": 6.599999999999999e-05
+ "totalCost": 6e-05
},
"usageDetails": {
"input": 10,