Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

feat(billing): split signals usage out of PostHog AI usage reporting (#60753)

Joshua Snyder970430bb2b41
diff --git a/posthog/tasks/test/test_usage_report.py b/posthog/tasks/test/test_usage_report.py
index fb01f644c590..c3d18b2a916d 100644
--- a/posthog/tasks/test/test_usage_report.py
+++ b/posthog/tasks/test/test_usage_report.py
@@ -3129,6 +3129,7 @@ class TestAIEventsUsageReport(ClickhouseDestroyTablesMixin, TestCase, Clickhouse
"$ai_trace_id": "trace_billable",
"$ai_total_cost_usd": 1.0,
"$ai_billable": True,
+ "ai_product": "posthog_ai",
"$group_1": "https://us.posthog.com",
},
)
@@ -3190,6 +3191,7 @@ class TestAIEventsUsageReport(ClickhouseDestroyTablesMixin, TestCase, Clickhouse
"$ai_trace_id": "trace_free",
"$ai_total_cost_usd": 2.0,
"$ai_billable": True,
+ "ai_product": "posthog_ai",
"$group_1": "https://us.posthog.com",
},
)
@@ -3250,6 +3252,7 @@ class TestAIEventsUsageReport(ClickhouseDestroyTablesMixin, TestCase, Clickhouse
"$ai_trace_id": "trace_summarize",
"$ai_total_cost_usd": 2.0,
"$ai_billable": True,
+ "ai_product": "posthog_ai",
"$group_1": "https://us.posthog.com",
},
)
@@ -3310,6 +3313,7 @@ class TestAIEventsUsageReport(ClickhouseDestroyTablesMixin, TestCase, Clickhouse
"$ai_trace_id": "trace_mixed_excluded",
"$ai_total_cost_usd": 2.0,
"$ai_billable": True,
+ "ai_product": "posthog_ai",
"$group_1": "https://us.posthog.com",
},
)
@@ -3373,6 +3377,7 @@ class TestAIEventsUsageReport(ClickhouseDestroyTablesMixin, TestCase, Clickhouse
"$ai_trace_id": "trace_mixed_billable",
"$ai_total_cost_usd": 1.0,
"$ai_billable": True,
+ "ai_product": "posthog_ai",
"$group_1": "https://us.posthog.com",
},
)
@@ -3435,6 +3440,7 @@ class TestAIEventsUsageReport(ClickhouseDestroyTablesMixin, TestCase, Clickhouse
"$ai_trace_id": "trace_billable_search",
"$ai_total_cost_usd": 0.5,
"$ai_billable": True,
+ "ai_product": "posthog_ai",
"$group_1": "https://us.posthog.com",
},
)
@@ -3515,6 +3521,7 @@ class TestAIEventsUsageReport(ClickhouseDestroyTablesMixin, TestCase, Clickhouse
"$ai_trace_id": "trace_multi_turn",
"$ai_total_cost_usd": 1.5,
"$ai_billable": True,
+ "ai_product": "posthog_ai",
"$group_1": "https://us.posthog.com",
},
)
@@ -3566,6 +3573,7 @@ class TestAIEventsUsageReport(ClickhouseDestroyTablesMixin, TestCase, Clickhouse
"$ai_trace_id": "trace_billable",
"$ai_total_cost_usd": 0.5,
"$ai_billable": True,
+ "ai_product": "posthog_ai",
"$group_1": "https://us.posthog.com",
},
)
@@ -3596,6 +3604,7 @@ class TestAIEventsUsageReport(ClickhouseDestroyTablesMixin, TestCase, Clickhouse
"$ai_trace_id": "trace_billable",
"$ai_total_cost_usd": 0.0,
"$ai_billable": True,
+ "ai_product": "posthog_ai",
"$group_1": "https://us.posthog.com",
},
)
@@ -3611,6 +3620,7 @@ class TestAIEventsUsageReport(ClickhouseDestroyTablesMixin, TestCase, Clickhouse
"$ai_trace_id": "trace_billable",
"$ai_total_cost_usd": -1.0,
"$ai_billable": True,
+ "ai_product": "posthog_ai",
"$group_1": "https://us.posthog.com",
},
)
@@ -3669,6 +3679,7 @@ class TestAIEventsUsageReport(ClickhouseDestroyTablesMixin, TestCase, Clickhouse
"$ai_trace_id": "trace_no_tools",
"$ai_total_cost_usd": 0.5,
"$ai_billable": True,
+ "ai_product": "posthog_ai",
"$group_1": "https://us.posthog.com",
},
)
@@ -3762,6 +3773,7 @@ class TestAIEventsUsageReport(ClickhouseDestroyTablesMixin, TestCase, Clickhouse
"$ai_trace_id": "trace_us",
"$ai_total_cost_usd": 1.0,
"$ai_billable": True,
+ "ai_product": "posthog_ai",
"$group_1": "https://us.posthog.com",
},
)
@@ -3777,6 +3789,7 @@ class TestAIEventsUsageReport(ClickhouseDestroyTablesMixin, TestCase, Clickhouse
"$ai_trace_id": "trace_eu_in_us",
"$ai_total_cost_usd": 5.0,
"$ai_billable": True,
+ "ai_product": "posthog_ai",
"$group_1": "https://eu.posthog.com",
},
)
@@ -3853,6 +3866,7 @@ class TestAIEventsUsageReport(ClickhouseDestroyTablesMixin, TestCase, Clickhouse
"$ai_trace_id": "trace_eu",
"$ai_total_cost_usd": 2.0,
"$ai_billable": True,
+ "ai_product": "posthog_ai",
"$group_1": "not-the-instance-group",
"$group_2": "https://eu.posthog.com",
},
@@ -3869,6 +3883,7 @@ class TestAIEventsUsageReport(ClickhouseDestroyTablesMixin, TestCase, Clickhouse
"$ai_trace_id": "trace_us_in_eu",
"$ai_total_cost_usd": 3.0,
"$ai_billable": True,
+ "ai_product": "posthog_ai",
"$group_1": "not-the-instance-group",
"$group_2": "https://us.posthog.com",
},
@@ -3884,6 +3899,327 @@ class TestAIEventsUsageReport(ClickhouseDestroyTablesMixin, TestCase, Clickhouse
self.assertEqual(result[0][0], self.org_1_team_1.id)
self.assertEqual(result[0][1], 240)
+ @patch("posthog.tasks.usage_report.get_instance_region")
+ def test_signals_ai_product_excluded_from_ai_credits(self, mock_region: MagicMock) -> None:
+ """Generations tagged ai_product='signals' must not count toward PostHog AI credits."""
+ from posthog.tasks.usage_report import get_teams_with_ai_credits_used_in_period
+
+ mock_region.return_value = "US"
+ self._setup_teams()
+ analytics_org = Organization.objects.create(name="PostHog Analytics")
+ analytics_team = Team.objects.create(pk=2, organization=analytics_org, name="Analytics")
+ self._setup_instance_group_mapping(analytics_team)
+
+ period = get_previous_day(at=now() + relativedelta(days=1))
+ period_start, period_end = period
+
+ # Billable generation tagged as signals — should be excluded
+ _create_event(
+ event="$ai_generation",
+ team=analytics_team,
+ distinct_id="user_signals",
+ timestamp=period_start + relativedelta(hours=1),
+ properties={
+ "team_id": self.org_1_team_1.id,
+ "$ai_trace_id": "trace_signals",
+ "$ai_total_cost_usd": 5.0,
+ "$ai_billable": True,
+ "ai_product": "signals",
+ "$group_1": "https://us.posthog.com",
+ },
+ )
+
+ flush_persons_and_events()
+
+ result = get_teams_with_ai_credits_used_in_period(period_start, period_end)
+
+ self.assertEqual(result, [])
+
+ @patch("posthog.tasks.usage_report.get_instance_region")
+ def test_ai_credits_excludes_events_without_ai_product(self, mock_region: MagicMock) -> None:
+ """Generations missing the ai_product property are NOT billed — billing whitelists ai_product."""
+ from posthog.tasks.usage_report import get_teams_with_ai_credits_used_in_period
+
+ mock_region.return_value = "US"
+ self._setup_teams()
+ analytics_org = Organization.objects.create(name="PostHog Analytics")
+ analytics_team = Team.objects.create(pk=2, organization=analytics_org, name="Analytics")
+ self._setup_instance_group_mapping(analytics_team)
+
+ period = get_previous_day(at=now() + relativedelta(days=1))
+ period_start, period_end = period
+
+ # Matching billable trace — isolates that exclusion is due to the missing ai_product,
+ # not a missing trace.
+ _create_event(
+ event="$ai_trace",
+ team=analytics_team,
+ distinct_id="user_legacy",
+ timestamp=period_start + relativedelta(hours=1),
+ properties={
+ "$ai_trace_id": "trace_legacy",
+ "$ai_output_state": {"messages": [{"tool_calls": [{"name": "query_executor"}]}]},
+ "$group_1": "https://us.posthog.com",
+ },
+ )
+
+ # Untagged generation (no ai_product) — excluded by the ai_product whitelist.
+ _create_event(
+ event="$ai_generation",
+ team=analytics_team,
+ distinct_id="user_legacy",
+ timestamp=period_start + relativedelta(hours=1),
+ properties={
+ "team_id": self.org_1_team_1.id,
+ "$ai_trace_id": "trace_legacy",
+ "$ai_total_cost_usd": 1.0,
+ "$group_1": "https://us.posthog.com",
+ "$ai_billable": True,
+ },
+ )
+
+ flush_persons_and_events()
+
+ result = get_teams_with_ai_credits_used_in_period(period_start, period_end)
+
+ self.assertEqual(result, [])
+
+ @patch("posthog.tasks.usage_report.get_instance_region")
+ def test_signals_credits_only_counts_signals_events(self, mock_region: MagicMock) -> None:
+ """The signals query only counts generations tagged ai_product='signals' for the same team."""
+ from posthog.tasks.usage_report import (
+ get_teams_with_ai_credits_used_in_period,
+ get_teams_with_signals_credits_used_in_period,
+ )
+
+ mock_region.return_value = "US"
+ self._setup_teams()
+ analytics_org = Organization.objects.create(name="PostHog Analytics")
+ analytics_team = Team.objects.create(pk=2, organization=analytics_org, name="Analytics")
+ self._setup_instance_group_mapping(analytics_team)
+
+ period = get_previous_day(at=now() + relativedelta(days=1))
+ period_start, period_end = period
+
+ # Signals event — should appear only in signals credits
+ _create_event(
+ event="$ai_generation",
+ team=analytics_team,
+ distinct_id="user_signals",
+ timestamp=period_start + relativedelta(hours=1),
+ properties={
+ "team_id": self.org_1_team_1.id,
+ "$ai_trace_id": "trace_signals",
+ "$ai_total_cost_usd": 2.0,
+ "$ai_billable": True,
+ "ai_product": "signals",
+ "$group_1": "https://us.posthog.com",
+ },
+ )
+
+ # Max AI event — should appear only in ai credits. Max AI is billed via its paired
+ # $ai_trace (unlike signals, which never emits one), so create a matching billable trace.
+ _create_event(
+ event="$ai_trace",
+ team=analytics_team,
+ distinct_id="user_max",
+ timestamp=period_start + relativedelta(hours=2),
+ properties={
+ "$ai_trace_id": "trace_max",
+ "$ai_output_state": {"messages": [{"tool_calls": [{"name": "query_executor"}]}]},
+ "$group_1": "https://us.posthog.com",
+ },
+ )
+
+ _create_event(
+ event="$ai_generation",
+ team=analytics_team,
+ distinct_id="user_max",
+ timestamp=period_start + relativedelta(hours=2),
+ properties={
+ "team_id": self.org_1_team_1.id,
+ "$ai_trace_id": "trace_max",
+ "$ai_total_cost_usd": 1.0,
+ "$ai_billable": True,
+ "ai_product": "posthog_ai",
+ "$group_1": "https://us.posthog.com",
+ },
+ )
+
+ flush_persons_and_events()
+
+ signals_result = get_teams_with_signals_credits_used_in_period(period_start, period_end)
+ ai_result = get_teams_with_ai_credits_used_in_period(period_start, period_end)
+
+ # signals: 2.0 USD * 100 * 1.2 = 240
+ self.assertEqual(signals_result, [(self.org_1_team_1.id, 240)])
+ # ai (posthog_ai only): 1.0 USD * 100 * 1.2 = 120
+ self.assertEqual(ai_result, [(self.org_1_team_1.id, 120)])
+
+ @patch("posthog.tasks.usage_report.get_instance_region")
+ def test_ai_credits_counts_billable_generation_with_no_trace(self, mock_region: MagicMock) -> None:
+ """A billable generation with no matching $ai_trace bills via the empty-trace fallback.
+
+ The predicate is uniform across products: bill when the trace is billable OR there is no
+ trace. So a billable posthog_ai generation whose $ai_trace was not captured still bills.
+ """
+ from posthog.tasks.usage_report import get_teams_with_ai_credits_used_in_period
+
+ mock_region.return_value = "US"
+ self._setup_teams()
+ analytics_org = Organization.objects.create(name="PostHog Analytics")
+ analytics_team = Team.objects.create(pk=2, organization=analytics_org, name="Analytics")
+ self._setup_instance_group_mapping(analytics_team)
+
+ period = get_previous_day(at=now() + relativedelta(days=1))
+ period_start, period_end = period
+
+ # Billable posthog_ai generation with NO matching $ai_trace event.
+ _create_event(
+ event="$ai_generation",
+ team=analytics_team,
+ distinct_id="user_orphan",
+ timestamp=period_start + relativedelta(hours=1),
+ properties={
+ "team_id": self.org_1_team_1.id,
+ "$ai_trace_id": "trace_orphan",
+ "$ai_total_cost_usd": 3.0,
+ "$ai_billable": True,
+ "ai_product": "posthog_ai",
+ "$group_1": "https://us.posthog.com",
+ },
+ )
+
+ flush_persons_and_events()
+
+ result = get_teams_with_ai_credits_used_in_period(period_start, period_end)
+
+ # 3.0 USD * 100 * 1.2 = 360
+ self.assertEqual(result, [(self.org_1_team_1.id, 360)])
+
+ @patch("posthog.tasks.usage_report.get_instance_region")
+ def test_ai_credits_counts_traceless_whitelisted_product(self, mock_region: MagicMock) -> None:
+ """A traceless whitelisted product (e.g. slack_app) bills via the empty-trace fallback."""
+ from posthog.tasks.usage_report import get_teams_with_ai_credits_used_in_period
+
+ mock_region.return_value = "US"
+ self._setup_teams()
+ analytics_org = Organization.objects.create(name="PostHog Analytics")
+ analytics_team = Team.objects.create(pk=2, organization=analytics_org, name="Analytics")
+ self._setup_instance_group_mapping(analytics_team)
+
+ period = get_previous_day(at=now() + relativedelta(days=1))
+ period_start, period_end = period
+
+ # slack_app emits no $ai_trace — billed via the empty-trace fallback, not a paired trace.
+ _create_event(
+ event="$ai_generation",
+ team=analytics_team,
+ distinct_id="user_slack",
+ timestamp=period_start + relativedelta(hours=1),
+ properties={
+ "team_id": self.org_1_team_1.id,
+ "$ai_trace_id": "trace_slack",
+ "$ai_total_cost_usd": 1.0,
+ "$ai_billable": True,
+ "ai_product": "slack_app",
+ "$group_1": "https://us.posthog.com",
+ },
+ )
+
+ flush_persons_and_events()
+
+ result = get_teams_with_ai_credits_used_in_period(period_start, period_end)
+
+ # 1.0 USD * 100 * 1.2 = 120
+ self.assertEqual(result, [(self.org_1_team_1.id, 120)])
+
+ @patch("posthog.tasks.usage_report.get_instance_region")
+ def test_signals_credits_counts_traceless_generation(self, mock_region: MagicMock) -> None:
+ """A billable signals generation with no $ai_trace IS billed via the empty-trace fallback.
+
+ Signals never emits $ai_trace events, so the LEFT JOIN never matches; the fallback is
+ what makes signals billable at all.
+ """
+ from posthog.tasks.usage_report import get_teams_with_signals_credits_used_in_period
+
+ mock_region.return_value = "US"
+ self._setup_teams()
+ analytics_org = Organization.objects.create(name="PostHog Analytics")
+ analytics_team = Team.objects.create(pk=2, organization=analytics_org, name="Analytics")
+ self._setup_instance_group_mapping(analytics_team)
+
+ period = get_previous_day(at=now() + relativedelta(days=1))
+ period_start, period_end = period
+
+ _create_event(
+ event="$ai_generation",
+ team=analytics_team,
+ distinct_id="user_signals",
+ timestamp=period_start + relativedelta(hours=1),
+ properties={
+ "team_id": self.org_1_team_1.id,
+ "$ai_trace_id": "trace_signals",
+ "$ai_total_cost_usd": 4.0,
+ "$ai_billable": True,
+ "ai_product": "signals",
+ "$group_1": "https://us.posthog.com",
+ },
+ )
+
+ flush_persons_and_events()
+
+ result = get_teams_with_signals_credits_used_in_period(period_start, period_end)
+
+ # 4.0 USD * 100 * 1.2 = 480
+ self.assertEqual(result, [(self.org_1_team_1.id, 480)])
+
+ @patch("posthog.tasks.usage_report.get_instance_region")
+ def test_signals_credits_excludes_non_billable_generation(self, mock_region: MagicMock) -> None:
+ """A signals generation tagged $ai_billable=false is not counted, even for signals."""
+ from posthog.tasks.usage_report import get_teams_with_signals_credits_used_in_period
+
+ mock_region.return_value = "US"
+ self._setup_teams()
+ analytics_org = Organization.objects.create(name="PostHog Analytics")
+ analytics_team = Team.objects.create(pk=2, organization=analytics_org, name="Analytics")
+ self._setup_instance_group_mapping(analytics_team)
+
+ period = get_previous_day(at=now() + relativedelta(days=1))
+ period_start, period_end = period
+
+ _create_event(
+ event="$ai_generation",
+ team=analytics_team,
+ distinct_id="user_signals",
+ timestamp=period_start + relativedelta(hours=1),
+ properties={
+ "team_id": self.org_1_team_1.id,
+ "$ai_trace_id": "trace_signals",
+ "$ai_total_cost_usd": 4.0,
+ "$ai_billable": False,
+ "ai_product": "signals",
+ "$group_1": "https://us.posthog.com",
+ },
+ )
+
+ flush_persons_and_events()
+
+ result = get_teams_with_signals_credits_used_in_period(period_start, period_end)
+
+ self.assertEqual(result, [])
+
+ def test_has_non_zero_usage_counts_signals_credits(self) -> None:
+ """A signals-only org must survive has_non_zero_usage so its report still reaches billing."""
+ import dataclasses
+
+ from posthog.tasks.usage_report import UsageReportCounters, has_non_zero_usage
+
+ zero = {field.name: 0 for field in dataclasses.fields(UsageReportCounters)}
+
+ self.assertFalse(has_non_zero_usage(UsageReportCounters(**zero)))
+ self.assertTrue(has_non_zero_usage(UsageReportCounters(**{**zero, "signals_credits_used_in_period": 5})))
+
class TestSendUsage(LicensedTestMixin, ClickhouseDestroyTablesMixin, APIBaseTest):
def setUp(self) -> None:
diff --git a/posthog/tasks/usage_report.py b/posthog/tasks/usage_report.py
index 2338678f55d0..99f8ebdf14c9 100644
--- a/posthog/tasks/usage_report.py
+++ b/posthog/tasks/usage_report.py
@@ -200,6 +200,9 @@ class UsageReportCounters:
# AI Billing Credits (PostHog AI feature usage)
ai_credits_used_in_period: int
+ # Signals Billing Credits (Signals product usage — same cost math as ai_credits, scoped to ai_product='signals')
+ signals_credits_used_in_period: int
+
# CDP Delivery
hog_function_calls_in_period: int
hog_function_fetch_calls_in_period: int
@@ -1091,6 +1094,18 @@ CLOUD_REGION_TO_URL = {
}
+# ai_product values that roll into PostHog AI (Max) billing credits.
+POSTHOG_AI_PRODUCTS = [
+ "posthog_ai",
+ "slack_app",
+ "subscriptions",
+ "alert_investigation_agent",
+]
+
+# ai_product values billed as signals credits.
+SIGNALS_AI_PRODUCTS = ["signals"]
+
+
def get_ai_billing_instance_group_type_index(team_id: int) -> int | None:
"""Resolve the $group_N index that holds the customer cloud URL for the internal AI events team."""
for mapping in get_group_types_for_team(team_id):
@@ -1108,20 +1123,28 @@ def build_ai_billing_region_filter(team_id: int, region_url: str) -> dict[str, s
return {"region_group_property": f"$group_{instance_group_index}", "region_url": region_url}
-@timed_log()
-@retry(tries=QUERY_RETRIES, delay=QUERY_RETRY_DELAY, backoff=QUERY_RETRY_BACKOFF)
-def get_teams_with_ai_credits_used_in_period(
+def _get_teams_with_ai_credits_for_products(
begin: datetime,
end: datetime,
+ *,
+ ai_products: list[str],
+ usage_report_tag: str,
+ product_tag: Product = Product.MAX_AI,
) -> list[tuple[int, int]]:
"""
- Calculate AI credits used in the period for billable AI generations.
+ Shared implementation for AI billing credit aggregation, whitelisting on the
+ `ai_product` event property — only generations tagged with an `ai_products` value are billed.
- Billing is performed at the trace level. Traces are billable only if they contain
- tool calls that include at least one non-excluded tool. Free (non-billable) traces:
+ A billable $ai_generation (with positive cost) is billed when its trace is billable OR it has no
+ trace. Products that emit a paired $ai_trace (e.g. posthog_ai) are billed only on a billable trace;
+ a trace is billable only if it contains tool calls including at least one non-excluded tool. Free
+ (non-billable) traces:
- Traces that only contain 'summarize_sessions' tool calls
- Traces that only contain 'search' tool calls with kind='docs'
+ Products that emit no $ai_trace (e.g. signals, slack_app) have no matching trace, so they are
+ billed via the empty-trace fallback.
+
We are also performing additional filtering to maintain current trace tool calls and not all messages
in the ongoing conversation thread (otherwise we might end up billing for traces we would not want to)
@@ -1153,7 +1176,7 @@ def get_teams_with_ai_credits_used_in_period(
return []
with tags_context(
- product=Product.MAX_AI, feature=Feature.USAGE_REPORT, usage_report="ai_credits", kind="usage_report"
+ product=product_tag, feature=Feature.USAGE_REPORT, usage_report=usage_report_tag, kind="usage_report"
):
results = sync_execute(
"""
@@ -1235,6 +1258,7 @@ def get_teams_with_ai_credits_used_in_period(
AND timestamp >= %(begin)s
AND timestamp < %(end)s
AND event = '$ai_generation'
+ AND JSONExtractString(properties, 'ai_product') IN %(ai_products)s
)
WHERE
ai_billable = 1
@@ -1250,8 +1274,10 @@ def get_teams_with_ai_credits_used_in_period(
FROM costs c
LEFT JOIN trace_analysis t ON c.trace_id = t.trace_id
WHERE
- -- keep rows that are billable OR have no trace metadata
- t.is_billable = 1 OR t.trace_id IS NULL
+ -- keep rows whose trace is billable, or that have no trace (traceless products bill
+ -- on $ai_billable alone, already enforced in the costs CTE). Use empty(), not
+ -- IS NULL: join_use_nulls=0 yields '' — not NULL — for an unmatched trace_id.
+ t.is_billable = 1 OR empty(t.trace_id)
GROUP BY
c.customer_team_id
HAVING
@@ -1265,6 +1291,7 @@ def get_teams_with_ai_credits_used_in_period(
"end": end,
"markup_multiplier": 1 + AI_COST_MARKUP_PERCENT,
"excluded_tools": AI_BILLING_EXCLUDED_TOOLS,
+ "ai_products": tuple(ai_products),
**region_filter_params,
},
workload=Workload.OFFLINE,
@@ -1275,6 +1302,37 @@ def get_teams_with_ai_credits_used_in_period(
return results
+@timed_log()
+@retry(tries=QUERY_RETRIES, delay=QUERY_RETRY_DELAY, backoff=QUERY_RETRY_BACKOFF)
+def get_teams_with_ai_credits_used_in_period(
+ begin: datetime,
+ end: datetime,
+) -> list[tuple[int, int]]:
+ """PostHog AI (Max) billing credits — events tagged with an ai_product in POSTHOG_AI_PRODUCTS."""
+ return _get_teams_with_ai_credits_for_products(
+ begin,
+ end,
+ ai_products=POSTHOG_AI_PRODUCTS,
+ usage_report_tag="ai_credits",
+ )
+
+
+@timed_log()
+@retry(tries=QUERY_RETRIES, delay=QUERY_RETRY_DELAY, backoff=QUERY_RETRY_BACKOFF)
+def get_teams_with_signals_credits_used_in_period(
+ begin: datetime,
+ end: datetime,
+) -> list[tuple[int, int]]:
+ """Signals billing credits — only events tagged with ai_product='signals'."""
+ return _get_teams_with_ai_credits_for_products(
+ begin,
+ end,
+ ai_products=SIGNALS_AI_PRODUCTS,
+ usage_report_tag="signals_credits",
+ product_tag=Product.SIGNALS,
+ )
+
+
dwh_pricing_free_period_start = datetime(2025, 10, 29, 0, 0, 0, tzinfo=UTC)
dwh_pricing_free_period_end = datetime(2025, 11, 6, 0, 0, 0, tzinfo=UTC)
@@ -1938,6 +1996,7 @@ def has_non_zero_usage(report: UsageReportCounters) -> bool:
or report.exceptions_captured_in_period > 0
or report.ai_event_count_in_period > 0
or report.ai_credits_used_in_period > 0
+ or report.signals_credits_used_in_period > 0
or report.workflow_emails_sent_in_period > 0
or report.workflow_push_sent_in_period > 0
or report.workflow_sms_sent_in_period > 0
@@ -2193,6 +2252,9 @@ def _get_all_usage_data(period_start: datetime, period_end: datetime) -> dict[st
),
"teams_with_ai_event_count_in_period": get_teams_with_ai_event_count_in_period(period_start, period_end),
"teams_with_ai_credits_used_in_period": get_teams_with_ai_credits_used_in_period(period_start, period_end),
+ "teams_with_signals_credits_used_in_period": get_teams_with_signals_credits_used_in_period(
+ period_start, period_end
+ ),
"teams_with_active_hog_destinations_in_period": get_teams_with_active_hog_destinations_in_period(),
"teams_with_active_hog_transformations_in_period": get_teams_with_active_hog_transformations_in_period(),
"teams_with_workflow_emails_sent_in_period": get_teams_with_workflow_emails_sent_in_period(
@@ -2357,6 +2419,7 @@ def _get_team_report(all_data: dict[str, Any], team: Team) -> UsageReportCounter
rust_events_count_in_period=all_data["teams_with_rust_events_count_in_period"].get(team.id, 0),
ai_event_count_in_period=all_data["teams_with_ai_event_count_in_period"].get(team.id, 0),
ai_credits_used_in_period=all_data["teams_with_ai_credits_used_in_period"].get(team.id, 0),
+ signals_credits_used_in_period=all_data["teams_with_signals_credits_used_in_period"].get(team.id, 0),
active_hog_destinations_in_period=all_data["teams_with_active_hog_destinations_in_period"].get(team.id, 0),
active_hog_transformations_in_period=all_data["teams_with_active_hog_transformations_in_period"].get(
team.id, 0
diff --git a/posthog/temporal/usage_report/queries.py b/posthog/temporal/usage_report/queries.py
index 3f48d3b14e4a..0f67d8461423 100644
--- a/posthog/temporal/usage_report/queries.py
+++ b/posthog/temporal/usage_report/queries.py
@@ -77,6 +77,7 @@ from posthog.tasks.usage_report import (
get_teams_with_rows_exported_in_period,
get_teams_with_rows_synced_in_period,
get_teams_with_sdk_logs_records_in_period,
+ get_teams_with_signals_credits_used_in_period,
get_teams_with_survey_responses_count_in_period,
get_teams_with_workflow_billable_invocations_in_period,
get_teams_with_workflow_emails_sent_in_period,
@@ -424,6 +425,10 @@ QUERIES: list[QuerySpec] = [
name="teams_with_ai_credits_used_in_period",
fn=get_teams_with_ai_credits_used_in_period,
),
+ QuerySpec(
+ name="teams_with_signals_credits_used_in_period",
+ fn=get_teams_with_signals_credits_used_in_period,
+ ),
# ---- ClickHouse: workflows / messaging ----------------------------------
QuerySpec(
name="teams_with_workflow_emails_sent_in_period",