: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): drop the always-on GLM Baseten routing flag (#99376)
posthog[bot]8e811daaf2f7
diff --git a/services/llm-gateway/README.md b/services/llm-gateway/README.mdindex d818e7302dc0..c570ddaf02a8 100644--- a/services/llm-gateway/README.md+++ b/services/llm-gateway/README.md@@ -216,7 +216,6 @@ The gateway exposes models consistently across Anthropic Messages, chat/completi- **GLM 5.2** (`@cf/zai-org/glm-5.2`) can run on Cloudflare Workers AI, Modal, or Baseten.- **GLM 5.3** (`zai-org/glm-5.3`) runs only on Baseten and is available to ReviewHog and PostHog Desktop behind its own `posthog-code-glm-53-model` flag.- Deliberately not `tasks-glm-baseten-inference`: that one only moves GLM 5.2 traffic onto Baseten, so sharing it would grant 5.3 by proxy the moment 5.2 routing changed.GLM 5.3 has no open weights released yet, so the flag is not created: the access gate fails closed, keeping the model blocked server-side and hidden in every picker.Do not create the flag until Baseten lists the model and the deployment slug, context window, and contract rate in `model_cost_overrides.py` / `model_registry.py` are confirmed against `inference.baseten.co/v1/models`: the rate is pinned, so a wrong placeholder bills at the wrong price with no automatic correction.- **GLM 5.3 Flash** (`zai-org/glm-5.3-flash`) runs only on Baseten and is available to ReviewHog and PostHog Desktop behind its own `posthog-code-glm-53-flash-model` flag.@@ -229,7 +228,7 @@ Provider configuration:- **Modal** (an OpenAI-compatible vLLM endpoint) — configure `LLM_GATEWAY_MODAL_API_BASE`, `LLM_GATEWAY_MODAL_KEY`, and `LLM_GATEWAY_MODAL_SECRET` (a [Modal proxy-token](https://modal.com/docs/guide/endpoints) pair, sent as `Modal-Key`/`Modal-Secret` headers).- **Baseten** (an OpenAI-compatible endpoint) - configure `LLM_GATEWAY_BASETEN_API_BASE` and `LLM_GATEWAY_BASETEN_API_KEY`.-The `tasks-glm-baseten-inference` feature flag routes matching users' GLM 5.2 traffic to Baseten when its API key is configured. The flag is evaluated server-side, and caller-forwarded flag headers cannot select Baseten. Cloudflare or Modal must remain configured as the fallback for users who do not match the flag or when evaluation is unavailable.+GLM 5.2 traffic goes to Baseten whenever its API key is configured. No feature flag gates this, and caller-forwarded flag headers cannot select Baseten. Cloudflare or Modal serves GLM 5.2 only while the Baseten key is absent, so removing that key is the rollback.Two knobs opt traffic into Modal (OR semantics, both default off):diff --git a/services/llm-gateway/src/llm_gateway/flags.py b/services/llm-gateway/src/llm_gateway/flags.pyindex f4bc4e612234..c50a528a1414 100644--- a/services/llm-gateway/src/llm_gateway/flags.py+++ b/services/llm-gateway/src/llm_gateway/flags.py@@ -11,7 +11,6 @@ from llm_gateway.config import get_settingslogger = structlog.get_logger(__name__)GLM_MODAL_FLAG = "tasks-glm-modal-inference"-GLM_BASETEN_FLAG = "tasks-glm-baseten-inference"_flag_cache: TTLCache[tuple[str, str], bool] = TTLCache(maxsize=10_000, ttl=60)# Global per-flag backoff so an evaluation outage doesn't stack one blocking roundtrip per new user.diff --git a/services/llm-gateway/src/llm_gateway/inference_routing.py b/services/llm-gateway/src/llm_gateway/inference_routing.pyindex 59f488aa03d5..bef928bfad13 100644--- a/services/llm-gateway/src/llm_gateway/inference_routing.py+++ b/services/llm-gateway/src/llm_gateway/inference_routing.py@@ -48,7 +48,7 @@ from llm_gateway.cloudflare import (make_cloudflare_responses_call,)from llm_gateway.config import Settings, get_settings-from llm_gateway.flags import GLM_BASETEN_FLAG, GLM_MODAL_FLAG, evaluate_flag+from llm_gateway.flags import GLM_MODAL_FLAG, evaluate_flagfrom llm_gateway.modal import (is_modal_configured,is_modal_served_model,@@ -106,14 +106,10 @@ async def _route_to_modal(model: str, user: AuthenticatedUser, product: str, setreturn await evaluate_flag(GLM_MODAL_FLAG, user.distinct_id) or False-async def _route_to_baseten(model: str, user: AuthenticatedUser, settings: Settings) -> bool:+def _route_to_baseten(model: str, settings: Settings) -> bool:if not is_baseten_configured(settings):return False- if model in BASETEN_EXCLUSIVE_MODELS:- return True- if model != BASETEN_PUBLIC_MODEL:- return False- return await evaluate_flag(GLM_BASETEN_FLAG, user.distinct_id) or False+ return model in BASETEN_EXCLUSIVE_MODELS or model == BASETEN_PUBLIC_MODELasync def _send_provider_request(@@ -168,7 +164,7 @@ async def _send_inference_request(model = request_data["model"]settings = get_settings()- if await _route_to_baseten(model, user, settings):+ if _route_to_baseten(model, settings):api_base, api_key = ensure_baseten_configured(settings)return await _send_provider_request(request_data, user, is_streaming, product, baseten_config, make_baseten_call(api_base, api_key)diff --git a/services/llm-gateway/tests/test_inference_routing.py b/services/llm-gateway/tests/test_inference_routing.pyindex 796b100510a0..78c3f8f73018 100644--- a/services/llm-gateway/tests/test_inference_routing.py+++ b/services/llm-gateway/tests/test_inference_routing.py@@ -172,14 +172,16 @@ async def test_flag_opts_into_modal_at_fraction_zero() -> None:@pytest.mark.parametrize(("send_fn", "endpoint"), [(row[0], f"baseten_{row[2].removeprefix('cloudflare_')}") for row in SURFACES])-async def test_baseten_flag_routes_each_surface(send_fn: Any, endpoint: str) -> None:+async def test_configured_baseten_serves_public_glm_on_each_surface(send_fn: Any, endpoint: str) -> None:+ # Public GLM goes to Baseten on configuration alone, so the route must not depend on (or pay+ # for) a remote flag evaluation.handle = AsyncMock(return_value={"ok": True})settings = _settings(baseten_api_key="baseten-key")- _, evaluate = await _send(settings, handle, flag=True, send_fn=send_fn)+ _, evaluate = await _send(settings, handle, send_fn=send_fn)assert handle.call_args.kwargs["provider_config"].endpoint_name == endpoint- evaluate.assert_awaited_once_with("tasks-glm-baseten-inference", "d-1")+ evaluate.assert_not_called()@pytest.mark.parametrize("model", [DEEPSEEK_MODEL, GLM53_MODEL, GLM53_FLASH_MODEL])@@ -248,32 +250,17 @@ async def test_modal_flag_is_evaluated_without_baseten_credentials() -> None:evaluate.assert_awaited_once_with("tasks-glm-modal-inference", "d-1")-async def test_baseten_flag_does_not_rewrite_other_cloudflare_models() -> None:+async def test_configured_baseten_does_not_capture_other_cloudflare_models() -> None:handle = AsyncMock(return_value={"ok": True})request = {"model": KIMI_MODEL, "messages": [{"role": "user", "content": "hi"}]}- _, evaluate = await _send(_settings(baseten_api_key="baseten-key"), handle, flag=True, request_data=request)+ _, evaluate = await _send(_settings(baseten_api_key="baseten-key"), handle, request_data=request)assert _called_providers(handle) == ["cloudflare"]assert handle.call_args.kwargs["model"] == KIMI_MODELevaluate.assert_not_called()- ("settings", "expected_provider"),- [- (_settings(baseten_api_key="baseten-key"), "cloudflare"),- (_settings(baseten_api_key="baseten-key", glm_modal_traffic_fraction=1.0), "modal"),- ],-)-async def test_baseten_flag_off_preserves_existing_routing(settings: Settings, expected_provider: str) -> None:- handle = AsyncMock(return_value={"ok": True})-- await _send(settings, handle, flag=False)-- assert _called_providers(handle) == [expected_provider]--async def test_forwarded_flag_header_cannot_force_modal() -> None:# x-posthog-flag-* headers come from any authenticated caller — they must not override the# server-side flag/fraction, or a client could pin itself to a backend operators turned off.@@ -284,14 +271,14 @@ async def test_forwarded_flag_header_cannot_force_modal() -> None:@pytest.mark.parametrize(- ("settings", "flag", "expected_provider"),+ ("settings", "expected_provider"),[- (_settings(glm_modal_traffic_fraction=1.0), None, "modal"),- (_settings(baseten_api_key="baseten-key"), True, "baseten"),+ (_settings(glm_modal_traffic_fraction=1.0), "modal"),+ (_settings(baseten_api_key="baseten-key"), "baseten"),],)async def test_provider_failure_propagates_without_cross_backend_retry(- settings: Settings, flag: bool | None, expected_provider: str+ settings: Settings, expected_provider: str) -> None:handle = AsyncMock(side_effect=ProviderError(@@ -299,7 +286,7 @@ async def test_provider_failure_propagates_without_cross_backend_retry())with pytest.raises(HTTPException) as exc_info:- await _send(settings, handle, flag=flag)+ await _send(settings, handle)assert exc_info.value.status_code == 502assert _called_providers(handle) == [expected_provider]diff --git a/services/llm-gateway/tests/test_product_config.py b/services/llm-gateway/tests/test_product_config.pyindex 58734555ee60..553334fcbffe 100644--- a/services/llm-gateway/tests/test_product_config.py+++ b/services/llm-gateway/tests/test_product_config.py@@ -5,7 +5,7 @@ from fastapi import HTTPExceptionfrom llm_gateway.baseten import BASETEN_MODELSfrom llm_gateway.cloudflare import CLOUDFLARE_ALLOWED_MODELS-from llm_gateway.flags import GLM_BASETEN_FLAG, GLM_MODAL_FLAG+from llm_gateway.flags import GLM_MODAL_FLAGfrom llm_gateway.inference_routing import is_inference_routed_modelfrom llm_gateway.modal import is_modal_served_modelfrom llm_gateway.products.config import (@@ -764,7 +764,7 @@ class TestModelAccessFlag:def test_every_gated_model_has_its_own_flag(self):flags = list(MODEL_ACCESS_FLAGS.values())assert len(flags) == len(set(flags))- assert not set(flags) & {GLM_BASETEN_FLAG, GLM_MODAL_FLAG}+ assert GLM_MODAL_FLAG not in flags@pytest.mark.parametrize("model", [None, "", "gpt-5.2", "claude-opus-5", "@cf/zai-org/glm-5.2"])def test_ungated_models_need_no_flag(self, model: str | None):