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(tasks): mint go ai-gateway tokens for support-reply draft runs (#128187)

Jonathan Mieloo3a742405823a
diff --git a/products/tasks/backend/logic/services/gateway_model_pin.py b/products/tasks/backend/logic/services/gateway_model_pin.py
index e8afabac2e7e..332ef423f60d 100644
--- a/products/tasks/backend/logic/services/gateway_model_pin.py
+++ b/products/tasks/backend/logic/services/gateway_model_pin.py
@@ -73,6 +73,7 @@ PRODUCT_ALLOWED_MODELS: dict[str, list[str]] = {
"posthog_ai": _first_party_pin("posthog_ai"),
"account_audit": _first_party_pin("account_audit"),
"onboarding": ["claude-sonnet-5", "claude-opus-4-8"],
+ "conversations": ["claude-haiku-4-5", "claude-sonnet-4-6", "claude-sonnet-5"],
"background_agents": _first_party_pin("background_agents"),
"posthog_code": DESKTOP_AGENT_MODELS,
FREE_TIER_PIN_KEY: FREE_TIER_MODELS,
diff --git a/products/tasks/backend/temporal/process_task/ai_gateway_token.py b/products/tasks/backend/temporal/process_task/ai_gateway_token.py
index 285cd5bca4cb..b388f5d7e553 100644
--- a/products/tasks/backend/temporal/process_task/ai_gateway_token.py
+++ b/products/tasks/backend/temporal/process_task/ai_gateway_token.py
@@ -98,6 +98,7 @@ MINTABLE_PRODUCTS = frozenset(
"posthog_ai",
"account_audit",
"onboarding",
+ "conversations",
"background_agents",
"posthog_code",
"review_hog",
@@ -261,6 +262,8 @@ def mint_refusal(
"""Why a routed run must not mint."""
if ai_product == "account_audit" and (origin_product != "account_audit" or not internal):
return "no_account_audit_provenance"
+ if ai_product == "conversations" and (origin_product != "support_reply" or not internal):
+ return "no_conversations_provenance"
if ai_product == "background_agents" and (origin_product not in BACKGROUND_AGENTS_ORIGINS or not internal):
return "no_background_agents_provenance"
if ai_product == "slack_app" and not has_slack_provenance(
diff --git a/products/tasks/backend/temporal/process_task/tests/test_ai_gateway_token.py b/products/tasks/backend/temporal/process_task/tests/test_ai_gateway_token.py
index ef902e482555..038409cf33b6 100644
--- a/products/tasks/backend/temporal/process_task/tests/test_ai_gateway_token.py
+++ b/products/tasks/backend/temporal/process_task/tests/test_ai_gateway_token.py
@@ -360,6 +360,14 @@ class TestMintScopedToken:
assert body["product"] == "onboarding"
assert body["allowed_models"] == ["claude-sonnet-5", "claude-opus-4-8"]
+ def test_conversations_mint_carries_the_legacy_model_pin(self, mint_settings):
+ with patch("products.tasks.backend.temporal.process_task.ai_gateway_token.requests.post") as post:
+ post.return_value = self._response(201, {"token": "phe_abc"})
+ assert mint_scoped_token(ai_product="conversations", team_id=2) == "phe_abc"
+ body = post.call_args.kwargs["json"]
+ assert body["product"] == "conversations"
+ assert body["allowed_models"] == ["claude-haiku-4-5", "claude-sonnet-4-6", "claude-sonnet-5"]
+
def test_limit_tier_is_sent_only_when_given(self, mint_settings):
with patch("products.tasks.backend.temporal.process_task.ai_gateway_token.requests.post") as post:
post.return_value = self._response(201, {"token": "phe_abc"})
@@ -1483,18 +1491,39 @@ class TestMintRefusalScope:
== expected
)
- @pytest.mark.parametrize("product", ["posthog_ai", "workflows", "review_hog", "onboarding"])
+ @pytest.mark.parametrize("product", ["posthog_ai", "workflows", "review_hog", "onboarding", "conversations"])
def test_pinned_products_refuse_an_off_pin_model(self, product):
- refusal = mint_refusal(product, team_id=2, state=None, model="claude-opus-3", runtime="acp")
+ refusal = mint_refusal(
+ product,
+ team_id=2,
+ state=None,
+ model="claude-opus-3",
+ runtime="acp",
+ internal=True,
+ origin_product="support_reply",
+ )
assert refusal == "model_outside_pin"
def test_unpinned_products_take_any_model(self):
assert mint_refusal("signals_scout", team_id=2, state=None, model="zai-org/glm-5.3", runtime="acp") is None
- @pytest.mark.parametrize("product", ["review_hog", "signals_scout", "signals_implementation", "onboarding"])
+ @pytest.mark.parametrize(
+ "product", ["review_hog", "signals_scout", "signals_implementation", "onboarding", "conversations"]
+ )
def test_products_billed_elsewhere_skip_the_credit_check(self, product):
with patch(_CREDIT_LOOKUP, return_value="ai_credits_exhausted") as quota:
- assert mint_refusal(product, team_id=2, state=None, model=None, runtime="acp") is None
+ assert (
+ mint_refusal(
+ product,
+ team_id=2,
+ state=None,
+ model=None,
+ runtime="acp",
+ internal=True,
+ origin_product="support_reply",
+ )
+ is None
+ )
quota.assert_not_called()
@@ -1665,6 +1694,21 @@ def test_account_audit_cost_routing_requires_server_provenance(
mint.assert_called_once_with(ai_product="account_audit", team_id=123, user=None)
[email protected]("internal", [True, False])
+def test_support_reply_mint_requires_server_provenance(settings: Settings, internal: bool) -> None:
+ settings.SANDBOX_AI_GATEWAY_URL = "https://ai-gateway.example.com"
+ settings.SANDBOX_AI_GATEWAY_PRODUCTS = "conversations"
+ with patch("products.tasks.backend.temporal.process_task.utils.mint_scoped_token", return_value="phe_test") as mint:
+ env = ai_gateway_env_vars(
+ team_id=123, origin_product="support_reply", internal=internal, model=None, runtime="acp"
+ )
+ assert ("AI_GATEWAY_TOKEN" in env) is internal
+ if internal:
+ mint.assert_called_once_with(ai_product="conversations", team_id=123, user=None)
+ else:
+ mint.assert_not_called()
+
+
class TestPosthogCodeSandboxMint:
def _team(self, *, paid: bool) -> Team:
organization = Organization.objects.create(name="Code Org")