Skip to content

fix(auth): resolve environment token when constructing clients (proof of concept) - #34

Draft
Kayvan-Zahiri wants to merge 1 commit into
Speechify-AI:mainfrom
Kayvan-Zahiri:codex/runtime-environment-token
Draft

Kayvan-Zahiri wants to merge 1 commit into
Speechify-AI:mainfrom
Kayvan-Zahiri:codex/runtime-environment-token

Conversation

@Kayvan-Zahiri

Copy link
Copy Markdown

Proof of concept for #33; this generated-code change needs to be ported into the API definition/generator before it can survive regeneration. It is not merge-ready as-is. No generated source is added to .fernignore and no release/version/publish configuration is changed.

Speechify and AsyncSpeechify capture SPEECHIFY_API_KEY while importing the module because os.getenv is a parameter default. Loading dotenv or retrieving a secret after importing therefore fails to authenticate a new client. Updating or removing the variable after import also leaves new clients using the old key.

Default token to None and resolve the environment inside each constructor when no explicit token is supplied. Explicit string and callable tokens keep precedence.

Twelve offline public-client cases cover both clients with late, replaced, removed and absent environment keys plus explicit-string/callable controls. Six fail on the original source. All 78 tests pass afterward, with four optional/unimplemented tests skipped. httpx.MockTransport verifies the Authorization header on actual models requests; no live service or real key is used. Full Ruff lint/format (106 files), mypy (106 source files, one informational untyped-body note), wheel/sdist build and diff checks pass. Developed with AI assistance and verified locally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant