feat(auth): add anthropic api key storage and cli auth
This commit is contained in:
@@ -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':
|
||||
|
||||
Reference in New Issue
Block a user