: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
feat(gateway): project per-team overspend allowance to credential blob (#63840)
Richard Solomou3583334e7a2f
diff --git a/posthog/admin/admins/team_admin.py b/posthog/admin/admins/team_admin.pyindex 4aa86e323837..101e9eae34db 100644--- a/posthog/admin/admins/team_admin.py+++ b/posthog/admin/admins/team_admin.py@@ -37,6 +37,7 @@ from posthog.models.activity_logging.activity_log import ActivityContextBase, Defrom posthog.models.remote_config import RemoteConfigfrom posthog.models.team.team import DEPRECATED_ATTRSfrom posthog.session_recordings.recordings import recording_s3_client+from posthog.storage.gateway_credential_cache import validate_overspend_allowance_usdfrom posthog.temporal.common.client import sync_connectfrom posthog.temporal.common.search_attributes import POSTHOG_TEAM_ID_KEYfrom posthog.temporal.session_replay.delete_recordings.object_storage import store_session_id_chunks@@ -74,6 +75,22 @@ class TeamAdminForm(ModelForm):raise ValidationError("test_account_filters must be a JSON list (e.g. `[]`).")return value+ def clean_llm_gateway_overspend_allowance_usd(self):+ value = self.cleaned_data.get("llm_gateway_overspend_allowance_usd")+ if value is None:+ return value+ # The projection reads the allowance from the project-root team, so a child-env value+ # never reaches the wire — reject instead of silently no-opping.+ if self.instance.parent_team_id is not None:+ raise ValidationError(+ f"This is a child environment; set the allowance on its project-root team "+ f"({self.instance.parent_team_id}) instead."+ )+ try:+ return validate_overspend_allowance_usd(value)+ except ValueError as e:+ raise ValidationError(str(e))+@admin.register(Team)class TeamAdmin(admin.ModelAdmin):@@ -242,6 +259,7 @@ class TeamAdmin(admin.ModelAdmin):"fields": ["llm_gateway_enabled_at","llm_gateway_revoked_at",+ "llm_gateway_overspend_allowance_usd","admit_state","ai_gateway_actions","policy_cache_blob",@@ -251,7 +269,9 @@ class TeamAdmin(admin.ModelAdmin):"If you want the team enabled or revoked in the other region too, flip the ""matching Team row there. The gateway admits a team only when ""<code>llm_gateway_enabled_at</code> is set and "- "<code>llm_gateway_revoked_at</code> is null."+ "<code>llm_gateway_revoked_at</code> is null. "+ "<code>llm_gateway_overspend_allowance_usd</code> (0–10000) lets the team keep dispatching "+ "past $0 down to that USD floor; leave blank to use the gateway's operator default."),},),diff --git a/posthog/admin/test_team_admin.py b/posthog/admin/test_team_admin.pyindex 9d59d03611b5..fb032c628740 100644--- a/posthog/admin/test_team_admin.py+++ b/posthog/admin/test_team_admin.py@@ -1,4 +1,5 @@from datetime import timedelta+from decimal import Decimalfrom freezegun import freeze_timefrom posthog.test.base import BaseTest@@ -309,3 +310,34 @@ class TestTeamAdminLLMGateway(BaseTest):rendered = str(self.admin.policy_cache_blob(self.team))assert "<script>" not in renderedassert "<script>" in rendered+++class TestTeamAdminFormOverspendAllowance(BaseTest):+ def _form(self, value, instance=None):+ instance = instance or self.team+ request = RequestFactory().get("/")+ request.user = self.user+ form_class = TeamAdmin(Team, AdminSite()).get_form(request, instance)+ form = form_class(instance=instance)+ form.cleaned_data = {"llm_gateway_overspend_allowance_usd": value}+ return form++ @parameterized.expand([("whole", Decimal("5"), Decimal("5.000000")), ("none_passthrough", None, None)])+ def test_clean_accepts_valid(self, _name, value, expected) -> None:+ self.assertEqual(self._form(value).clean_llm_gateway_overspend_allowance_usd(), expected)++ @parameterized.expand(+ [("negative", Decimal("-1")), ("over_max", Decimal("10001")), ("too_precise", Decimal("1.0000001"))]+ )+ def test_clean_rejects_invalid(self, _name, value) -> None:+ from django.forms import ValidationError++ with self.assertRaises(ValidationError):+ self._form(value).clean_llm_gateway_overspend_allowance_usd()++ def test_clean_rejects_child_environment(self) -> None:+ from django.forms import ValidationError++ child = Team.objects.create(organization=self.organization, name="child env", parent_team=self.team)+ with self.assertRaises(ValidationError):+ self._form(Decimal("5"), instance=child).clean_llm_gateway_overspend_allowance_usd()diff --git a/posthog/api/test/__snapshots__/test_element.ambr b/posthog/api/test/__snapshots__/test_element.ambrindex 2ef99b2edfe6..6c224d6c4d07 100644--- a/posthog/api/test/__snapshots__/test_element.ambr+++ b/posthog/api/test/__snapshots__/test_element.ambr@@ -139,6 +139,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",diff --git a/posthog/api/test/__snapshots__/test_preflight.ambr b/posthog/api/test/__snapshots__/test_preflight.ambrindex abdb4cd65f7f..e27d9de9ebdc 100644--- a/posthog/api/test/__snapshots__/test_preflight.ambr+++ b/posthog/api/test/__snapshots__/test_preflight.ambr@@ -139,6 +139,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",diff --git a/posthog/api/test/dashboards/__snapshots__/test_dashboard.ambr b/posthog/api/test/dashboards/__snapshots__/test_dashboard.ambrindex 51755bf586a4..49d0d7c028bf 100644--- a/posthog/api/test/dashboards/__snapshots__/test_dashboard.ambr+++ b/posthog/api/test/dashboards/__snapshots__/test_dashboard.ambr@@ -171,6 +171,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -304,6 +305,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -441,6 +443,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -549,6 +552,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -687,6 +691,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -848,6 +853,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -1013,6 +1019,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -1121,6 +1128,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -1329,6 +1337,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -1656,6 +1665,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -2103,6 +2113,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -2561,6 +2572,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -2828,6 +2840,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -3359,6 +3372,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -3914,6 +3928,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -4051,6 +4066,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -4159,6 +4175,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -4297,6 +4314,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -4486,6 +4504,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -4594,6 +4613,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -4731,6 +4751,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -4911,6 +4932,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -5082,6 +5104,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -5409,6 +5432,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -6120,6 +6144,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -6340,6 +6365,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -6520,6 +6546,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -6691,6 +6718,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -6978,6 +7006,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -7352,6 +7381,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -7485,6 +7515,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -7622,6 +7653,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -7730,6 +7762,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -7868,6 +7901,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -8076,6 +8110,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -8184,6 +8219,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -8364,6 +8400,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -8535,6 +8572,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -8818,6 +8856,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -9199,6 +9238,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -9332,6 +9372,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -9469,6 +9510,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -9577,6 +9619,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -9715,6 +9758,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -9920,6 +9964,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -10028,6 +10073,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -10208,6 +10254,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -10425,6 +10472,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -10731,6 +10779,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -11007,6 +11056,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -11440,6 +11490,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -11943,6 +11994,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -12161,6 +12213,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -12620,6 +12673,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -12871,6 +12925,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -13409,6 +13464,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -14001,6 +14057,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -14315,6 +14372,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -14738,6 +14796,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -15199,6 +15258,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -15332,6 +15392,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -15469,6 +15530,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -15577,6 +15639,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -15715,6 +15778,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -15917,6 +15981,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -16025,6 +16090,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -16163,6 +16229,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -16352,6 +16419,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -16460,6 +16528,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -16648,6 +16717,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -16819,6 +16889,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -17111,6 +17182,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -17473,6 +17545,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -17581,6 +17654,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -17714,6 +17788,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -17851,6 +17926,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -17959,6 +18035,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -18097,6 +18174,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -18286,6 +18364,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -18575,6 +18654,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -18912,6 +18992,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -19130,6 +19211,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -19887,6 +19969,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -20409,6 +20492,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -20768,6 +20852,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -20947,6 +21032,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -21243,6 +21329,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -21557,6 +21644,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -21980,6 +22068,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -22650,6 +22739,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",diff --git a/posthog/api/test/notebooks/__snapshots__/test_notebook.ambr b/posthog/api/test/notebooks/__snapshots__/test_notebook.ambrindex 04c56646b4bd..f7adb8ff4553 100644--- a/posthog/api/test/notebooks/__snapshots__/test_notebook.ambr+++ b/posthog/api/test/notebooks/__snapshots__/test_notebook.ambr@@ -181,6 +181,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -470,6 +471,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -708,6 +710,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -816,6 +819,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -1217,6 +1221,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",diff --git a/posthog/management/commands/llm_gateway_team.py b/posthog/management/commands/llm_gateway_team.pyindex 89ebe7533fb2..197340dc9900 100644--- a/posthog/management/commands/llm_gateway_team.py+++ b/posthog/management/commands/llm_gateway_team.py@@ -7,20 +7,26 @@ Usage:python manage.py llm_gateway_team unenable 42python manage.py llm_gateway_team revoke 42python manage.py llm_gateway_team unrevoke 42+ python manage.py llm_gateway_team set-allowance 42 5+ python manage.py llm_gateway_team clear-allowance 42python manage.py llm_gateway_team refresh 42python manage.py llm_gateway_team status 42-Both fields live on Team and project into the dedicated llm_gateway_policy-hypercache blob via Team.save() signal handlers. The gateway admits a team-only when enabled_at is set and revoked_at is null.+The admission fields and llm_gateway_overspend_allowance_usd live on Team.+enabled_at/revoked_at project into the dedicated llm_gateway_policy blob;+llm_gateway_overspend_allowance_usd projects into each credential's gateway_credential+blob (under the wire key overspend_allowance_usd). Both flow through Team.save() signal+handlers. The gateway admits a team only when enabled_at is set and revoked_at is null."""+from decimal import Decimal, InvalidOperationfrom typing import Anyfrom django.core.management.base import BaseCommand, CommandErrorfrom django.utils import timezonefrom posthog.models.team.team import Team+from posthog.storage.gateway_credential_cache import validate_overspend_allowance_usdfrom posthog.storage.team_llm_gateway_policy_cache import update_team_llm_gateway_policy_cache_VERBS = (@@ -28,6 +34,8 @@ _VERBS = (("unenable", "clear llm_gateway_enabled_at (no-op if already null)"),("revoke", "set llm_gateway_revoked_at to now (idempotent: no-op if already set)"),("unrevoke", "clear llm_gateway_revoked_at (no-op if already null)"),+ ("set-allowance", "set llm_gateway_overspend_allowance_usd (USD, 0–10000, max 6 dp)"),+ ("clear-allowance", "clear llm_gateway_overspend_allowance_usd (unset → gateway falls back to its default)"),("refresh", "rewrite the team's policy cache entry from current DB state (no field change)"),("status", "print the team's current admission state"),)@@ -41,6 +49,8 @@ class Command(BaseCommand):for verb, desc in _VERBS:p = sub.add_parser(verb, help=desc)p.add_argument("team", help="team id (integer) or api_token")+ if verb == "set-allowance":+ p.add_argument("usd", help="allowance in USD, e.g. 5 or 5.000000 (0–10000, max 6 dp)")def handle(self, *args: Any, **opts: Any) -> None:team = _resolve_team(opts["team"])@@ -54,8 +64,17 @@ class Command(BaseCommand):self.stdout.write(f" {_snapshot(team)}")return+ if action == "set-allowance":+ canonical_id = team.parent_team_id or team.id+ if canonical_id != team.id:+ raise CommandError(+ f"team {team.id} is a child environment; set the allowance on its project-root "+ f"team {canonical_id} — the gateway projection reads it from there, not the child"+ )+ allowance = _parse_allowance(opts["usd"]) if action == "set-allowance" else None+before = _snapshot(team)- changed = _apply(team, action)+ changed = _apply(team, action, allowance)if not changed:self.stdout.write(f"team {team.id} ({team.api_token}): {action} no-op ({before})")return@@ -83,7 +102,16 @@ def _resolve_team(arg: str) -> Team:raise CommandError(f"no team with id={team_id}")-def _apply(team: Team, action: str) -> bool:+def _parse_allowance(raw: str) -> Decimal:+ try:+ return validate_overspend_allowance_usd(Decimal(raw))+ except InvalidOperation:+ raise CommandError(f"invalid allowance {raw!r}: not a number")+ except ValueError as e:+ raise CommandError(f"invalid allowance {raw!r}: {e}")+++def _apply(team: Team, action: str, allowance: Decimal | None) -> bool:"""Mutate team in-place; return True if a save is required."""now = timezone.now()if action == "enable":@@ -106,11 +134,24 @@ def _apply(team: Team, action: str) -> bool:return Falseteam.llm_gateway_revoked_at = Nonereturn True+ if action == "set-allowance":+ if team.llm_gateway_overspend_allowance_usd == allowance:+ return False+ team.llm_gateway_overspend_allowance_usd = allowance+ return True+ if action == "clear-allowance":+ if team.llm_gateway_overspend_allowance_usd is None:+ return False+ team.llm_gateway_overspend_allowance_usd = None+ return Trueraise CommandError(f"unknown action {action!r}")def _snapshot(team: Team) -> str:- return f"enabled_at={team.llm_gateway_enabled_at} revoked_at={team.llm_gateway_revoked_at}"+ return (+ f"enabled_at={team.llm_gateway_enabled_at} revoked_at={team.llm_gateway_revoked_at} "+ f"overspend_allowance_usd={team.llm_gateway_overspend_allowance_usd}"+ )def _print_status(stdout: Any, team: Team) -> None:@@ -119,3 +160,4 @@ def _print_status(stdout: Any, team: Team) -> None:stdout.write(f"team {team.id} ({team.api_token}) state={state}")stdout.write(f" enabled_at: {team.llm_gateway_enabled_at}")stdout.write(f" revoked_at: {team.llm_gateway_revoked_at}")+ stdout.write(f" overspend_allowance_usd: {team.llm_gateway_overspend_allowance_usd}")diff --git a/posthog/management/commands/test/test_llm_gateway_team.py b/posthog/management/commands/test/test_llm_gateway_team.pyindex 8afa48ddc80d..868432373c4e 100644--- a/posthog/management/commands/test/test_llm_gateway_team.py+++ b/posthog/management/commands/test/test_llm_gateway_team.py@@ -1,4 +1,5 @@from datetime import UTC, datetime+from decimal import Decimalfrom io import StringIOfrom posthog.test.base import BaseTest@@ -9,6 +10,8 @@ from django.core.management.base import CommandErrorfrom parameterized import parameterized+from posthog.models.team.team import Team+class TestLLMGatewayTeamCommand(BaseTest):def _run(self, *args: str) -> str:@@ -102,6 +105,46 @@ class TestLLMGatewayTeamCommand(BaseTest):with self.assertRaises(CommandError):self._run("enable", arg)+ @parameterized.expand([("integer", "5", "5.000000"), ("fractional", "0.5", "0.500000"), ("zero", "0", "0.000000")])+ def test_set_allowance_stores_quantized_value(self, _name: str, arg: str, expected: str) -> None:+ out = self._run("set-allowance", str(self.team.id), arg)+ self.team.refresh_from_db()+ self.assertEqual(self.team.llm_gateway_overspend_allowance_usd, Decimal(expected))+ self.assertIn("set-allowance ok", out)++ def test_set_allowance_idempotent(self) -> None:+ self.team.llm_gateway_overspend_allowance_usd = Decimal("5.000000")+ self.team.save()+ out = self._run("set-allowance", str(self.team.id), "5")+ self.assertIn("no-op", out)++ def test_clear_allowance_unsets_value(self) -> None:+ self.team.llm_gateway_overspend_allowance_usd = Decimal("5.000000")+ self.team.save()+ out = self._run("clear-allowance", str(self.team.id))+ self.team.refresh_from_db()+ self.assertIsNone(self.team.llm_gateway_overspend_allowance_usd)+ self.assertIn("clear-allowance ok", out)++ def test_clear_allowance_on_unset_is_noop(self) -> None:+ out = self._run("clear-allowance", str(self.team.id))+ self.assertIn("no-op", out)++ @parameterized.expand([("negative", "-1"), ("too_large", "10001"), ("too_precise", "1.0000001"), ("nan", "nan")])+ def test_set_allowance_rejects_invalid(self, _name: str, arg: str) -> None:+ with self.assertRaises(CommandError):+ self._run("set-allowance", str(self.team.id), arg)+ self.team.refresh_from_db()+ self.assertIsNone(self.team.llm_gateway_overspend_allowance_usd)++ def test_set_allowance_rejects_child_environment(self) -> None:+ # Child-env value never reaches the wire (projection reads the root team), so reject.+ child = Team.objects.create(organization=self.organization, name="child env", parent_team=self.team)+ with self.assertRaises(CommandError):+ self._run("set-allowance", str(child.id), "5")+ child.refresh_from_db()+ self.assertIsNone(child.llm_gateway_overspend_allowance_usd)+def test_refresh_rewrites_cache_without_field_change(self) -> None:# refresh exists so an operator can re-warm a drifted cache without# toggling enabled_at/revoked_at (which enable/revoke would no-op on).diff --git a/posthog/migrations/1225_team_llm_gateway_overspend_allowance_usd.py b/posthog/migrations/1225_team_llm_gateway_overspend_allowance_usd.pynew file mode 100644index 000000000000..56f14a0223b0--- /dev/null+++ b/posthog/migrations/1225_team_llm_gateway_overspend_allowance_usd.py@@ -0,0 +1,26 @@+from django.db import migrations, models+++class Migration(migrations.Migration):+ dependencies = [("posthog", "1224_columnconfiguration_properties")]++ operations = [+ migrations.AddField(+ model_name="team",+ name="llm_gateway_overspend_allowance_usd",+ field=models.DecimalField(blank=True, decimal_places=6, max_digits=20, null=True),+ ),+ # Plain AddConstraint (not NOT-VALID) is safe here: the column is brand-new and all-NULL,+ # so validation scans nothing that fails and the lock is brief.+ migrations.AddConstraint(+ model_name="team",+ constraint=models.CheckConstraint(+ name="llm_gateway_overspend_allowance_usd_in_range",+ condition=models.Q(llm_gateway_overspend_allowance_usd__isnull=True)+ | models.Q(+ llm_gateway_overspend_allowance_usd__gte=0,+ llm_gateway_overspend_allowance_usd__lte=10000,+ ),+ ),+ ),+ ]diff --git a/posthog/migrations/max_migration.txt b/posthog/migrations/max_migration.txtindex fc48247429b1..272a07911099 100644--- a/posthog/migrations/max_migration.txt+++ b/posthog/migrations/max_migration.txt@@ -1 +1 @@-1224_columnconfiguration_properties+1225_team_llm_gateway_overspend_allowance_usddiff --git a/posthog/models/team/team.py b/posthog/models/team/team.pyindex 75c04adb0a3b..d30722ab9318 100644--- a/posthog/models/team/team.py+++ b/posthog/models/team/team.py@@ -268,7 +268,17 @@ class Team(UUIDTClassicModel):# be done without locking the table. By adding this constraint using Postgres's `NOT VALID` option# (via Django `AddConstraintNotValid()`) and subsequent `VALIDATE CONSTRAINT`, we avoid locking.condition=models.Q(project_id__isnull=False),- )+ ),+ models.CheckConstraint(+ name="llm_gateway_overspend_allowance_usd_in_range",+ # Mirrors OVERSPEND_ALLOWANCE_MIN/MAX_USD; null = unset stays valid. The Python+ # write surfaces validate too, but update/bulk_update/shell/raw bypass them.+ condition=models.Q(llm_gateway_overspend_allowance_usd__isnull=True)+ | models.Q(+ llm_gateway_overspend_allowance_usd__gte=0,+ llm_gateway_overspend_allowance_usd__lte=10000,+ ),+ ),]objects: TeamManager = TeamManager()@@ -445,6 +455,10 @@ class Team(UUIDTClassicModel):# null revoked_at = not revoked. Set by internal tooling/admin only.llm_gateway_enabled_at = models.DateTimeField(null=True, blank=True)llm_gateway_revoked_at = models.DateTimeField(null=True, blank=True)+ # Per-team USD floor the gateway lets a team dispatch past $0 down to. Projected into+ # gateway_credential.json as the `overspend_allowance_usd` wire key. Null = use the+ # gateway default; 0 = no allowance. Range [0, 10000] validated at the write surfaces.+ llm_gateway_overspend_allowance_usd = models.DecimalField(max_digits=20, decimal_places=6, null=True, blank=True)# Heatmapsheatmaps_opt_in = field_access_control(models.BooleanField(null=True, blank=True), "project", "admin")diff --git a/posthog/session_recordings/test/__snapshots__/test_session_recording_playlist.ambr b/posthog/session_recordings/test/__snapshots__/test_session_recording_playlist.ambrindex 66e8af71783b..e8663435b540 100644--- a/posthog/session_recordings/test/__snapshots__/test_session_recording_playlist.ambr+++ b/posthog/session_recordings/test/__snapshots__/test_session_recording_playlist.ambr@@ -118,6 +118,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -433,6 +434,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -746,6 +748,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -1170,6 +1173,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -1456,6 +1460,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -1843,6 +1848,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",diff --git a/posthog/session_recordings/test/__snapshots__/test_session_recordings.ambr b/posthog/session_recordings/test/__snapshots__/test_session_recordings.ambrindex a129e22a0ffa..3d47937b24c9 100644--- a/posthog/session_recordings/test/__snapshots__/test_session_recordings.ambr+++ b/posthog/session_recordings/test/__snapshots__/test_session_recordings.ambr@@ -198,6 +198,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -406,6 +407,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -958,6 +960,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -1162,6 +1165,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -1714,6 +1718,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -1914,6 +1919,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -2466,6 +2472,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -2666,6 +2673,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -3218,6 +3226,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -3422,6 +3431,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -3974,6 +3984,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -4178,6 +4189,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -4730,6 +4742,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -4934,6 +4947,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -5540,6 +5554,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -5847,6 +5862,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -5985,6 +6001,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -6437,6 +6454,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -6793,6 +6811,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -7287,6 +7306,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -7515,6 +7535,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -7739,6 +7760,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -8242,6 +8264,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -8561,6 +8584,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -9035,6 +9059,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -9428,6 +9453,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -9650,6 +9676,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -9988,6 +10015,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -10440,6 +10468,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -10753,6 +10782,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -11254,6 +11284,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -11607,6 +11638,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -12109,6 +12141,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -12408,6 +12441,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -12894,6 +12928,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -13228,6 +13263,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",diff --git a/posthog/storage/gateway_credential_cache.py b/posthog/storage/gateway_credential_cache.pyindex 7f369f9578c9..74b72e536736 100644--- a/posthog/storage/gateway_credential_cache.py+++ b/posthog/storage/gateway_credential_cache.py@@ -5,7 +5,7 @@ One blob per phs_ project secret key / pha_ OAuth token, keyed by the credentialso the secret never sits in a Redis key. Public phc_ project tokens can't dispatch.Key: cache/team_tokens_hashed/<sha256$hex>/team_metadata/gateway_credential.json- Body: {team_id, project_token, scopes, billing_mode, revoked_at}+ Body: {team_id, project_token, scopes, billing_mode, revoked_at, overspend_allowance_usd?}The hash matches Django's hash_key_value(token, mode="sha256") = "sha256$"+hex, which thegateway derives identically. A credential holding llm_gateway:read attributes to its team@@ -19,6 +19,7 @@ cold Redis.import osfrom collections.abc import Callable+from decimal import Decimalfrom typing import Anyfrom django.conf import settings@@ -65,6 +66,36 @@ GATEWAY_CREDENTIAL_FIELDS = ["revoked_at",]+# Overspend allowance wire contract (gateway-defined, internal/auth/gateway_credential.go):+# fixed-point USD string, 6dp, present only when set. Out-of-range/malformed clamps to 0 there,+# so we validate at the write surfaces instead of relying on the clamp.+OVERSPEND_ALLOWANCE_KEY = "overspend_allowance_usd"+OVERSPEND_ALLOWANCE_QUANTUM = Decimal("0.000001")+OVERSPEND_ALLOWANCE_MIN_USD = Decimal(0)+OVERSPEND_ALLOWANCE_MAX_USD = Decimal(10000)+++def format_overspend_allowance_usd(value: Decimal) -> str:+ """Fixed-point 6dp string for the wire. `:f` avoids scientific notation, which the+ gateway's decimal parser can't read."""+ return f"{value.quantize(OVERSPEND_ALLOWANCE_QUANTUM):f}"+++def validate_overspend_allowance_usd(value: Decimal) -> Decimal:+ """Quantize to 6dp; raise ValueError outside [0, 10000] or beyond 6dp. Callers map to+ their own error type."""+ if not value.is_finite():+ raise ValueError("overspend allowance must be a finite number")+ if value < OVERSPEND_ALLOWANCE_MIN_USD or value > OVERSPEND_ALLOWANCE_MAX_USD:+ raise ValueError(+ f"overspend allowance must be between {OVERSPEND_ALLOWANCE_MIN_USD} and {OVERSPEND_ALLOWANCE_MAX_USD} USD"+ )+ exponent = value.as_tuple().exponent # int for any finite Decimal+ if isinstance(exponent, int) and -exponent > 6:+ raise ValueError("overspend allowance supports at most 6 decimal places")+ return value.quantize(OVERSPEND_ALLOWANCE_QUANTUM)++Credential = ProjectSecretAPIKey | OAuthAccessToken@@ -243,7 +274,7 @@ def _policy_for_credential(if isinstance(credential, OAuthAccessToken) and not _oauth_authorization_ok(credential, team, team.id, memo):return HyperCacheStoreMissing()- return {+ policy: dict[str, Any] = {"team_id": team.id,"project_token": project_token,"scopes": [GATEWAY_CREDENTIAL_REQUIRED_SCOPE],@@ -251,6 +282,13 @@ def _policy_for_credential("revoked_at": None,}+ # Omit when null so the gateway uses its default; an explicit 0 disables the allowance.+ allowance = team.llm_gateway_overspend_allowance_usd+ if allowance is not None:+ policy[OVERSPEND_ALLOWANCE_KEY] = format_overspend_allowance_usd(allowance)++ return policy+def _resolve_credential(hash_key: str) -> Credential | None:"""Reverse a cache-key hash back to its credential (Django-side reads only;diff --git a/posthog/storage/gateway_credential_signal_handlers.py b/posthog/storage/gateway_credential_signal_handlers.pyindex 5b65ac9d9d07..a407c7b39811 100644--- a/posthog/storage/gateway_credential_signal_handlers.py+++ b/posthog/storage/gateway_credential_signal_handlers.py@@ -49,6 +49,10 @@ _LOADED_ELIGIBLE_ATTR = "_fp_loaded_eligible"_LOADED_IS_ACTIVE_ATTR = "_fp_loaded_is_active"_LOADED_MEMBERSHIP_LEVEL_ATTR = "_fp_loaded_membership_level"_LOADED_TEAM_API_TOKEN_ATTR = "_fp_loaded_team_api_token"+_LOADED_TEAM_OVERSPEND_ATTR = "_fp_loaded_team_overspend_allowance"++# Distinguishes "no snapshot captured" from a captured null allowance (null is a valid value).+_UNSET = object()_SECRET_KEY_KIND = "project_secret_api_key"_OAUTH_KIND = "oauth_access_token"@@ -253,26 +257,32 @@ def _reproject_on_membership_delete(_reproject_user_sync_then_async(instance.user_id)-def _capture_old_team_token_if_deferred(sender: type[Team], instance: Team, **kwargs: Any) -> None:+def _capture_old_team_fields_if_deferred(sender: type[Team], instance: Team, **kwargs: Any) -> None:# Sole snapshot source for Team: no post_init handler, since these rows are loaded# far more often than saved — one query per save beats a snapshot on every load.if not settings.AI_GATEWAY_REDIS_URL or _LOADED_TEAM_API_TOKEN_ATTR in instance.__dict__:returnif not instance.pk or instance._state.adding:return- row = Team.objects.filter(pk=instance.pk).values("api_token").first()+ row = Team.objects.filter(pk=instance.pk).values("api_token", "llm_gateway_overspend_allowance_usd").first()if row is not None:instance.__dict__[_LOADED_TEAM_API_TOKEN_ATTR] = row["api_token"]+ instance.__dict__[_LOADED_TEAM_OVERSPEND_ATTR] = row["llm_gateway_overspend_allowance_usd"]-def _reproject_team_on_api_token_change(sender: type[Team], instance: Team, created: bool, **kwargs: Any) -> None:- # project_token in the blob is the team's api_token; a rotation leaves every- # gateway credential blob on this team's gateways carrying the stale token.+def _reproject_team_on_change(sender: type[Team], instance: Team, created: bool, **kwargs: Any) -> None:+ # api_token (project_token) and overspend allowance both feed every credential blob on+ # this team; a change to either leaves them stale, so re-project.if not settings.AI_GATEWAY_REDIS_URL or created:returnold_token = instance.__dict__.get(_LOADED_TEAM_API_TOKEN_ATTR)+ old_allowance = instance.__dict__.get(_LOADED_TEAM_OVERSPEND_ATTR, _UNSET)instance.__dict__[_LOADED_TEAM_API_TOKEN_ATTR] = instance.api_token- if not old_token or old_token == instance.api_token:+ instance.__dict__[_LOADED_TEAM_OVERSPEND_ATTR] = instance.llm_gateway_overspend_allowance_usd++ token_changed = bool(old_token) and old_token != instance.api_token+ allowance_changed = old_allowance is not _UNSET and old_allowance != instance.llm_gateway_overspend_allowance_usd+ if not token_changed and not allowance_changed:returnfrom posthog.tasks.gateway_credential import reproject_team_gateway_credentials_task # noqa: PLC0415@@ -348,8 +358,8 @@ def connect_signal_handlers() -> None:# Team / OrganizationMembership: pre_save fallback only (no post_init). These rows# are read far more than written, so paying one query per save beats snapshotting# every load.- pre_save.connect(_capture_old_team_token_if_deferred, sender=Team)- post_save.connect(_reproject_team_on_api_token_change, sender=Team)+ pre_save.connect(_capture_old_team_fields_if_deferred, sender=Team)+ post_save.connect(_reproject_team_on_change, sender=Team)post_init.connect(_snapshot_user, sender=User)pre_save.connect(_capture_old_user_is_active_if_deferred, sender=User)diff --git a/posthog/storage/test/test_gateway_credential_cache.py b/posthog/storage/test/test_gateway_credential_cache.pyindex eef95c3af7a9..9fe207d996bd 100644--- a/posthog/storage/test/test_gateway_credential_cache.py+++ b/posthog/storage/test/test_gateway_credential_cache.py@@ -1,11 +1,13 @@import jsonfrom datetime import timedelta+from decimal import Decimalimport pytestfrom posthog.test.base import BaseTestfrom unittest.mock import patchfrom django.conf import settings+from django.db import IntegrityError, transactionfrom django.test import override_settingsfrom django.utils import timezone@@ -22,11 +24,14 @@ from posthog.settings.utils import generate_rsa_private_key_pemfrom posthog.storage.gateway_credential_cache import (GATEWAY_CREDENTIAL_FIELDS,GATEWAY_CREDENTIAL_SECRET_KEY_CACHE_TTL,+ OVERSPEND_ALLOWANCE_KEY,clear_gateway_credential,credential_hash,+ format_overspend_allowance_usd,gateway_credential_hypercache as hypercache,project_gateway_credential,refresh_all_gateway_credentials,+ validate_overspend_allowance_usd,)from posthog.tasks.gateway_credential import (refresh_gateway_credentials,@@ -158,6 +163,85 @@ class TestGatewayCredentialWireShape(GatewayCredentialTestMixin):self.assertEqual(blob["team_id"], self.team.id)self.assertEqual(blob["project_token"], self.team.api_token)+ def test_overspend_allowance_omitted_when_unset(self):+ # Null = unset: the field is absent so the gateway falls back to its operator default.+ credential, _ = self._make_secret_key([GATEWAY_SCOPE])+ project_gateway_credential(credential)+ blob = self._read_blob(credential_hash(credential))+ assert blob is not None+ self.assertNotIn(OVERSPEND_ALLOWANCE_KEY, blob)++ @parameterized.expand(+ [+ ("whole", Decimal("5"), "5.000000"),+ ("explicit_zero", Decimal("0"), "0.000000"),+ ("fractional", Decimal("0.5"), "0.500000"),+ ("max", Decimal("10000"), "10000.000000"),+ ]+ )+ def test_overspend_allowance_projected_as_fixed_point_string(self, _name, value, expected):+ # update() bypasses signals (no Redis needed) and persists for the fresh team read.+ Team.objects.filter(pk=self.team.pk).update(llm_gateway_overspend_allowance_usd=value)+ credential, _ = self._make_secret_key([GATEWAY_SCOPE])+ project_gateway_credential(credential)+ blob = self._read_blob(credential_hash(credential))+ assert blob is not None+ # Pin the literal wire value, not a serializer round-trip.+ self.assertEqual(blob[OVERSPEND_ALLOWANCE_KEY], expected)+ self.assertIsInstance(blob[OVERSPEND_ALLOWANCE_KEY], str)+++class TestOverspendAllowanceFormatting(BaseTest):+ @parameterized.expand(+ [+ ("whole", Decimal("5"), "5.000000"),+ ("zero", Decimal("0"), "0.000000"),+ ("max", Decimal("10000"), "10000.000000"),+ ("six_dp", Decimal("1.234567"), "1.234567"),+ ]+ )+ def test_format_is_fixed_point_never_scientific(self, _name, value, expected):+ formatted = format_overspend_allowance_usd(value)+ self.assertEqual(formatted, expected)+ self.assertNotIn("E", formatted.upper())++ @parameterized.expand(+ [+ ("whole", Decimal("5"), Decimal("5.000000")),+ ("zero", Decimal("0"), Decimal("0.000000")),+ ("max", Decimal("10000"), Decimal("10000.000000")),+ ("six_dp", Decimal("1.234567"), Decimal("1.234567")),+ ]+ )+ def test_validate_accepts_in_range(self, _name, value, expected):+ self.assertEqual(validate_overspend_allowance_usd(value), expected)++ @parameterized.expand(+ [+ ("negative", Decimal("-0.000001")),+ ("over_max", Decimal("10000.000001")),+ ("too_precise", Decimal("1.0000001")),+ ("nan", Decimal("NaN")),+ ]+ )+ def test_validate_rejects_out_of_contract(self, _name, value):+ with self.assertRaises(ValueError):+ validate_overspend_allowance_usd(value)+++class TestOverspendAllowanceDBConstraint(BaseTest):+ # The CHECK constraint backstops update/bulk_update/shell/raw writes that bypass the validators.+ @parameterized.expand([("negative", Decimal("-1")), ("over_max", Decimal("10001"))])+ def test_db_rejects_out_of_range_update(self, _name, value):+ with self.assertRaises(IntegrityError), transaction.atomic():+ Team.objects.filter(pk=self.team.pk).update(llm_gateway_overspend_allowance_usd=value)++ @parameterized.expand([("zero", Decimal("0")), ("max", Decimal("10000")), ("unset", None)])+ def test_db_accepts_in_range_update(self, _name, value):+ Team.objects.filter(pk=self.team.pk).update(llm_gateway_overspend_allowance_usd=value)+ self.team.refresh_from_db()+ self.assertEqual(self.team.llm_gateway_overspend_allowance_usd, value)+class TestGatewayCredentialScopeGating(GatewayCredentialTestMixin):@parameterized.expand(@@ -647,3 +731,39 @@ class TestGatewayCredentialSignals(GatewayCredentialTestMixin):team.save()mock_delay.assert_called_with(self.team.id)++ @parameterized.expand([("set", None, Decimal("5")), ("clear", Decimal("5"), None)])+ @patch("posthog.storage.gateway_credential_signal_handlers.transaction")+ @patch("posthog.storage.gateway_credential_signal_handlers.settings")+ @patch("posthog.tasks.gateway_credential.reproject_team_gateway_credentials_task.delay")+ def test_team_overspend_allowance_change_reprojects(+ self, _name, initial, new, mock_delay, mock_settings, mock_transaction+ ):+ # Both transitions between the two observable states (unset and set) reproject every+ # credential blob on the team, rather than waiting out the TTL.+ mock_settings.AI_GATEWAY_REDIS_URL = "redis://localhost"+ mock_transaction.on_commit.side_effect = lambda fn: fn()++ if initial is not None:+ Team.objects.filter(pk=self.team.pk).update(llm_gateway_overspend_allowance_usd=initial)+ team = Team.objects.get(pk=self.team.pk) # snapshot allowance at pre_save under patched setting+ team.llm_gateway_overspend_allowance_usd = new+ team.save()++ mock_delay.assert_called_with(self.team.id)++ @patch("posthog.storage.gateway_credential_signal_handlers.transaction")+ @patch("posthog.storage.gateway_credential_signal_handlers.settings")+ @patch("posthog.tasks.gateway_credential.reproject_team_gateway_credentials_task.delay")+ def test_team_save_without_gateway_field_change_does_not_reproject(+ self, mock_delay, mock_settings, mock_transaction+ ):+ # A save touching neither api_token nor llm_gateway_overspend_allowance_usd must not enqueue.+ mock_settings.AI_GATEWAY_REDIS_URL = "redis://localhost"+ mock_transaction.on_commit.side_effect = lambda fn: fn()++ team = Team.objects.get(pk=self.team.pk)+ team.name = "renamed, no gateway field touched"+ team.save()++ mock_delay.assert_not_called()diff --git a/posthog/tasks/test/__snapshots__/test_process_scheduled_changes.ambr b/posthog/tasks/test/__snapshots__/test_process_scheduled_changes.ambrindex 714a41ba598a..e22e147c5d79 100644--- a/posthog/tasks/test/__snapshots__/test_process_scheduled_changes.ambr+++ b/posthog/tasks/test/__snapshots__/test_process_scheduled_changes.ambr@@ -441,6 +441,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -633,6 +634,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -1223,6 +1225,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -1507,6 +1510,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",diff --git a/posthog/test/setup_receivers_baseline.txt b/posthog/test/setup_receivers_baseline.txtindex 723936249742..5641204e7059 100644--- a/posthog/test/setup_receivers_baseline.txt+++ b/posthog/test/setup_receivers_baseline.txt@@ -113,7 +113,7 @@ post_save:posthog.models.team.team.reevaluate_authorized_urls_healthpost_save:posthog.storage.gateway_credential_signal_handlers._reproject_on_access_control_changepost_save:posthog.storage.gateway_credential_signal_handlers._reproject_on_membership_savepost_save:posthog.storage.gateway_credential_signal_handlers._reproject_on_role_membership_change-post_save:posthog.storage.gateway_credential_signal_handlers._reproject_team_on_api_token_change+post_save:posthog.storage.gateway_credential_signal_handlers._reproject_team_on_changepost_save:posthog.storage.gateway_credential_signal_handlers._reproject_user_on_savepost_save:posthog.storage.gateway_credential_signal_handlers._update_oauth_on_savepost_save:posthog.storage.gateway_credential_signal_handlers._update_secret_key_on_save@@ -194,7 +194,7 @@ pre_save:posthog.models.product_intent.product_intent._capture_original_team_idpre_save:posthog.storage.gateway_credential_signal_handlers._capture_old_membership_level_if_deferredpre_save:posthog.storage.gateway_credential_signal_handlers._capture_old_oauth_if_deferredpre_save:posthog.storage.gateway_credential_signal_handlers._capture_old_secret_key_if_deferred-pre_save:posthog.storage.gateway_credential_signal_handlers._capture_old_team_token_if_deferred+pre_save:posthog.storage.gateway_credential_signal_handlers._capture_old_team_fields_if_deferredpre_save:posthog.storage.gateway_credential_signal_handlers._capture_old_user_is_active_if_deferredpre_save:posthog.storage.team_access_cache_signal_handlers.personal_api_key_pre_savepre_save:posthog.storage.team_access_cache_signal_handlers.project_secret_api_key_pre_savediff --git a/products/actions/backend/api/test/__snapshots__/test_action.ambr b/products/actions/backend/api/test/__snapshots__/test_action.ambrindex 4c8ca736fcdf..25e56694c862 100644--- a/products/actions/backend/api/test/__snapshots__/test_action.ambr+++ b/products/actions/backend/api/test/__snapshots__/test_action.ambr@@ -139,6 +139,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -607,6 +608,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -744,6 +746,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",diff --git a/products/annotations/backend/api/test/__snapshots__/test_annotation.ambr b/products/annotations/backend/api/test/__snapshots__/test_annotation.ambrindex 964609a75dd5..ebbe2d19eb9f 100644--- a/products/annotations/backend/api/test/__snapshots__/test_annotation.ambr+++ b/products/annotations/backend/api/test/__snapshots__/test_annotation.ambr@@ -139,6 +139,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -616,6 +617,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -753,6 +755,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",diff --git a/products/early_access_features/backend/test/__snapshots__/test_early_access_feature.ambr b/products/early_access_features/backend/test/__snapshots__/test_early_access_feature.ambrindex 1ec57b739726..c9d5ef7e05aa 100644--- a/products/early_access_features/backend/test/__snapshots__/test_early_access_feature.ambr+++ b/products/early_access_features/backend/test/__snapshots__/test_early_access_feature.ambr@@ -96,6 +96,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -557,6 +558,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -698,6 +700,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",diff --git a/products/feature_flags/backend/api/test/__snapshots__/test_feature_flag.ambr b/products/feature_flags/backend/api/test/__snapshots__/test_feature_flag.ambrindex e997d8aad0f8..b9ded2ce890a 100644--- a/products/feature_flags/backend/api/test/__snapshots__/test_feature_flag.ambr+++ b/products/feature_flags/backend/api/test/__snapshots__/test_feature_flag.ambr@@ -603,6 +603,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -873,6 +874,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -981,6 +983,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -1196,6 +1199,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",diff --git a/products/feature_flags/backend/api/test/__snapshots__/test_organization_feature_flag.ambr b/products/feature_flags/backend/api/test/__snapshots__/test_organization_feature_flag.ambrindex 6438cfa519c3..1fae3ce7baa2 100644--- a/products/feature_flags/backend/api/test/__snapshots__/test_organization_feature_flag.ambr+++ b/products/feature_flags/backend/api/test/__snapshots__/test_organization_feature_flag.ambr@@ -139,6 +139,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -331,6 +332,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -636,6 +638,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -805,6 +808,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -977,6 +981,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -1077,6 +1082,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -1491,6 +1497,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -1628,6 +1635,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -1736,6 +1744,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -1857,6 +1866,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -1980,6 +1990,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -2102,6 +2113,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -2240,6 +2252,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -2480,6 +2493,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -2588,6 +2602,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -2751,6 +2766,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -2888,6 +2904,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -2996,6 +3013,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -3134,6 +3152,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -3369,6 +3388,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -3477,6 +3497,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",diff --git a/products/product_analytics/backend/api/test/__snapshots__/test_insight.ambr b/products/product_analytics/backend/api/test/__snapshots__/test_insight.ambrindex 1642a3a61d18..701d3861d51a 100644--- a/products/product_analytics/backend/api/test/__snapshots__/test_insight.ambr+++ b/products/product_analytics/backend/api/test/__snapshots__/test_insight.ambr@@ -580,6 +580,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -717,6 +718,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -825,6 +827,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -963,6 +966,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -1152,6 +1156,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -1260,6 +1265,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -1397,6 +1403,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -1605,6 +1612,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -1939,6 +1947,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -2242,6 +2251,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",@@ -2612,6 +2622,7 @@"posthog_team"."logs_settings","posthog_team"."llm_gateway_enabled_at","posthog_team"."llm_gateway_revoked_at",+ "posthog_team"."llm_gateway_overspend_allowance_usd","posthog_team"."heatmaps_opt_in","posthog_team"."receive_org_level_activity_logs","posthog_team"."web_analytics_pre_aggregated_tables_enabled",