Repository navigation
Description
Summary
Today provider API keys are only picked up from the system environment or a .env file in the current project directory. Every new project requires copying the same keys into another .env, and running infer outside a project with a .env means no providers work.
Add a userspace fallback: ~/.infer/auth.json, a flat JSON map of provider key env vars, read when a key is not supplied by a higher-precedence source.
{
"ANTHROPIC_API_KEY": "sk-ant-...",
"OPENAI_API_KEY": "sk-...",
"GROQ_API_KEY": "gsk_..."
}Current behavior
Provider keys are resolved in three independent places, all of which only know about the project .env and os.Environ():
internal/gateway/manager.gorunContainer()- passes--env-file .env(if present) plus a hardcodedapiKeyEnvVarsallowlist read fromos.Getenv.internal/gateway/manager.goloadEnvironment()- binary mode; merges.envlines intoos.Environ().internal/agent/application/agent_manager.goloadDotEnvFile()- A2A agent containers; reads./.envonly.
Proposed behavior
Precedence per key (first hit wins), applied to the existing apiKeyEnvVars allowlist:
- System environment variable
- Project
.env ~/.infer/auth.json(new fallback)
Implement the auth.json read once in a shared helper (e.g. in config/) and use it from all three resolution paths above, so the fallback behaves identically for the gateway container, gateway binary mode, and A2A agent containers.
Notes:
- Missing or unreadable
~/.infer/auth.jsonis not an error; silently skip (log at debug). - Warn if the file permissions are broader than
0600, matching common credential-file conventions. - The sandbox
ProtectedPathsinconfig/config.goalready listsauth.json, so agent tools cannot read or edit it; no changes needed there. - Flat env-var-name keys keep this a pure fallback source - no new provider name mapping, no schema beyond
map[string]string.
Out of scope
- An
infer auth login/infer auth setcommand to manage the file (can be a follow-up; the file is trivially hand-editable). - OS keychain/keyring integration.
- Non-key configuration in auth.json (gateway URL, models, etc. stay in config.yaml).
Acceptance Criteria
- With no project
.envand no exported keys, keys in~/.infer/auth.jsonare passed to the gateway (both containerdocker run -eand binary mode) and to A2A agent containers. - A key present in the system env or project
.envalways wins over the same key inauth.json. - A missing, empty, or malformed
~/.infer/auth.jsondegrades gracefully: no crash, existing behavior unchanged, debug log only (warn on malformed). - Unit tests cover the precedence order and the missing/malformed-file cases.
- README/docs mention
~/.infer/auth.jsonand the precedence order.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
[-][FEATURE] Fallback to ~/.infer/auth.json for authentication if no .env in the project folder[/-][+][FEATURE] Fallback to ~/.infer/auth.json for provider keys if no .env in the project folder[/+][-][FEATURE] Fallback to ~/.infer/auth.json for provider keys if no .env in the project folder[/-][+][FEATURE] Fallback to ~/.infer/auth.json for providers keys if no .env in the project folder[/+][-][FEATURE] Fallback to ~/.infer/auth.json for providers keys if no .env in the project folder[/-][+]feat: Fallback to ~/.infer/auth.json for provider keys when no project .env[/+][-]feat: Fallback to ~/.infer/auth.json for provider keys when no project .env[/-][+][FEATURE] Fallback to ~/.infer/auth.json for provider keys when no project .env[/+]edenreich commentedon Sep 3, 2026
@infer Can you work on this? use /go /ponytail:ponytail
inference-gateway-maintainer commentedon Sep 3, 2026
Model:
ollama_cloud/glm-5.3-flash· View JobTodos
Pull Request
#1169
✅ Infer Result: Success
All work is complete. Issue #1167 is implemented, tested, and PR #1169 is ready for review.
Summary
Implemented the
~/.infer/auth.jsonuserspace fallback for provider API keys (PR #1169, resolves #1167).Precedence per key (first hit wins): system environment > project
.env>~/.infer/auth.jsonWhat changed:
config/auth.go- shared loader:AuthFilePath()+LoadAuthKeys(), a flatmap[string]stringread of~/.infer/auth.json. Missing/unreadable/empty files degrade silently; malformed JSON drops everything (no partial trust) and warns; permissions broader than0600warn.configcan't import the platform logger (the logger importsconfig), so warnings are returned for callers to log.manager.gorunContainer()) -.envstill goes via--env-file;-eis now also passed for keys resolved fromauth.json, but never for keys present in.env, so the project.envalways beats the fallback and the system env still wins.loadEnvironment()) - explicit precedence via first-hit dedup (system env, then.env, thenauth.json), making it deterministic and consistent with container mode.agent_manager.go) -auth.jsonis the final fallback for agent-declared env keys (after.env, system env, and the agent's own config value). The resolution loop was extracted intoresolveAgentEnvso the order is unit-testable without docker.config/auth_test.go(missing/empty/malformed/valid/broad-perms/unreadable),internal/gateway/manager_env_test.go(binary-mode precedence incl. system >.env>auth.json),TestResolveAgentEnv(A2A order).docs/configuration-reference.mddocument the file, its precedence order,chmod 600, and sandbox protection.Verification:
task precommit:run(gofmt, imports, golangci-lint 0 issues, markdownlint) andgo test -race -tags puregoon the touched packages all pass; tree is clean and pushed. Board #7 status set to QA. Docs-site mirror ticket opened at inference-gateway/docs#642.Skipped:
infer auth logincommand and keychain integration (explicitly out of scope in the issue; the file is hand-editable).Model:
ollama_cloud/glm-5.3-flash· Exit Code:0· Duration: 14m 14sTokens: 7,699,077 in · 51,925 out · 7,751,002 total (58 requests)
Tool calls: 83 total · 100% success rate
Traces
Stats
Triggered by edenreich · Infer Action · OSS
feat(auth): add ~/.infer/auth.json as userspace provider key fallback (…
inference-gateway-releaser commentedon Sep 4, 2026
🎉 This issue has been resolved in version 0.189.0 🎉
The release is available on:
Your semantic-release bot 📦🚀