: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
from typing import Any
from rest_framework.request import Request
from rest_framework.throttling import UserRateThrottle
from posthog.rate_limit import PersonalApiKeyOrUserRateThrottle
class ReportMetricRefreshThrottle(PersonalApiKeyOrUserRateThrottle):
scope = "report_metric_refresh"
rate = "10/minute"
def get_cache_key(self, request: Request, view: Any) -> str | None:
team_id = self.safely_get_team_id_from_view(view)
if team_id is not None:
return self.cache_format % {"scope": self.scope, "ident": f"team_{team_id}"}
return super().get_cache_key(request, view)
class ReportTaskActionRunBurstThrottle(UserRateThrottle):
# Scope and rate match the tasks create throttle for report tasks, so a run started from the
# API spends the same per-user budget as one started from the inbox.
scope = "signal_report_task_create_burst"
rate = "20/hour"
class ReportTaskActionRunSustainedThrottle(UserRateThrottle):
scope = "signal_report_task_create_day"
rate = "50/day"
class UserReportCreateBurstThrottle(UserRateThrottle):
# The daily cap counts stored reports, and a report is stored only after the safety judge returns.
# This rate limits how far parallel creates can pass the cap during that wait.
scope = "signal_report_user_create_burst"
rate = "10/minute"