: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
fix(elevenlabs): treat a rejected key at connect as invalid, not transient (#79417)
Tom Owers4414b9ec7379
diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/elevenlabs/elevenlabs.py b/products/warehouse_sources/backend/temporal/data_imports/sources/elevenlabs/elevenlabs.pyindex 3b11f79e33af..759305247805 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/elevenlabs/elevenlabs.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/elevenlabs/elevenlabs.py@@ -164,6 +164,11 @@ def validate_credentials(api_key: str, schema_name: Optional[str] = None) -> tupif schema_name is None:return True, Nonereturn False, f"Your ElevenLabs API key is missing the permission required to sync `{schema_name}`."+ # A 4xx other than the 401/403 above (a 400 is what users actually hit) is a deterministic client+ # error: the key was rejected and retrying sends the same request, so treat it as an invalid key+ # rather than a transient "try again". 429 is a rate limit and stays retryable below.+ if 400 <= status < 500 and status != 429:+ return False, "Invalid ElevenLabs API key"# A 429/5xx/unexpected status leaves the key unverified. Don't accept it — surface it so the user# can retry, rather than saving a source that only fails on its first sync.return False, f"Could not verify the ElevenLabs API key (status {status}). Please try again."diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/elevenlabs/tests/test_elevenlabs.py b/products/warehouse_sources/backend/temporal/data_imports/sources/elevenlabs/tests/test_elevenlabs.pyindex 5d84af64cd9e..786f31fbb0cc 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/elevenlabs/tests/test_elevenlabs.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/elevenlabs/tests/test_elevenlabs.py@@ -237,6 +237,8 @@ class TestValidateCredentials:[("valid", 200, None, True),("bad_key", 401, None, False),+ # A 400 (the status users actually hit) is a deterministic client error, not transient.+ ("bad_request_at_create", 400, None, False),("missing_scope_at_create", 403, None, True),("missing_scope_at_schema", 403, "history", False),# An unverified key (transient 429/5xx) must not be saved as valid at create time.@@ -250,6 +252,15 @@ class TestValidateCredentials:ok, _msg = validate_credentials("k", schema_name)assert ok is expected_ok+ @mock.patch(SESSION_PATCH)+ def test_client_error_reads_as_invalid_key_not_retry(self, mts) -> None:+ # A 400 must not tell the user to "try again" — that only resolves for transient 429/5xx.+ mts.return_value.get.return_value = mock.MagicMock(status_code=400)+ ok, msg = validate_credentials("k")+ assert ok is False+ assert msg is not None+ assert "try again" not in msg.lower()+@mock.patch(SESSION_PATCH)def test_network_error_is_not_valid(self, mts) -> None:mts.return_value.get.side_effect = requests.ConnectionError("boom")