fix: resolve api_key from env var with runtime assertion#763
Closed
kraenhansen wants to merge 4 commits intomainfrom
Closed
fix: resolve api_key from env var with runtime assertion#763kraenhansen wants to merge 4 commits intomainfrom
kraenhansen wants to merge 4 commits intomainfrom
Conversation
The upcoming SDK regeneration (#761) makes api_key required in the generated base client. This updates the wrapper to resolve api_key from the parameter or ELEVENLABS_API_KEY env var, raising a clear error if neither is set — keeping the public API backwards-compatible. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 18e76d2. Configure here.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…n by env var Addresses review feedback: `api_key or os.getenv(...)` treated an explicitly-passed empty string the same as None, silently falling through to the env var. Now uses `is not None` so only an unset parameter falls back. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This test only checks that the import/attribute chain works, not API calls. Use a non-empty dummy key to satisfy the new validation. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Member
Author
|
Closing this as obsolete with https://github.com/elevenlabs/elevenlabs-dx/pull/2097 merged. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
api_keyrequired in the generated base client_resolve_api_key()helper that resolves from the parameter orELEVENLABS_API_KEYenv var, raising a clearValueErrorif neither is setsrc/elevenlabs/client.py(in.fernignore) andtests/test_client_init.py— no generated code modifiedapi_keyremainsOptional[str]onElevenLabsandAsyncElevenLabsapi_key=os.getenv("ELEVENLABS_API_KEY")default was evaluated once at import time, so env var changes after import were silently ignored. The env var is now read fresh on every client construction.Mirrors the approach from elevenlabs-js#368.
Test plan
ElevenLabs(api_key="key")— works as beforeElevenLabs()withELEVENLABS_API_KEYenv var set — resolves from envElevenLabs()without env var — raises clearValueError_resolve_api_key,ElevenLabs, andAsyncElevenLabs(11 tests)api_key: strrequired in base)🤖 Generated with Claude Code
Note
Medium Risk
Changes how
ElevenLabs/AsyncElevenLabsobtain and validate API keys, which can break callers that relied on empty/missing keys or import-time env evaluation. Risk is limited to client construction/auth header setup and is covered by new unit tests.Overview
API key handling is now resolved at runtime.
ElevenLabsandAsyncElevenLabsno longer defaultapi_keyfromos.getenv(...)at import time; instead they call a new internal_resolve_api_key()on construction to use the passed value or fall back toELEVENLABS_API_KEY.Missing/empty keys now fail fast.
_resolve_api_key()raises a clearValueErrorwhen neither an explicit key nor a non-empty env var is available (and treats""as invalid), with new tests validating precedence and error cases; a convai import test was updated to stop passing an empty key.Reviewed by Cursor Bugbot for commit 6709ca1. Bugbot is set up for automated code reviews on this repo. Configure here.