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(admin): point AI gateway add_credit at the team-keyed endpoint (#66454)

Brandon38de8665ec7f
diff --git a/posthog/llm/gateway_internal_client.py b/posthog/llm/gateway_internal_client.py
index ab4b32e7e0d8..55cd49de13b3 100644
--- a/posthog/llm/gateway_internal_client.py
+++ b/posthog/llm/gateway_internal_client.py
@@ -100,10 +100,15 @@ def get_wallet(team_id: int) -> Wallet:
def add_credit(team_id: int, amount_usd: str, reason: str, idempotency_key: str) -> CreditResult:
+ # Team-keyed top-up: funds the team wallet that admission draws down and
+ # get_wallet() reads, so the credit is spendable today. The gateway's
+ # org-scoped /internal/accounts/{org_id}/credits is the billing path but is
+ # not yet drawn down at admission.
+ # TODO(billing-entrypoint): revisit once credits are org-keyed end to end.
url, token = _config()
try:
response = httpx.post(
- f"{url}/internal/accounts/{team_id}/credits",
+ f"{url}/internal/teams/{team_id}/credits",
headers=_auth_headers(token, {IDEMPOTENCY_KEY_HEADER: idempotency_key}),
json={"amount_usd": amount_usd, "reason": reason},
timeout=INTERNAL_API_TIMEOUT_SECONDS,
diff --git a/posthog/llm/test_gateway_internal_client.py b/posthog/llm/test_gateway_internal_client.py
index e6c3357c2684..71faa4d48305 100644
--- a/posthog/llm/test_gateway_internal_client.py
+++ b/posthog/llm/test_gateway_internal_client.py
@@ -105,7 +105,7 @@ class TestAddCredit:
result = add_credit(42, "25.00", "topping up", "key-123")
url = mock_post.call_args.args[0]
- assert url == "http://gw/internal/accounts/42/credits"
+ assert url == "http://gw/internal/teams/42/credits"
assert mock_post.call_args.kwargs["json"] == {"amount_usd": "25.00", "reason": "topping up"}
assert mock_post.call_args.kwargs["headers"][IDEMPOTENCY_KEY_HEADER] == "key-123"
assert mock_post.call_args.kwargs["headers"]["Authorization"] == "Bearer tok"