diff --git a/amplifier_module_provider_anthropic/_cost.py b/amplifier_module_provider_anthropic/_cost.py index 88fbf73..bff060f 100644 --- a/amplifier_module_provider_anthropic/_cost.py +++ b/amplifier_module_provider_anthropic/_cost.py @@ -157,8 +157,14 @@ }, # ------------------------------------------------------------------ # Claude Haiku 3.5 ($0.80 / $4.00 / $0.08 / $1.00) + # + # The served id is claude-3-5-haiku-20241022: Claude 3-generation ids put + # the version before the family, and later ids put the family first. + # "claude-haiku-3-5-20250929" was neither shape -- family-first ordering + # with Sonnet 4.5's snapshot date. `compute_cost` does an exact + # `_RATES.get()`, so the real id missed and Haiku 3.5 cost returned None. # ------------------------------------------------------------------ - "claude-haiku-3-5-20250929": { + "claude-3-5-haiku-20241022": { "input_per_m": Decimal("0.80"), "output_per_m": Decimal("4.00"), "cache_read_per_m": Decimal("0.08"), diff --git a/tests/test_cost.py b/tests/test_cost.py index e6e8ada..b135902 100644 --- a/tests/test_cost.py +++ b/tests/test_cost.py @@ -146,6 +146,33 @@ def test_unknown_model_returns_none(): assert result is None, f"Expected None for unknown model, got {result!r}" +# --------------------------------------------------------------------------- +# Haiku 3.5 is keyed by its served model id +# --------------------------------------------------------------------------- +def test_haiku_35_real_model_id_is_priced(): + """The id the API actually returns must resolve to the Haiku 3.5 rates.""" + result = compute_cost("claude-3-5-haiku-20241022", input_tokens=1_000_000) + assert result == Decimal("0.80") + + +def test_haiku_35_output_and_cache_rates(): + assert compute_cost( + "claude-3-5-haiku-20241022", output_tokens=1_000_000 + ) == Decimal("4.00") + assert compute_cost( + "claude-3-5-haiku-20241022", cache_read_input_tokens=1_000_000 + ) == Decimal("0.08") + assert compute_cost( + "claude-3-5-haiku-20241022", cache_creation_input_tokens=1_000_000 + ) == Decimal("1.00") + + +def test_former_haiku_35_key_was_never_a_served_model_id(): + """No model was served as claude-haiku-3-5-20250929, so it must not price.""" + result = compute_cost("claude-haiku-3-5-20250929", input_tokens=1_000_000) + assert result is None + + # --------------------------------------------------------------------------- # (g) None != Decimal('0'): unknown is distinct from free # ---------------------------------------------------------------------------