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.

fix(aio): allow scoped tokens to check cached summaries (#103415)

posthog[bot]025b204ba053
diff --git a/products/ai_observability/backend/api/summarization.py b/products/ai_observability/backend/api/summarization.py
index abd150c008b4..616651c10dd8 100644
--- a/products/ai_observability/backend/api/summarization.py
+++ b/products/ai_observability/backend/api/summarization.py
@@ -742,7 +742,7 @@ with their titles.
""",
tags=["AI observability"],
)
- @action(detail=False, methods=["post"], url_path="batch_check")
+ @action(detail=False, methods=["post"], url_path="batch_check", required_scopes=["llm_analytics:read"])
@llma_track_latency("llma_summarize_batch_check")
@monitor(feature=None, endpoint="llma_summarize_batch_check", method="POST")
def batch_check(self, request: Request, **kwargs) -> Response:
diff --git a/products/ai_observability/backend/api/test/test_summarization.py b/products/ai_observability/backend/api/test/test_summarization.py
index b574e595094a..81aadaab1fa6 100644
--- a/products/ai_observability/backend/api/test/test_summarization.py
+++ b/products/ai_observability/backend/api/test/test_summarization.py
@@ -416,6 +416,30 @@ class TestSummarizationAPI(APIBaseTest):
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertIn("trace_ids", str(response.data).lower())
+ @parameterized.expand(
+ [
+ ("read_scope", "llm_analytics:read", status.HTTP_200_OK),
+ ("write_scope", "llm_analytics:write", status.HTTP_200_OK),
+ ("wrong_scope", "feature_flag:read", status.HTTP_403_FORBIDDEN),
+ ]
+ )
+ def test_batch_check_accepts_a_personal_api_key(self, _name, scope, expected_status):
+ self.organization.is_ai_data_processing_approved = True
+ self.organization.save()
+
+ key_value = self.create_personal_api_key_with_scopes([scope])
+
+ response = self.client.post(
+ f"/api/environments/{self.team.id}/llm_analytics/summarization/batch_check/",
+ {"trace_ids": ["trace1"], "mode": "minimal"},
+ format="json",
+ HTTP_AUTHORIZATION=f"Bearer {key_value}",
+ )
+
+ self.assertEqual(response.status_code, expected_status)
+ if expected_status == status.HTTP_403_FORBIDDEN:
+ self.assertIn("llm_analytics:read", str(response.data["detail"]))
+
def test_summarization_denied_when_ai_consent_not_approved(self):
"""Should return 403 when AI data processing is not approved."""
self.organization.is_ai_data_processing_approved = False