mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-17 09:34:48 +00:00
fix(bedrock): price a model_id ARN at its region's row
This commit is contained in:
parent
60f03632d6
commit
a341c87f6f
2 changed files with 16 additions and 8 deletions
|
|
@ -22,6 +22,7 @@ from litellm.constants import (
|
|||
OPENAI_LIVE_TERMINAL_RESPONSE_EVENT_TYPES,
|
||||
REALTIME_METERED_USAGE_KEY,
|
||||
)
|
||||
from litellm.litellm_core_utils.aws_partition import is_bedrock_arn
|
||||
from litellm.litellm_core_utils.core_helpers import as_str_mapping
|
||||
from litellm.litellm_core_utils.cost_discount import resolve_cost_discount
|
||||
from litellm.litellm_core_utils.decisions_pricing import decisions_pricing_fields, is_decisions_call_type
|
||||
|
|
@ -884,6 +885,15 @@ def _bedrock_registration_has_prices(entry: Mapping[str, object]) -> bool:
|
|||
)
|
||||
|
||||
|
||||
def _bedrock_invoked_profile(invoked_model_id: str) -> ModelInfo | None:
|
||||
profile: Final = _cost_map_model_info(invoked_model_id, "bedrock")
|
||||
arn_region: Final = invoked_model_id.split(":")[3] if is_bedrock_arn(invoked_model_id) else None
|
||||
regional_key: Final = f"bedrock/{arn_region}/{profile['key']}" if profile is not None and arn_region else None
|
||||
if regional_key is None or _raw_cost_map_entry(regional_key) is None:
|
||||
return profile
|
||||
return _cost_map_model_info(regional_key, "bedrock")
|
||||
|
||||
|
||||
def _bedrock_pricing_info(
|
||||
model: str | None,
|
||||
invoked_model_id: str | None,
|
||||
|
|
@ -900,7 +910,7 @@ def _bedrock_pricing_info(
|
|||
),
|
||||
None,
|
||||
)
|
||||
profile: Final = _cost_map_model_info(invoked_model_id, "bedrock") if invoked_model_id else None
|
||||
profile: Final = _bedrock_invoked_profile(invoked_model_id) if invoked_model_id else None
|
||||
if profile is None or not _declares_rates(profile):
|
||||
return _cost_map_model_info(registration[0], None) if registration is not None else None
|
||||
if registration is None or registration[0] == profile["key"]:
|
||||
|
|
|
|||
|
|
@ -406,24 +406,22 @@ def test_bedrock_cohere_embedding_bills_the_row_of_the_region_it_calls(
|
|||
def test_bedrock_embedding_with_a_govcloud_arn_model_id_bills_at_the_arn_region_row(
|
||||
respx_mock: respx.MockRouter,
|
||||
) -> None:
|
||||
arn: Final = "arn:aws-us-gov:bedrock:us-gov-west-1::foundation-model/amazon.nova-2-multimodal-embeddings-v1:0"
|
||||
route = respx_mock.post(url__startswith=f"{GOVCLOUD_WEST_RUNTIME}/model/").mock(
|
||||
return_value=httpx.Response(
|
||||
200, json={"embeddings": [{"embeddingType": "TEXT", "embedding": [0.1, 0.2, 0.3]}]}
|
||||
)
|
||||
return_value=httpx.Response(200, json=titan_embedding_response)
|
||||
)
|
||||
|
||||
response: Final = litellm.embedding(
|
||||
model="bedrock/amazon.nova-2-multimodal-embeddings-v1:0",
|
||||
model="bedrock/amazon.titan-embed-text-v2:0",
|
||||
input=[test_input],
|
||||
api_key="test-bearer-token",
|
||||
model_id=arn,
|
||||
model_id="arn:aws-us-gov:bedrock:us-gov-west-1::foundation-model/amazon.titan-embed-text-v2:0",
|
||||
)
|
||||
|
||||
assert route.call_count == 1
|
||||
assert response.usage.prompt_tokens > 0
|
||||
assert response._hidden_params["response_cost"] == pytest.approx(
|
||||
response.usage.prompt_tokens
|
||||
* litellm.model_cost["bedrock/us-gov-west-1/amazon.nova-2-multimodal-embeddings-v1:0"]["input_cost_per_token"]
|
||||
* litellm.model_cost["bedrock/us-gov-west-1/amazon.titan-embed-text-v2:0"]["input_cost_per_token"]
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue