: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
fix(llm-gateway): price Baseten GLM through routed provider (#75981)
Adam Bowker231d59026c5c
diff --git a/services/llm-gateway/src/llm_gateway/rate_limiting/cost_refresh.py b/services/llm-gateway/src/llm_gateway/rate_limiting/cost_refresh.pyindex da181876e623..855b624f7469 100644--- a/services/llm-gateway/src/llm_gateway/rate_limiting/cost_refresh.py+++ b/services/llm-gateway/src/llm_gateway/rate_limiting/cost_refresh.py@@ -27,6 +27,7 @@ COST_ALIASES: dict[str, tuple[str, str]] = {# Modal serves the same GLM checkpoint; billed at the CF rate until trued# up against Modal's GPU-time invoices."openai/zai-org/GLM-5.2-FP8": ("cloudflare/@cf/zai-org/glm-5.2", "openai"),+ "openai/zai-org/GLM-5.2": (BASETEN_METRIC_MODEL, "openai"),"openai/moonshotai/kimi-k3": ("moonshotai/kimi-k3", "openai"),}diff --git a/services/llm-gateway/src/llm_gateway/rate_limiting/model_cost_overrides.py b/services/llm-gateway/src/llm_gateway/rate_limiting/model_cost_overrides.pyindex 982f83cb51f2..11a00c5fbcde 100644--- a/services/llm-gateway/src/llm_gateway/rate_limiting/model_cost_overrides.py+++ b/services/llm-gateway/src/llm_gateway/rate_limiting/model_cost_overrides.py@@ -2,6 +2,8 @@ from __future__ import annotationsfrom typing import TYPE_CHECKING, Final, cast+from llm_gateway.baseten import BASETEN_METRIC_MODEL+if TYPE_CHECKING:from llm_gateway.rate_limiting.model_cost_service import ModelCost@@ -32,7 +34,7 @@ BASETEN_GLM_COST: Final[ModelCost] = {}MODEL_COST_OVERRIDES: Final[dict[str, ModelCost]] = {- "openai/zai-org/GLM-5.2": cast("ModelCost", dict(BASETEN_GLM_COST)),+ BASETEN_METRIC_MODEL: cast("ModelCost", dict(BASETEN_GLM_COST)),"moonshotai/kimi-k3": cast("ModelCost", dict(KIMI_K3_COST)),"claude-fable-5": {"litellm_provider": "anthropic",@@ -86,7 +88,7 @@ MODEL_COST_OVERRIDES: Final[dict[str, ModelCost]] = {}# Provider-specific contract prices must not be replaced by a same-named LiteLLM entry.-PINNED_MODEL_COST_OVERRIDES: Final[frozenset[str]] = frozenset({"openai/zai-org/GLM-5.2"})+PINNED_MODEL_COST_OVERRIDES: Final[frozenset[str]] = frozenset({BASETEN_METRIC_MODEL})def apply_model_cost_overrides(model_cost: dict[str, ModelCost]) -> dict[str, ModelCost]:diff --git a/services/llm-gateway/tests/test_baseten.py b/services/llm-gateway/tests/test_baseten.pyindex f48f9d09d416..de93c449f7eb 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_METRIC_MODEL,_inject_baseten_params,ensure_baseten_configured,make_baseten_responses_call,)from llm_gateway.config import Settings-from llm_gateway.rate_limiting.cost_refresh import normalize_metric_labels+from llm_gateway.rate_limiting.cost_refresh import COST_ALIASES, normalize_metric_labelsfrom llm_gateway.rate_limiting.model_cost_overrides import MODEL_COST_OVERRIDESGLM_MODEL = "@cf/zai-org/glm-5.2"@@ -31,10 +32,10 @@ def test_inject_baseten_params_maps_model_and_pins_api_key() -> None:assert "headers" not in kwargsassert kwargs["extra_headers"] == {"Authorization": "Api-Key test-key"}assert kwargs["drop_params"] is True- assert BASETEN_MODEL in MODEL_COST_OVERRIDES- assert MODEL_COST_OVERRIDES[BASETEN_MODEL]["input_cost_per_token"] == 1.4e-06- assert MODEL_COST_OVERRIDES[BASETEN_MODEL]["cache_read_input_token_cost"] == 1.4e-07- assert MODEL_COST_OVERRIDES[BASETEN_MODEL]["output_cost_per_token"] == 4.4e-06+ assert COST_ALIASES[BASETEN_MODEL] == (BASETEN_METRIC_MODEL, "openai")+ assert MODEL_COST_OVERRIDES[BASETEN_METRIC_MODEL]["input_cost_per_token"] == 1.4e-06+ assert MODEL_COST_OVERRIDES[BASETEN_METRIC_MODEL]["cache_read_input_token_cost"] == 1.4e-07+ assert MODEL_COST_OVERRIDES[BASETEN_METRIC_MODEL]["output_cost_per_token"] == 4.4e-06assert normalize_metric_labels(BASETEN_MODEL, "openai") == ("baseten", "baseten/zai-org/glm-5.2")diff --git a/services/llm-gateway/tests/test_cost_refresh.py b/services/llm-gateway/tests/test_cost_refresh.pyindex 5d8c52478cc4..f9cd142f84bb 100644--- a/services/llm-gateway/tests/test_cost_refresh.py+++ b/services/llm-gateway/tests/test_cost_refresh.py@@ -99,6 +99,8 @@ class TestApplyCostAliases:("model", "prompt_tokens", "completion_tokens", "expected_input_cost", "expected_output_cost"),[("@cf/zai-org/glm-5.2", 1000, 100, 0.0014, 0.00044),+ ("zai-org/GLM-5.2-FP8", 1000, 100, 0.0014, 0.00044),+ ("zai-org/GLM-5.2", 1000, 100, 0.0014, 0.00044),("moonshotai/kimi-k3", 1000, 100, 0.003, 0.0015),],)