| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
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
| Back | FazBrowse Home | New Git URL |
Closes #734.
api_key defaults to os.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 no api_key was passed.
Why client.py and not the generated file. base_client.py is Fern output and a regen would drop the change. src/deepgram/client.py is in .fernignore, and AGENTS.md lists 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 same ApiError is raised.
Test added at tests/custom/test_api_key_env_resolution.py, registered in .fernignore and in the AGENTS.md frozen-files list. Verified non-vacuous: with the fix reverted, exactly one of the four fails. pytest tests/custom is 858 passed, 1 skipped; ruff check clean.