:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
chore(llm-gateway): fail tests when a routed model has no price (#90342)
Adam Bowkerf619fdcb5bdc
diff --git a/services/llm-gateway/tests/test_baseten.py b/services/llm-gateway/tests/test_baseten.pyindex 91e7038e154b..f8a051b9258a 100644--- a/services/llm-gateway/tests/test_baseten.py+++ b/services/llm-gateway/tests/test_baseten.py@@ -5,12 +5,13 @@ import pytestfrom fastapi import HTTPExceptionfrom llm_gateway.baseten import (+ BASETEN_MODELS,_inject_baseten_params,ensure_baseten_configured,make_baseten_responses_call,)from llm_gateway.config import Settings-from llm_gateway.rate_limiting.cost_refresh import COST_ALIASES, normalize_metric_labels+from llm_gateway.rate_limiting.cost_refresh import ALIAS_METRIC_LABELS, COST_ALIASES, normalize_metric_labelsfrom llm_gateway.rate_limiting.model_cost_overrides import MODEL_COST_OVERRIDESGLM_MODEL = "@cf/zai-org/glm-5.2"@@ -57,6 +58,16 @@ def test_inject_baseten_params_maps_model_and_pins_api_key(assert normalize_metric_labels(litellm_model, "openai") == ("baseten", metric_model)[email protected]("public_model", sorted(BASETEN_MODELS))+def test_every_baseten_model_is_priced_and_labeled(public_model: str) -> None:+ # Derived from BASETEN_MODELS, so a model added there without a price fails here rather than+ # billing nothing: the usage reporter drops any generation whose $ai_total_cost_usd is 0.+ litellm_key = f"openai/{BASETEN_MODELS[public_model]}"+ assert litellm_key in COST_ALIASES or litellm_key in MODEL_COST_OVERRIDES+ provider, _ = ALIAS_METRIC_LABELS[litellm_key]+ assert provider == "baseten"++def test_inject_baseten_params_forces_streaming_usage() -> None:kwargs: dict[str, Any] = {"model": GLM_MODEL,diff --git a/services/llm-gateway/tests/test_cost_refresh.py b/services/llm-gateway/tests/test_cost_refresh.pyindex f9cd142f84bb..5d1791b2e838 100644--- a/services/llm-gateway/tests/test_cost_refresh.py+++ b/services/llm-gateway/tests/test_cost_refresh.py@@ -127,6 +127,24 @@ class TestApplyCostAliases:assert input_cost == pytest.approx(expected_input_cost)assert output_cost == pytest.approx(expected_output_cost)+ @pytest.mark.parametrize("alias", sorted(COST_ALIASES))+ def test_every_alias_resolves_a_nonzero_price(self, alias: str) -> None:+ # The case above pins exact rates for a hand-picked few. This one covers every alias, so a+ # newly routed model cannot ship priced at zero — apply_cost_aliases only logs a warning+ # when the canonical entry is missing, and an unpriced generation bills nothing.+ model_cost = dict(litellm.model_cost)+ apply_model_cost_overrides(model_cost)+ apply_cost_aliases(model_cost)+ litellm.model_cost = model_cost++ provider, _, model = alias.partition("/")+ input_cost, output_cost = litellm.cost_per_token(+ model=model, prompt_tokens=1000, completion_tokens=1000, custom_llm_provider=provider+ )++ assert input_cost > 0+ assert output_cost > 0+class TestNormalizeMetricLabels:def test_returns_user_facing_labels_for_aliased_model(self) -> None: