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(elevenlabs): show the actionable invalid-key message for a rejected key (#121909)

Tom Owersf786da64ba30
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.py
index 9f26f423a3a1..2729e7a953b8 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
@@ -201,6 +201,12 @@ def _client_config(api_key: str, paginator: BasePaginator) -> ClientConfig:
}
+_INVALID_API_KEY_MESSAGE = (
+ "Your ElevenLabs API key is invalid or has been revoked. Create a new key in your "
+ "ElevenLabs account settings, then try again."
+)
+
+
def validate_credentials(api_key: str, schema_name: Optional[str] = None) -> tuple[bool, str | None]:
"""Probe the API key. 200 => valid. 401 => invalid key. 403 => valid key missing a scope.
@@ -233,11 +239,7 @@ def validate_credentials(api_key: str, schema_name: Optional[str] = None) -> tup
if status == 200:
return True, None
if status == 401:
- return (
- False,
- "Your ElevenLabs API key is invalid or has been revoked. Create a new key in your "
- "ElevenLabs account settings, then try again.",
- )
+ return False, _INVALID_API_KEY_MESSAGE
if status == 403:
if schema_name is None:
return True, None
@@ -246,7 +248,7 @@ def validate_credentials(api_key: str, schema_name: Optional[str] = None) -> tup
# 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"
+ return False, _INVALID_API_KEY_MESSAGE
# 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.py
index c9a1f8c9e59c..8b4fb4d18f91 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
@@ -380,6 +380,13 @@ class TestValidateCredentials:
assert validate_credentials("k", schema_name) == (True, None)
assert [request.url for request in network.requests_log] == [expected_url]
+ @parameterized.expand([("unauthorized", 401), ("bad_request", 400)])
+ def test_rejected_key_message_is_actionable(self, _name: str, status: int) -> None:
+ with scripted_network([ScriptedResponse(status=status)]):
+ ok, msg = validate_credentials("k")
+ assert ok is False
+ assert "Create a new key in your ElevenLabs account settings" in (msg or "")
+
def test_session_does_not_follow_redirects(self) -> None:
# requests keeps the custom xi-api-key header across a cross-origin 3xx; following one would
# replay the key to the redirect target, so the credentialed session must refuse redirects.