: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): GPT5.6 allowlist and ai lane knob (#75967)
Alex Lebedevf99c73c388e7
diff --git a/.env.example b/.env.exampleindex 320c668fd48a..03e1419cb33a 100644--- a/.env.example+++ b/.env.example@@ -59,3 +59,9 @@ HEATMAP_BROWSERLESS_TOKEN=# BROWSERLESS_TOKEN=# BROWSERLESS_SESSION_TIMEOUT_MS=180000# BROWSERLESS_CONNECT_TIMEOUT_MS=30000++# The llm-gateway's AI-observability capture lane. The local ingestion stack cannot ingest+# AI-lane batches (the forwarder 401s on /batch/ and events are silently dropped), so local+# dev keeps it off and $ai_generation events go through the standard capture lane instead.+# Production leaves this unset (defaults to true).+LLM_GATEWAY_POSTHOG_AI_LANE_CAPTURE=falsediff --git a/services/llm-gateway/src/llm_gateway/callbacks/__init__.py b/services/llm-gateway/src/llm_gateway/callbacks/__init__.pyindex 679415e2db7f..c472d96e6d31 100644--- a/services/llm-gateway/src/llm_gateway/callbacks/__init__.py+++ b/services/llm-gateway/src/llm_gateway/callbacks/__init__.py@@ -20,6 +20,7 @@ def init_callbacks() -> None:region_url=settings.posthog_api_base_url,secondary_api_key=settings.posthog_secondary_project_token,secondary_host=settings.posthog_secondary_host,+ ai_lane_capture=settings.posthog_ai_lane_capture,))diff --git a/services/llm-gateway/src/llm_gateway/callbacks/posthog.py b/services/llm-gateway/src/llm_gateway/callbacks/posthog.pyindex c64578991d46..c0efa7a015d8 100644--- a/services/llm-gateway/src/llm_gateway/callbacks/posthog.py+++ b/services/llm-gateway/src/llm_gateway/callbacks/posthog.py@@ -163,10 +163,12 @@ class PostHogCallback(InstrumentedCallback):region_url: str = "https://us.posthog.com",secondary_api_key: str | None = None,secondary_host: str | None = None,+ ai_lane_capture: bool = True,):super().__init__()self._api_key = api_keyself._host = host+ self._ai_lane_capture = ai_lane_capture# Customer-origin region URL stamped on every captured event via the# `instance` group. The PHAI usage report filters on $group_<N> where# N is the destination project's `instance` group_type_index, so the@@ -420,8 +422,9 @@ class PostHogCallback(InstrumentedCallback):host=host,sync_mode=True,enable_local_evaluation=False,- _use_ai_lane=True,- _enable_multimodal_capture=True,+ # Multimodal capture implies the AI lane, so one setting governs both.+ _use_ai_lane=self._ai_lane_capture,+ _enable_multimodal_capture=self._ai_lane_capture,)try:_capture_ai_event(client, **capture_kwargs)diff --git a/services/llm-gateway/src/llm_gateway/config.py b/services/llm-gateway/src/llm_gateway/config.pyindex d4e3e2ed28bb..f6ec1fd272f7 100644--- a/services/llm-gateway/src/llm_gateway/config.py+++ b/services/llm-gateway/src/llm_gateway/config.py@@ -188,6 +188,10 @@ class Settings(BaseSettings):posthog_secondary_project_token: str | None = Noneposthog_secondary_host: str | None = None+ # Set false on local dev stacks whose ingestion-ai forwarder rejects AI-lane batches+ # (401 on /batch/, events silently dropped) — capture falls back to the standard lane.+ posthog_ai_lane_capture: bool = True+metrics_enabled: bool = True# ~600 bytes per entry (key + AuthenticatedUser + LRU overhead), 10000 entries ≈ 6 MBdiff --git a/services/llm-gateway/src/llm_gateway/products/config.py b/services/llm-gateway/src/llm_gateway/products/config.pyindex a45a10485682..f086b9541074 100644--- a/services/llm-gateway/src/llm_gateway/products/config.py+++ b/services/llm-gateway/src/llm_gateway/products/config.py@@ -245,7 +245,21 @@ PRODUCTS: Final[dict[str, ProductConfig]] = {),"review_hog": ProductConfig(allowed_application_ids=None,- allowed_models=None, # any model — the one-shot chunking/dedup calls pin theirs in review_hog constants+ # The models the review pipeline pins: sonnet-5 (perspectives + one-shots), opus-4-8+ # (validation), opus-5 (outcome judge), gpt-5.5 / gpt-5.6 sol+luna+terra (Codex reviewers),+ # GLM 5.2 (evaluated as reviewer).+ allowed_models=frozenset(+ {+ "@cf/zai-org/glm-5.2",+ "claude-sonnet-5",+ "claude-opus-4-8",+ "claude-opus-5",+ "gpt-5.5",+ "gpt-5.6-sol",+ "gpt-5.6-luna",+ "gpt-5.6-terra",+ }+ ),allow_api_keys=True,# Deliberately unbilled while ReviewHog is an internal alpha.credit_bucket=None,diff --git a/services/llm-gateway/tests/callbacks/test_init.py b/services/llm-gateway/tests/callbacks/test_init.pynew file mode 100644index 000000000000..6c68ac779f30--- /dev/null+++ b/services/llm-gateway/tests/callbacks/test_init.py@@ -0,0 +1,23 @@+from unittest.mock import patch++import litellm++from llm_gateway.callbacks import init_callbacks+from llm_gateway.callbacks.posthog import PostHogCallback+from llm_gateway.config import Settings+++def test_init_callbacks_forwards_the_ai_lane_setting() -> None:+ # The env knob is only as real as this wiring: if init_callbacks stops forwarding+ # posthog_ai_lane_capture, the callback silently falls back to its default (True) and the+ # setting goes dead. False is asserted because it is the only value that can catch that.+ settings = Settings(posthog_project_token="test-token", posthog_ai_lane_capture=False)+ original_callbacks = litellm.callbacks+ try:+ with patch("llm_gateway.callbacks.get_settings", return_value=settings):+ init_callbacks()+ posthog_callbacks = [cb for cb in litellm.callbacks if isinstance(cb, PostHogCallback)]+ assert len(posthog_callbacks) == 1+ assert posthog_callbacks[0]._ai_lane_capture is False+ finally:+ litellm.callbacks = original_callbacksdiff --git a/services/llm-gateway/tests/callbacks/test_posthog.py b/services/llm-gateway/tests/callbacks/test_posthog.pyindex 3dc2c69a6bf8..5b644a93d6c4 100644--- a/services/llm-gateway/tests/callbacks/test_posthog.py+++ b/services/llm-gateway/tests/callbacks/test_posthog.py@@ -115,6 +115,28 @@ class TestPostHogCallback:assert props["ai_product"] == "wizard"mock_client.shutdown.assert_called_once()+ @pytest.mark.asyncio+ async def test_ai_lane_capture_off_builds_standard_lane_client(+ self,+ auth_user: AuthenticatedUser,+ standard_logging_object: dict,+ mock_posthog_client: tuple,+ ) -> None:+ # The local-dev knob: with ai_lane_capture=False the client must drop to the standard+ # capture lane (and with it multimodal capture), or local stacks keep losing every event.+ mock_cls, _ = mock_posthog_client+ callback = PostHogCallback(api_key="test-key", host="https://test.posthog.com", ai_lane_capture=False)+ kwargs = {"standard_logging_object": standard_logging_object, "litellm_params": {}}++ with (+ patch("llm_gateway.callbacks.posthog.get_auth_user", return_value=auth_user),+ patch("llm_gateway.callbacks.posthog.get_product", return_value="wizard"),+ ):+ await callback._on_success(kwargs, None, 0.0, 1.0, end_user_id=None)++ assert mock_cls.call_args.kwargs["_use_ai_lane"] is False+ assert mock_cls.call_args.kwargs["_enable_multimodal_capture"] is False+@pytest.mark.parametrize("event_method, effort, caller_effort, expected",[diff --git a/services/llm-gateway/tests/test_product_config.py b/services/llm-gateway/tests/test_product_config.pyindex c85b355299fa..8a7b65dbbcaf 100644--- a/services/llm-gateway/tests/test_product_config.py+++ b/services/llm-gateway/tests/test_product_config.py@@ -111,6 +111,12 @@ class TestCheckProductAccess:("changelog_bot", "personal_api_key", None, "openai/gpt-5.6-terra-pro", False, "not allowed"),("changelog_bot", "personal_api_key", None, "openai/gpt-5.6-sol-pro", False, "not allowed"),("changelog_bot", "oauth_access_token", "any-app-id", "openai/gpt-5.6-terra", False, "not authorized"),+ # review_hog: shared-key auth, models pinned to the review pipeline's constants —+ # the opus-5 outcome judge and the experiment's Codex arm must stay allowed, and+ # anything off the pin list is rejected.+ ("review_hog", "personal_api_key", None, "claude-opus-5", True, None),+ ("review_hog", "personal_api_key", None, "gpt-5.6-sol", True, None),+ ("review_hog", "personal_api_key", None, "claude-3-opus", False, "not allowed"),# unknown product("unknown", "personal_api_key", None, None, False, "Unknown product"),],