Environment variables¶
The module reads four environment variables, and only under the conditions
below. Everything else in chat.Config is set in code, because the module owns
no config system. A host maps its own configuration into chat.Config and
passes it in.
The variables¶
| Variable | Constant | Read when | Effect |
|---|---|---|---|
AI_PROVIDER |
chat.EnvAIProvider |
Config.Provider is empty |
names the provider; an unregistered name is then fatal with unsupported provider: <name> |
ANTHROPIC_API_KEY |
chatanthropic.EnvClaudeKey |
Config.Token and Config.Credentials resolved nothing, on ProviderClaude |
supplies the API key |
OPENAI_API_KEY |
chatopenai.EnvOpenAIKey |
Config.Token and Config.Credentials resolved nothing, on ProviderOpenAI |
supplies the API key |
GEMINI_API_KEY |
chatgemini.EnvGeminiKey |
Config.Token and Config.Credentials resolved nothing, on ProviderGemini |
supplies the API key |
Plus any variable you name: Config.Credentials.Env holds the name of an
environment variable to read the key from, which is how a host keeps the secret
out of its config file while keeping the reference in it.
Where each sits in the credential cascade¶
The three well-known key variables are the last step, not the first. In order, the first non-empty source wins:
Config.Token- the variable named by
Config.Credentials.Env - the keychain reference in
Config.Credentials.Keychain - the literal in
Config.Credentials.Key - the provider's well-known variable from the table above
Every value is whitespace-trimmed and an empty result falls through, so a variable that exists but is blank cannot mask a working source below it.
Why AI_PROVIDER has no prefix¶
AI_PROVIDER is deliberately unprefixed and deliberately narrow. It is an
ecosystem-wide default (the same variable across tools built on this module)
and it is consulted only when Config.Provider is empty, so it can never
override a provider a caller actually set. There is no AI_MODEL,
AI_BASE_URL or CHAT_* equivalent: everything else is host configuration, and
inventing a parallel environment schema here would fight whatever the host
already has.
Variables used only when running this module's own tests¶
| Variable | Effect |
|---|---|
INT_TEST=1 |
runs every integration test |
INT_TEST_CHAT=1 |
runs the integration tests tagged chat |
Integration tests are gated by environment variable rather than build tag, so they stay compiled and discoverable in an IDE. Without one of these set they skip.
Related¶
- Configuration fields: everything else, which is set in code.
- Choose & configure a provider: the credential cascade in practice.
- Provider-endpoint & credential security: why the reference is in config and the secret is not.