fix(speech-engine): strip residency suffix from API key before JWT verification - #873
Conversation
…rification The API signs Speech Engine upstream JWTs with sha256 of the base API key, stripping any `_residency_<region>` suffix first. The SDK hashed the key verbatim, so any EU/IN/SG residency key failed the handshake with "Invalid JWT: signature mismatch". Normalize the key the same way before hashing. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
PR SummaryMedium Risk Overview
Tests add acceptance for a residency-configured key against a token signed with the base key, and rejection when the base key does not match. Reviewed by Cursor Bugbot for commit 7a9be94. Bugbot is set up for automated code reviews on this repo. Configure here. |
Summary
Speech Engine servers configured with a data-residency API key (for example
sk_..._residency_in) rejected every upstream connection with "Invalid JWT: signature mismatch". The API signs the handshake JWT with a hash of the base key, with the_residency_<region>suffix removed, but the SDK hashed the key exactly as given. The SDK now strips the suffix the same way before hashing, so residency keys work without the workaround of passing a hand-trimmed key to the server.Details
_residency_[a-z0-9]+$rather than an enumerated region list, so a new region does not need an SDK release. The backend issues the keys, so an unknown suffix should not occur in practice.nextbranch so the next major release includes it. JS counterpart: fix(speech-engine): strip residency suffix from API key before JWT verification elevenlabs-js#458.Testing
pytest tests/test_speech_engine_auth.py: 24 passed, including two new cases (residency key verifies against a token signed with the base key; residency key with the wrong base key is still rejected).🤖 Generated with Claude Code