litellm/tests/unit/llms/bedrock/test_cost_calculation.py
Kerry Lu 560372456e
fix(bedrock): price claude_platform calls from their own cost map rows (#48150)
* fix(bedrock): price claude_platform calls from the anthropic cost map rows

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix: avoid recursive Claude Platform lookups

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>

* fix(bedrock): price claude_platform calls from their own cost map rows

Replace the claude_platform -> anthropic lookup redirect with
bedrock/claude_platform/* rows, and apply the inference_geo multiplier
in the bedrock cost path so US-only inference is priced at 1.1x

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test(bedrock): exempt claude_platform rows from the Converse routing guard

The claude_platform/ route is explicit in the row key, so these rows are
not accidental non-Converse Bedrock chat rows

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-24 13:54:18 -07:00

43 lines
1.3 KiB
Python

import json
from importlib.resources import files
from typing import Final
import pytest
import litellm
from litellm.types.utils import Usage
CLAUDE_PLATFORM_PREFIX: Final = "bedrock/claude_platform/"
CLAUDE_PLATFORM_KEYS: Final = tuple(
key
for key in json.loads(files("litellm").joinpath("model_prices_and_context_window_backup.json").read_text())
if key.startswith(CLAUDE_PLATFORM_PREFIX)
)
def test_claude_platform_rows_exist() -> None:
assert CLAUDE_PLATFORM_KEYS
@pytest.mark.parametrize("inference_geo", ["global", "us"])
@pytest.mark.parametrize("key", CLAUDE_PLATFORM_KEYS)
def test_claude_platform_cost_matches_claude_api_cost(
local_model_cost_map: None, key: str, inference_geo: str
) -> None:
usage: Final = Usage(
prompt_tokens=1_000,
completion_tokens=200,
cache_read_input_tokens=300,
cache_creation_input_tokens=250,
inference_geo=inference_geo,
)
claude_platform_cost: Final = litellm.cost_per_token(
model=key.removeprefix("bedrock/"), custom_llm_provider="bedrock", usage_object=usage
)
claude_api_cost: Final = litellm.cost_per_token(
model=key.removeprefix(CLAUDE_PLATFORM_PREFIX), custom_llm_provider="anthropic", usage_object=usage
)
assert claude_platform_cost == pytest.approx(claude_api_cost)
assert sum(claude_platform_cost) > 0