fix: resolve DEEPGRAM_API_KEY when the client is constructed (closes #734) - #767
Open
Kayvan-Zahiri wants to merge 1 commit into
Open
fix: resolve DEEPGRAM_API_KEY when the client is constructed (closes #734)#767Kayvan-Zahiri wants to merge 1 commit into
Kayvan-Zahiri wants to merge 1 commit into
Conversation
The generated base client takes os.getenv("DEEPGRAM_API_KEY") as a default
argument, so Python evaluates it once at import. The idiomatic layout of
imports at the top and load_dotenv() below them therefore fails: the default
is captured as None before the key exists, and DeepgramClient() raises even
though the variable is set by the time it is called.
client.py is permanently frozen in .fernignore, so the re-read goes there
rather than in the generated file.
Closes deepgram#734
Kayvan-Zahiri
requested review from
GregHolmes,
deepgram-kiley and
dg-coreylweathers
as code owners
August 17, 2026 23:42
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.
Closes #734.
api_keydefaults toos.getenv("DEEPGRAM_API_KEY")in the generated base client's signature (base_client.py:78,:254). Python evaluates default arguments once, at import, so the idiomatic layout fails:The fix re-reads the variable in
DeepgramClient.__init__/AsyncDeepgramClient.__init__when noapi_keywas passed.Why
client.pyand not the generated file.base_client.pyis Fern output and a regen would drop the change.src/deepgram/client.pyis in.fernignore, andAGENTS.mdlists it under "Never unfreeze (permanently frozen)", so it is the durable place for this.Behaviour that does not change, each covered by a test: an explicit
api_key=still wins over the environment,access_token=still takes precedence and still gets the"token"placeholder, and with no key anywhere the sameApiErroris raised.Test added at
tests/custom/test_api_key_env_resolution.py, registered in.fernignoreand in theAGENTS.mdfrozen-files list. Verified non-vacuous: with the fix reverted, exactly one of the four fails.pytest tests/customis 858 passed, 1 skipped;ruff checkclean.