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): report code_usage_subscribed on the usage endpoint (#71315)

Adam Bowkerb4361ad979d6
diff --git a/services/llm-gateway/src/llm_gateway/api/usage.py b/services/llm-gateway/src/llm_gateway/api/usage.py
index 0c5cb31ddb82..e98598a7b7ba 100644
--- a/services/llm-gateway/src/llm_gateway/api/usage.py
+++ b/services/llm-gateway/src/llm_gateway/api/usage.py
@@ -47,6 +47,7 @@ class UsageResponse(BaseModel):
ai_credits: AiCreditsStatus
is_rate_limited: bool
is_pro: bool
+ code_usage_subscribed: bool = False
billing_period_end: datetime | None = None
@@ -141,6 +142,7 @@ async def get_usage(
ai_credits=AiCreditsStatus(exhausted=credits_exhausted),
is_rate_limited=burst_status.exceeded or sustained_status.exceeded or credits_exhausted,
is_pro=is_pro_plan(plan_info.plan_key),
+ code_usage_subscribed=quota_status.code_usage_billing_active,
billing_period_end=billing_period_end,
)
diff --git a/services/llm-gateway/tests/test_usage.py b/services/llm-gateway/tests/test_usage.py
index 2e91f8cbe9b2..6f3410571585 100644
--- a/services/llm-gateway/tests/test_usage.py
+++ b/services/llm-gateway/tests/test_usage.py
@@ -424,6 +424,26 @@ class TestUsageEndpoint:
assert data["is_rate_limited"] is True
assert resolver_mock.call_args.args[0] == "ai_credits"
+ @pytest.mark.parametrize("billing_active", [True, False])
+ def test_code_usage_subscribed_reflects_billing_bit(
+ self, authenticated_usage_client: TestClient, billing_active: bool
+ ) -> None:
+ """Clients pick billing copy and hide the free-tier meter off this
+ field, so it must carry the same bit enforcement reads."""
+ from llm_gateway.services.quota_resolver import QuotaResourceStatus
+
+ app = authenticated_usage_client.app
+ app.state.quota_resolver.get_resource_status = AsyncMock(
+ return_value=QuotaResourceStatus(limited=False, code_usage_billing_active=billing_active)
+ )
+
+ response = authenticated_usage_client.get(
+ "/v1/usage/posthog_code",
+ headers={"Authorization": "Bearer phx_test"},
+ )
+ assert response.status_code == 200
+ assert response.json()["code_usage_subscribed"] is billing_active
+
def test_invalidate_plan_cache_calls_resolver(self, authenticated_usage_client: TestClient) -> None:
app = authenticated_usage_client.app
app.state.plan_resolver.invalidate = AsyncMock()