feat(auth): add anthropic api key storage and cli auth

This commit is contained in:
William Valentin
2026-02-14 00:43:12 -08:00
parent 0493660e7d
commit 4bb8c88fbe
7 changed files with 211 additions and 2 deletions
+8 -1
View File
@@ -3,6 +3,7 @@ import { AnthropicClient, OpenAIClient, OllamaClient, LlamaCppClient, GeminiClie
import type { ModelClient, RetryConfig, ModelTier } from '../models/index.js';
import { logger } from '../logger.js';
import { getZaiApiKey } from '../auth/zai.js';
import { getAnthropicApiKey } from '../auth/anthropic.js';
/**
* Resolve an API key from config or environment variable.
@@ -44,9 +45,15 @@ function resolveAuthCredential(cfg: ModelConfig, apiKeyEnvVar: string, authToken
export function createClientFromConfig(cfg: ModelConfig): ModelClient {
switch (cfg.provider) {
case 'anthropic':
if (!cfg.api_key && !getAnthropicApiKey()) {
throw new Error(
'Anthropic API key not configured. ' +
'Set ANTHROPIC_API_KEY, run `flynn anthropic-auth`, or provide api_key in config.',
);
}
return new AnthropicClient({
model: cfg.model,
apiKey: cfg.api_key,
apiKey: cfg.api_key ?? getAnthropicApiKey() ?? undefined,
authToken: cfg.auth_token,
});
case 'openai':