Skip to content

: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.

feat(llm-gateway): switch the legacy wizard product off with an upgrade message (merge last) (#96861)

Brandon20027256c929
diff --git a/services/llm-gateway/PARITY.md b/services/llm-gateway/PARITY.md
index 2a6ca7ac8daf..6604efeed7a5 100644
--- a/services/llm-gateway/PARITY.md
+++ b/services/llm-gateway/PARITY.md
@@ -36,15 +36,15 @@ Existing Django callers should use `build_openai_client`, `build_async_openai_cl
### ⛔ Stay on the Python gateway for now
-| Use case | Blocking contract |
-| ------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
-| PostHog Desktop, PostHog Code, cloud agents, onboarding, Wizard, and similar first-party products | Go can pin product and user attribution in a scoped token, but it does not apply Django's OAuth application allowlists, project access checks, plans, or billing policy. Desktop also requires a request-selected project validated against OAuth scope, live organization membership, and project-level access control. An asserted product remains caller-controlled and is not an authorization boundary. |
-| Django plan or quota enforcement | Go supports rolling attribution budgets, a hard team cap, and per-token caps. Python still owns plan checks, quota buckets, free-model policy, and requests that debit no wallet. |
-| Agent runs a customer can start on demand | Go can cap one run with a scoped token, but the Django integration only mints tokens for server-authorized internal products. User-started runs still need Python's provenance-based policy. |
-| OpenRouter or Cloudflare Workers AI | These provider paths are not available in Go. |
-| OpenAI audio transcription | Go has no transcription endpoint. |
-| OpenAI models through Anthropic Messages | Go does not provide this reverse translation. |
-| Python product usage status | The Python product usage and quota API is different from Go request usage and wallet APIs. |
+| Use case | Blocking contract |
+| ----------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
+| PostHog Desktop, PostHog Code, cloud agents, onboarding, and similar first-party products | Go can pin product and user attribution in a scoped token, but it does not apply Django's OAuth application allowlists, project access checks, plans, or billing policy. Desktop also requires a request-selected project validated against OAuth scope, live organization membership, and project-level access control. An asserted product remains caller-controlled and is not an authorization boundary. |
+| Django plan or quota enforcement | Go supports rolling attribution budgets, a hard team cap, and per-token caps. Python still owns plan checks, quota buckets, free-model policy, and requests that debit no wallet. |
+| Agent runs a customer can start on demand | Go can cap one run with a scoped token, but the Django integration only mints tokens for server-authorized internal products. User-started runs still need Python's provenance-based policy. The wizard is the exception, and the worked example: Django runs the blocklist, the rollout switch, the program pin, the mint throttle, and the posture-tiered cap at mint, then pins the model, effort, product, and org into the token. The wizard product is retired here, so a wizard call on this gateway answers 403 with an upgrade message. |
+| OpenRouter or Cloudflare Workers AI | These provider paths are not available in Go. |
+| OpenAI audio transcription | Go has no transcription endpoint. |
+| OpenAI models through Anthropic Messages | Go does not provide this reverse translation. |
+| Python product usage status | The Python product usage and quota API is different from Go request usage and wallet APIs. |
For PostHog Desktop, the Python gateway maps Django credential rejections to generic access denials. Transport, server, and malformed-response failures remain retryable service errors.
diff --git a/services/llm-gateway/src/llm_gateway/dependencies.py b/services/llm-gateway/src/llm_gateway/dependencies.py
index 11e2b7a7ea76..d1cf0a38ed90 100644
--- a/services/llm-gateway/src/llm_gateway/dependencies.py
+++ b/services/llm-gateway/src/llm_gateway/dependencies.py
@@ -157,7 +157,17 @@ async def enforce_product_access(
)
if not allowed:
- raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail=error)
+ # The structured form enforce_desktop_access uses, so a client can read
+ # `code` and `reason` instead of matching message text.
+ config = get_product_config(product)
+ denial: dict[str, object] = {
+ "message": error,
+ "type": "permission_error",
+ "code": "product_access_denied",
+ }
+ if config is not None and config.denial_message is not None:
+ denial["reason"] = "product_retired"
+ raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail={"error": denial})
await enforce_desktop_access(request, user, product)
return user
diff --git a/services/llm-gateway/src/llm_gateway/products/config.py b/services/llm-gateway/src/llm_gateway/products/config.py
index 1d3bc6a6722e..1807fc8376db 100644
--- a/services/llm-gateway/src/llm_gateway/products/config.py
+++ b/services/llm-gateway/src/llm_gateway/products/config.py
@@ -52,6 +52,9 @@ class ProductConfig:
# unaffected (they reach the gateway only with an explicit, feature-gated
# llm_gateway:read scope, not the wildcard a consent token uses).
requires_server_credential: bool = False
+ # Set on a retired product: every caller is refused with this message, whatever
+ # the auth method, so the entry can stay (aliases, cost keys) while nothing routes.
+ denial_message: str | None = None
BEDROCK_MODELS = BEDROCK_MODEL_IDS
@@ -65,6 +68,8 @@ TWIG_US_APP_ID = POSTHOG_CODE_US_APP_ID
TWIG_EU_APP_ID = POSTHOG_CODE_EU_APP_ID
WIZARD_US_APP_ID = "019a0c79-b69d-0000-f31b-b41345208c9d"
WIZARD_EU_APP_ID = "019a12d0-6edd-0000-0458-86616af3a3db"
+# What a retired wizard product answers every caller with.
+WIZARD_RETIRED_MESSAGE = "The wizard now runs on the PostHog AI gateway. Upgrade with: npx @posthog/wizard@latest"
POSTHOG_AI_US_APP_ID = "019ee060-3a0e-0000-7e9c-4e6b48dfae66"
POSTHOG_AI_EU_APP_ID = "019ee061-5620-0000-1a0d-ab1160fceeb1"
POSTHOG_AI_DEV_APP_ID = "019edb1a-cce4-0000-1f6d-682061862da9"
@@ -213,10 +218,13 @@ PRODUCTS: Final[dict[str, ProductConfig]] = {
allow_api_keys=True,
credit_bucket=None,
),
+ # Retired: the wizard mints per-run scoped tokens on the ai-gateway instead. The
+ # entry stays so the product name still resolves and answers with the upgrade path.
"wizard": ProductConfig(
- allowed_application_ids=frozenset({WIZARD_US_APP_ID, WIZARD_EU_APP_ID}),
+ allowed_application_ids=frozenset(),
allowed_models=None,
- allow_api_keys=True,
+ allow_api_keys=False,
+ denial_message=WIZARD_RETIRED_MESSAGE,
),
"llma_labeling": ProductConfig(
allowed_application_ids=None,
@@ -558,6 +566,10 @@ def check_product_access(
config = PRODUCTS.get(resolved_product)
if config is None:
return False, f"Unknown product: {product}"
+ # Before the auth-method checks: debug mode skips the application-id check, and
+ # a retired product must refuse there too.
+ if config.denial_message is not None:
+ return False, config.denial_message
settings = get_settings()
is_api_key = auth_method == "personal_api_key"
diff --git a/services/llm-gateway/tests/test_anthropic.py b/services/llm-gateway/tests/test_anthropic.py
index 7497ca0d65ae..c7ba75124950 100644
--- a/services/llm-gateway/tests/test_anthropic.py
+++ b/services/llm-gateway/tests/test_anthropic.py
@@ -442,7 +442,7 @@ class TestAnthropicMessagesEndpoint:
mock_anthropic.return_value = mock_response
response = authenticated_client.post(
- "/wizard/v1/messages",
+ "/ci/v1/messages",
json=provider_request_body,
headers=provider_request_headers,
)
@@ -452,7 +452,7 @@ class TestAnthropicMessagesEndpoint:
assert data["id"] == "msg_123"
@patch("llm_gateway.api.anthropic.litellm.anthropic_messages")
- def test_wizard_opus_5_high_effort_enables_thinking(
+ def test_opus_5_high_effort_enables_thinking(
self,
mock_anthropic: MagicMock,
authenticated_client: TestClient,
@@ -464,7 +464,7 @@ class TestAnthropicMessagesEndpoint:
mock_anthropic.return_value = mock_response
response = authenticated_client.post(
- "/wizard/v1/messages",
+ "/ci/v1/messages",
json={
"model": "claude-opus-5",
"messages": [{"role": "user", "content": "Hello"}],
@@ -477,11 +477,34 @@ class TestAnthropicMessagesEndpoint:
assert response.status_code == 200
assert mock_anthropic.call_args.kwargs["thinking"] == {"type": "adaptive"}
+ @patch("llm_gateway.api.anthropic.litellm.anthropic_messages")
+ def test_retired_wizard_route_answers_the_upgrade_path(
+ self,
+ mock_anthropic: MagicMock,
+ authenticated_client: TestClient,
+ provider_request_body: dict,
+ provider_request_headers: dict[str, str],
+ ) -> None:
+ # The body a stale CLI build sees: a code to branch on and the upgrade command.
+ response = authenticated_client.post(
+ "/wizard/v1/messages",
+ json=provider_request_body,
+ headers=provider_request_headers,
+ )
+
+ assert response.status_code == 403
+ error = response.json()["error"]
+ assert error["type"] == "permission_error"
+ assert error["code"] == "product_access_denied"
+ assert error["reason"] == "product_retired"
+ assert "npx @posthog/wizard@latest" in error["message"]
+ mock_anthropic.assert_not_called()
+
@pytest.mark.parametrize(
"product",
[
pytest.param("llm_gateway", id="llm_gateway_product"),
- pytest.param("wizard", id="wizard_product"),
+ pytest.param("ci", id="ci_product"),
],
)
@patch("llm_gateway.api.anthropic.litellm.anthropic_messages")
@@ -1338,7 +1361,7 @@ class TestAnthropicCountTokensEndpoint:
mock_httpx_client_cls.return_value = mock_client
response = authenticated_client.post(
- "/wizard/v1/messages/count_tokens",
+ "/ci/v1/messages/count_tokens",
json=valid_request_body,
headers={"Authorization": "Bearer phx_test_key"},
)
diff --git a/services/llm-gateway/tests/test_bedrock.py b/services/llm-gateway/tests/test_bedrock.py
index 1b39a221cb43..f351daf7c5fa 100644
--- a/services/llm-gateway/tests/test_bedrock.py
+++ b/services/llm-gateway/tests/test_bedrock.py
@@ -666,7 +666,7 @@ class TestBedrockCountTokensViaProvider:
mock_count_tokens.return_value = 42
response = authenticated_client.post(
- "/wizard/v1/messages/count_tokens",
+ "/ci/v1/messages/count_tokens",
json=valid_request_body,
headers=valid_request_headers,
)
diff --git a/services/llm-gateway/tests/test_dependencies.py b/services/llm-gateway/tests/test_dependencies.py
index 527d0403a6c7..192c718b66d8 100644
--- a/services/llm-gateway/tests/test_dependencies.py
+++ b/services/llm-gateway/tests/test_dependencies.py
@@ -27,7 +27,7 @@ from llm_gateway.dependencies import (
get_request_json,
resolve_quota,
)
-from llm_gateway.products.config import POSTHOG_CODE_US_APP_ID, SIGNALS_DEV_APP_ID
+from llm_gateway.products.config import POSTHOG_CODE_US_APP_ID, SIGNALS_DEV_APP_ID, WIZARD_US_APP_ID
from llm_gateway.rate_limiting.cost_throttles import SandboxTaskCostThrottle
from llm_gateway.rate_limiting.throttles import ThrottleContext, ThrottleResult
from llm_gateway.services.desktop_access_resolver import (
@@ -562,7 +562,10 @@ class TestServerCredentialRequirementWiring:
with pytest.raises(HTTPException) as exc_info:
await enforce_product_access(request=request, user=self._oauth_user(["*"]))
assert exc_info.value.status_code == 403
- assert "server-minted" in exc_info.value.detail
+ error = exc_info.value.detail["error"]
+ assert "server-minted" in error["message"]
+ assert error["code"] == "product_access_denied"
+ assert "reason" not in error
finally:
get_settings.cache_clear()
@@ -720,7 +723,7 @@ class TestDesktopAccessGate:
async def test_other_products_untouched(self) -> None:
get_settings.cache_clear()
try:
- request = self._request(False, path="/wizard/v1/messages")
+ request = self._request(False, path="/django/v1/messages")
user = AuthenticatedUser(
user_id=7,
team_id=1,
@@ -816,3 +819,42 @@ class TestSandboxTaskIdPlumbing:
assert bool(cache_key) is expect_ceiling
if expect_ceiling:
assert cache_key == f"cost:task:{expected_id}"
+
+
+class TestRetiredProduct:
+ @pytest.mark.asyncio
+ @pytest.mark.parametrize(
+ "user",
+ [
+ AuthenticatedUser(
+ user_id=7,
+ team_id=1,
+ auth_method="personal_api_key",
+ distinct_id="test-distinct-id-7",
+ scopes=["llm_gateway:read"],
+ ),
+ AuthenticatedUser(
+ user_id=7,
+ team_id=1,
+ auth_method="oauth_access_token",
+ distinct_id="test-distinct-id-7",
+ scopes=["llm_gateway:read"],
+ application_id=WIZARD_US_APP_ID,
+ ),
+ ],
+ ids=["personal_api_key", "wizard_oauth_app"],
+ )
+ async def test_wizard_is_refused_with_the_upgrade_path(self, user: AuthenticatedUser) -> None:
+ get_settings.cache_clear()
+ try:
+ request = _make_request({"model": "claude-sonnet-5", "messages": []}, path="/wizard/v1/messages")
+ with pytest.raises(HTTPException) as exc_info:
+ await enforce_product_access(request=request, user=user)
+ assert exc_info.value.status_code == 403
+ error = exc_info.value.detail["error"]
+ assert error["type"] == "permission_error"
+ assert error["code"] == "product_access_denied"
+ assert error["reason"] == "product_retired"
+ assert "npx @posthog/wizard@latest" in error["message"]
+ finally:
+ get_settings.cache_clear()
diff --git a/services/llm-gateway/tests/test_product_config.py b/services/llm-gateway/tests/test_product_config.py
index 553334fcbffe..e229778e21ff 100644
--- a/services/llm-gateway/tests/test_product_config.py
+++ b/services/llm-gateway/tests/test_product_config.py
@@ -117,11 +117,11 @@ class TestCheckProductAccess:
True,
None,
),
- # wizard allows API keys and OAuth with valid app ID
- ("wizard", "personal_api_key", None, "claude-3-opus", True, None),
- ("wizard", "oauth_access_token", "invalid-app-id", None, False, "not authorized"),
- ("wizard", "oauth_access_token", WIZARD_US_APP_ID, None, True, None),
- ("wizard", "oauth_access_token", WIZARD_EU_APP_ID, None, True, None),
+ # wizard is retired here: every auth method, including its own apps, gets the upgrade path
+ ("wizard", "personal_api_key", None, "claude-3-opus", False, "npx @posthog/wizard@latest"),
+ ("wizard", "oauth_access_token", "invalid-app-id", None, False, "npx @posthog/wizard@latest"),
+ ("wizard", "oauth_access_token", WIZARD_US_APP_ID, None, False, "npx @posthog/wizard@latest"),
+ ("wizard", "oauth_access_token", WIZARD_EU_APP_ID, None, False, "npx @posthog/wizard@latest"),
# django allows API keys with any model; OAuth rejected (no app IDs configured)
("django", "personal_api_key", None, "gpt-4.1-mini", True, None),
("django", "personal_api_key", None, "claude-3-opus", True, None),
@@ -809,3 +809,13 @@ class TestSignalsApplicationIsolation:
# of which it could reach while Signals shared the Desktop app.
allowed, _ = check_product_access(product, "oauth_access_token", SIGNALS_DEV_APP_ID, None)
assert allowed is expected_allowed
+
+
+class TestRetiredProduct:
+ @patch("llm_gateway.products.config.get_settings", return_value=MagicMock(debug=True))
+ def test_a_retired_product_is_refused_in_debug_mode_too(self, _settings):
+ # Debug skips the application-id check, which must not reopen a retired product.
+ allowed, error = check_product_access("wizard", "oauth_access_token", WIZARD_US_APP_ID, None)
+ assert allowed is False
+ assert error is not None
+ assert "npx @posthog/wizard@latest" in error