AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
fix(backend): price Sonnet 5.5 cache reads at Anthropic's $0.10 per million (#15468)
Nicholas Tindled57a14b9b6b1
diff --git a/autogpt_platform/backend/backend/copilot/anthropic_rate_card_test.py b/autogpt_platform/backend/backend/copilot/anthropic_rate_card_test.pyindex 842140c99b..f64ad5fddd 100644--- a/autogpt_platform/backend/backend/copilot/anthropic_rate_card_test.py+++ b/autogpt_platform/backend/backend/copilot/anthropic_rate_card_test.py@@ -205,7 +205,7 @@ class TestSonnet5_5Rates:assert cost == 12.0assert "falling back" not in caplog.text- @pytest.mark.parametrize("cache_ttl, expected_cost", [("5m", 2.7), ("1h", 4.2)])+ @pytest.mark.parametrize("cache_ttl, expected_cost", [("5m", 2.6), ("1h", 4.1)])def test_sonnet_5_5_cache_rates(self, cache_ttl, expected_cost):cost = compute_anthropic_cost_usd(model="claude-sonnet-5-5",diff --git a/autogpt_platform/backend/backend/copilot/anthropic_rates.json b/autogpt_platform/backend/backend/copilot/anthropic_rates.jsonindex f24f9df48d..518cd92a47 100644--- a/autogpt_platform/backend/backend/copilot/anthropic_rates.json+++ b/autogpt_platform/backend/backend/copilot/anthropic_rates.json@@ -902,8 +902,8 @@"cache_creation_input_token_cost": 2.5e-06,"cache_creation_input_token_cost_above_1hr": 4e-06,"cache_creation_input_token_cost_batches": 1.25e-06,- "cache_read_input_token_cost": 2e-07,- "cache_read_input_token_cost_batches": 1e-07,+ "cache_read_input_token_cost": 1e-07,+ "cache_read_input_token_cost_batches": 5e-08,"input_cost_per_token": 2e-06,"input_cost_per_token_batches": 1e-06,"litellm_provider": "anthropic",diff --git a/autogpt_platform/backend/backend/copilot/billing_e2e/audit_test.py b/autogpt_platform/backend/backend/copilot/billing_e2e/audit_test.pyindex 527c4006a7..247013f793 100644--- a/autogpt_platform/backend/backend/copilot/billing_e2e/audit_test.py+++ b/autogpt_platform/backend/backend/copilot/billing_e2e/audit_test.py@@ -21,7 +21,7 @@ from .ledger import (TreeCharge,)from .provider import PlannedFault-from .scenarios import SCENARIOS, _sdk_anthropic_failing+from .scenarios import SCENARIOS, _sdk_anthropic_failing, expected_charge_usd# A turn relaunched after the provider billed a call that streamed nothing._RELAUNCHED = _sdk_anthropic_failing(@@ -185,8 +185,11 @@ def _as_the_cli_reports(call: Call) -> AssistantMessage:def _turn_charged_for(*calls: Call) -> tuple[PlatformLedger, list[Usage]]:- """Turn 1's ledger and session usage, as if the platform charged ``calls``."""- microdollars = usd_to_microdollars(sum(call.invoice_usd for call in calls))+ """Turn 1's ledger and session usage, as if the platform charged ``calls``+ on the direct route's basis."""+ microdollars = usd_to_microdollars(+ sum(expected_charge_usd(_RELAUNCHED.charge, call) for call in calls)+ )input_tokens = sum(call.usage.input_tokens for call in calls)output_tokens = sum(call.usage.output_tokens for call in calls)cache_read = sum(call.usage.cache_read_tokens for call in calls)diff --git a/autogpt_platform/backend/backend/copilot/billing_e2e/invoice.py b/autogpt_platform/backend/backend/copilot/billing_e2e/invoice.pyindex 9275cfb44b..907c9050c7 100644--- a/autogpt_platform/backend/backend/copilot/billing_e2e/invoice.py+++ b/autogpt_platform/backend/backend/copilot/billing_e2e/invoice.py@@ -46,6 +46,16 @@ class Price(BaseModel):# Anthropic's list prices. The bundled CLI prices its calls from its own copy.ANTHROPIC_PRICES: dict[str, Price] = {+ SONNET: Price(+ input=2.0, output=10.0, cache_read=0.1, cache_write_5m=2.5, cache_write_1h=4.0+ ),+}++# The bundled CLI's own copy, which the platform charges where no provider+# reports a cost. It prices Sonnet 5.5 cache reads at $0.20 per million,+# twice Anthropic's rate; a row charged from it fails once the platform+# stops charging the CLI's estimate.+CLI_ESTIMATE_PRICES: dict[str, Price] = {SONNET: Price(input=2.0, output=10.0, cache_read=0.2, cache_write_5m=2.5, cache_write_1h=4.0),@@ -56,7 +66,7 @@ ANTHROPIC_PRICES: dict[str, Price] = {# mismatch instead of matching by coincidence.OPENROUTER_PRICES: dict[str, Price] = {f"anthropic/{SONNET}": Price(- input=2.2, output=11.0, cache_read=0.22, cache_write_5m=2.75, cache_write_1h=4.4+ input=2.2, output=11.0, cache_read=0.11, cache_write_5m=2.75, cache_write_1h=4.4),KIMI: Price(input=0.66,diff --git a/autogpt_platform/backend/backend/copilot/billing_e2e/scenarios.py b/autogpt_platform/backend/backend/copilot/billing_e2e/scenarios.pyindex 1badf6ebe5..520dfe9016 100644--- a/autogpt_platform/backend/backend/copilot/billing_e2e/scenarios.py+++ b/autogpt_platform/backend/backend/copilot/billing_e2e/scenarios.py@@ -21,7 +21,7 @@ from typing import Any, Literalfrom pydantic import BaseModel-from .invoice import ANTHROPIC_PRICES, KIMI, MOONSHOT_FALLBACK, SONNET, Call+from .invoice import CLI_ESTIMATE_PRICES, KIMI, MOONSHOT_FALLBACK, SONNET, Callfrom .ledger import CreditBilling, PlannedDrainfrom .provider import PlannedFault@@ -106,11 +106,13 @@ _OPENROUTER = {# is configured._DIRECT = {"use_openrouter": False, "api_key": "sk-ant-billing-e2e"}+# Anthropic reports no cost, so a direct turn is charged the CLI's own+# estimate rather than the invoice (see ``CLI_ESTIMATE_PRICES``)._SDK_ANTHROPIC = Scenario(id="sdk-anthropic",engine="sdk",model=SONNET,- charge="invoice",+ charge="cli_estimate",cost_log_provider="anthropic",config={**_DIRECT, "claude_agent_model": SONNET},)@@ -306,8 +308,8 @@ def expected_charge_usd(basis: ChargeBasis, call: Call) -> float:if basis == "invoice":return call.invoice_usdif basis == "cli_estimate":- list_price = ANTHROPIC_PRICES[call.model.removeprefix("anthropic/")]- return list_price.of(call.usage, call.cache_ttl)+ cli_price = CLI_ESTIMATE_PRICES[call.model.removeprefix("anthropic/")]+ return cli_price.of(call.usage, call.cache_ttl)if basis == "moonshot_estimate":return MOONSHOT_FALLBACK.of(call.usage, None)return 0.0diff --git a/autogpt_platform/scripted_model/scripted_model/invoice.py b/autogpt_platform/scripted_model/scripted_model/invoice.pyindex b6300eb108..4010acdc6e 100644--- a/autogpt_platform/scripted_model/scripted_model/invoice.py+++ b/autogpt_platform/scripted_model/scripted_model/invoice.py@@ -25,6 +25,9 @@ class Price:# Keyed by model name without the vendor prefix (``anthropic/``).+# Sonnet 5.5's cache read is the bundled CLI's $0.20, not Anthropic's $0.10:+# this model serves no OpenRouter generation lookup, so the platform charges+# the CLI's own estimate, and the journeys check that charge matches this bill.PRICES: dict[str, Price] = {"claude-sonnet-5-5": Price(2.0, 10.0, 0.2, 2.5, 4.0),"claude-opus-5-5": Price(4.0, 20.0, 0.2, 5.0, 8.0),