Skip to content

Commit 30c3e7b

Browse files
authored
Fix: Bedrock cross-region inference profile cost calculation (#14566)
* Add tests for Bedrock cross-region inference profile mapping - Test model mapping lookup works correctly - Test proxy cost calculation scenario reproduces original issue - Verify cost calculation returns expected values - Ensure compatibility with existing test patterns * Fix Bedrock cross-region inference profile cost calculation - Add mapping for bedrock/us.anthropic.claude-3-5-haiku-20241022-v1:0 - Sync backup file for local testing consistency - Resolve proxy spend tracking failures for cross-region profiles - Maintain identical configuration with standalone profile Fixes #14458
1 parent 110ce54 commit 30c3e7b

File tree

3 files changed

+77
-0
lines changed

3 files changed

+77
-0
lines changed

litellm/model_prices_and_context_window_backup.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13477,6 +13477,23 @@
1347713477
"supports_response_schema": true,
1347813478
"supports_tool_choice": true
1347913479
},
13480+
"bedrock/us.anthropic.claude-3-5-haiku-20241022-v1:0": {
13481+
"max_tokens": 8192,
13482+
"max_input_tokens": 200000,
13483+
"max_output_tokens": 8192,
13484+
"input_cost_per_token": 8e-07,
13485+
"output_cost_per_token": 4e-06,
13486+
"cache_creation_input_token_cost": 1e-06,
13487+
"cache_read_input_token_cost": 8e-08,
13488+
"litellm_provider": "bedrock",
13489+
"mode": "chat",
13490+
"supports_assistant_prefill": true,
13491+
"supports_pdf_input": true,
13492+
"supports_function_calling": true,
13493+
"supports_prompt_caching": true,
13494+
"supports_response_schema": true,
13495+
"supports_tool_choice": true
13496+
},
1348013497
"us.anthropic.claude-3-opus-20240229-v1:0": {
1348113498
"max_tokens": 4096,
1348213499
"max_input_tokens": 200000,

model_prices_and_context_window.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13477,6 +13477,23 @@
1347713477
"supports_response_schema": true,
1347813478
"supports_tool_choice": true
1347913479
},
13480+
"bedrock/us.anthropic.claude-3-5-haiku-20241022-v1:0": {
13481+
"max_tokens": 8192,
13482+
"max_input_tokens": 200000,
13483+
"max_output_tokens": 8192,
13484+
"input_cost_per_token": 8e-07,
13485+
"output_cost_per_token": 4e-06,
13486+
"cache_creation_input_token_cost": 1e-06,
13487+
"cache_read_input_token_cost": 8e-08,
13488+
"litellm_provider": "bedrock",
13489+
"mode": "chat",
13490+
"supports_assistant_prefill": true,
13491+
"supports_pdf_input": true,
13492+
"supports_function_calling": true,
13493+
"supports_prompt_caching": true,
13494+
"supports_response_schema": true,
13495+
"supports_tool_choice": true
13496+
},
1348013497
"us.anthropic.claude-3-opus-20240229-v1:0": {
1348113498
"max_tokens": 4096,
1348213499
"max_input_tokens": 200000,
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
"""Test Bedrock cross-region inference profile model mapping"""
2+
import os
3+
import sys
4+
5+
sys.path.insert(0, os.path.abspath("../../../.."))
6+
7+
from litellm.utils import _get_model_info_helper
8+
from litellm.cost_calculator import completion_cost
9+
from litellm.types.utils import ModelResponse, Usage, Choices, Message
10+
11+
12+
def test_bedrock_cross_region_inference_profile_mapping():
13+
"""Test that bedrock cross-region inference profile model is mapped"""
14+
model = "bedrock/us.anthropic.claude-3-5-haiku-20241022-v1:0"
15+
16+
model_info = _get_model_info_helper(model=model, custom_llm_provider="bedrock")
17+
18+
assert model_info is not None
19+
assert model_info["litellm_provider"] == "bedrock"
20+
assert model_info["input_cost_per_token"] == 8e-07
21+
22+
23+
def test_proxy_cost_calculation_scenario():
24+
"""Test exact GitHub issue scenario: proxy cost calculation"""
25+
model = "litellm_proxy/bedrock/us.anthropic.claude-3-5-haiku-20241022-v1:0"
26+
27+
# Test model info lookup works
28+
model_info = _get_model_info_helper(model=model, custom_llm_provider="litellm_proxy")
29+
assert model_info is not None
30+
31+
# Test cost calculation works
32+
response = ModelResponse(
33+
id="test",
34+
created=1234567890,
35+
model=model,
36+
object="chat.completion",
37+
choices=[Choices(finish_reason="stop", index=0, message=Message(content="Test", role="assistant"))],
38+
usage=Usage(total_tokens=150, prompt_tokens=100, completion_tokens=50),
39+
)
40+
41+
cost = completion_cost(completion_response=response, model=model, custom_llm_provider="litellm_proxy")
42+
expected_cost = (100 * 8e-07) + (50 * 4e-06)
43+
assert cost == expected_cost

0 commit comments

Comments
 (0)