The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(billing): preserve proxy pricing for context aliases
Popkov,Daniil37040e190519
diff --git a/agent/usage_pricing.py b/agent/usage_pricing.pyindex cdaae103a1a..f6ce5af6315 100644--- a/agent/usage_pricing.py+++ b/agent/usage_pricing.py@@ -435,7 +435,7 @@ def resolve_billing_route(elif provider_name == "fireworks" or host("api.fireworks.ai"):snapshot_provider = "fireworks"if snapshot_provider:- if snapshot_provider == "openai":+ if snapshot_provider == "openai" and (not url or host("api.openai.com")):bare = strip_codex_context_variant_suffix(bare)return BillingRoute(provider=snapshot_provider, model=bare, base_url=url, billing_mode="official_docs_snapshot")if provider_name in {"custom", "local"} or (base and base_url_hostname(base) in ("localhost", "127.0.0.1")):diff --git a/contributors/emails/[email protected] b/contributors/emails/[email protected]new file mode 100644index 00000000000..e0607cde5c4--- /dev/null+++ b/contributors/emails/[email protected]@@ -0,0 +1 @@+daniil-groisdiff --git a/tests/agent/test_openai_ultrafast.py b/tests/agent/test_openai_ultrafast.pyindex 63159b484a8..eae30261240 100644--- a/tests/agent/test_openai_ultrafast.py+++ b/tests/agent/test_openai_ultrafast.py@@ -1,6 +1,7 @@"""OpenAI Ultrafast (``service_tier: "ultrafast"``): one tier word table, a per-model request gate,and pricing from the tier the response was SERVED at. Relationship tests, no catalog snapshots."""+from decimal import Decimalfrom types import SimpleNamespaceimport pytest@@ -130,6 +131,25 @@ def test_served_ultrafast_on_a_model_without_a_published_rate_is_unknown(model):assert estimate_usage_cost(model, _usage(1_000, "ultrafast"), provider="openai-api").status == "unknown"[email protected]("provider", ["openai", "openai-api"])[email protected]("base_url,amount,source", [+ ("https://api.openai.com/v1", "0.06", "official_docs_snapshot"),+ ("https://proxy.example/v1", "0.007", "provider_models_api"),+ ("https://api.openai.com.proxy.example/v1", "0.007", "provider_models_api"),+])+def test_context_alias_pricing_preserves_custom_endpoint_rates(monkeypatch, provider, base_url, amount, source):+ import agent.usage_pricing as pricing++ monkeypatch.setattr(pricing, "fetch_endpoint_model_metadata", lambda *a, **kw: {+ "gpt-6-astra-900k": {"pricing": {"prompt": "0.000003", "completion": "0.000004"}},+ })+ cost = estimate_usage_cost(+ "gpt-6-astra-900k", CanonicalUsage(input_tokens=1000, output_tokens=1000),+ provider=provider, base_url=base_url,+ )+ assert (cost.amount_usd, cost.source) == (Decimal(amount), source)++@pytest.mark.parametrize("model", SOL_SPELLINGS)def test_sol_ultrafast_codex_request_uses_the_wire_slug_and_keeps_subscription_accounting(model):from agent.fast_mode import effective_request_overrides