Add API keys in settings.json, fixes #295

This commit is contained in:
Mario Zechner 2025-12-24 02:11:17 +01:00
parent e234e8d18f
commit bb1da1ec51
4 changed files with 72 additions and 20 deletions

View file

@ -258,10 +258,16 @@ If no model is provided:
### API Keys
API key resolution priority:
1. `settings.json` apiKeys (e.g., `{ "apiKeys": { "anthropic": "sk-..." } }`)
2. Custom providers from `models.json`
3. OAuth credentials from `oauth.json`
4. Environment variables (`ANTHROPIC_API_KEY`, `OPENAI_API_KEY`, etc.)
```typescript
import { defaultGetApiKey, configureOAuthStorage } from "@mariozechner/pi-coding-agent";
// Default: checks models.json, OAuth, environment variables
// Default: checks settings.json, models.json, OAuth, environment variables
const { session } = await createAgentSession();
// Custom resolver
@ -271,7 +277,7 @@ const { session } = await createAgentSession({
if (model.provider === "anthropic") {
return process.env.MY_ANTHROPIC_KEY;
}
// Fall back to default
// Fall back to default (pass settingsManager for settings.json lookup)
return defaultGetApiKey()(model);
},
});