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.

fix(stripe): treat IP-restricted API key error as non-retryable (#63685)

Tom Owers71a33d5682dd
diff --git a/posthog/temporal/data_imports/sources/stripe/source.py b/posthog/temporal/data_imports/sources/stripe/source.py
index adf99fcc2d74..cf50232c80cf 100644
--- a/posthog/temporal/data_imports/sources/stripe/source.py
+++ b/posthog/temporal/data_imports/sources/stripe/source.py
@@ -232,6 +232,10 @@ If automatic creation failed due to a permissions error and you're using a restr
"403 Client Error: Forbidden for url: https://api.stripe.com": "Your Stripe credentials do not have permissions to access endpoint. Please check your configuration and permissions in Stripe, then try again.",
"Expired API Key provided": "Your Stripe API key has expired. Please create a new key and reconnect.",
"Invalid API Key provided": None,
+ # Stripe rejects the request when the restricted key has an IP allowlist that doesn't
+ # include PostHog's egress IPs. This is a customer-side key configuration that retrying
+ # can never satisfy, so stop retrying. Match the stable phrase, not the appended IP.
+ "does not allow requests from your IP address": "Your Stripe API key restricts requests by IP address and is blocking PostHog. Remove the IP restriction on your restricted key in Stripe (or allowlist PostHog's IP addresses), then try again.",
# Surface Stripe's raw permission message — it names the specific scope that's missing
# (e.g. "Having the 'rak_payment_method_read' permission would allow this request to
# continue"), which is more actionable than a generic "check your permissions" toast.
diff --git a/posthog/temporal/data_imports/sources/stripe/tests/test_stripe_source.py b/posthog/temporal/data_imports/sources/stripe/tests/test_stripe_source.py
index c6e625c18606..3637043b1695 100644
--- a/posthog/temporal/data_imports/sources/stripe/tests/test_stripe_source.py
+++ b/posthog/temporal/data_imports/sources/stripe/tests/test_stripe_source.py
@@ -2,16 +2,11 @@ import pytest
from posthog.temporal.data_imports.sources.stripe.source import StripeSource
-from products.data_warehouse.backend.types import ExternalDataSourceType
-
class TestStripeSource:
def setup_method(self):
self.source = StripeSource()
- def test_source_type(self):
- assert self.source.source_type == ExternalDataSourceType.STRIPE
-
@pytest.mark.parametrize(
"observed_error",
[
@@ -22,6 +17,9 @@ class TestStripeSource:
# 401/403 surfaced as a requests HTTPError keep matching the existing URL-based keys.
"401 Client Error: Unauthorized for url: https://api.stripe.com/v1/customers",
"403 Client Error: Forbidden for url: https://api.stripe.com/v1/prices",
+ # IP allowlist rejection — matched on the stable phrase, ignoring the appended IP address.
+ "The API key provided does not allow requests from your IP address.",
+ "The API key provided does not allow requests from your IP address (1.2.3.4).",
],
)
def test_non_retryable_errors_match_permission_failures(self, observed_error):