diff --git a/src/api/services/provider-presets.ts b/src/api/services/provider-presets.ts index 7a70a61a..fd986a4d 100644 --- a/src/api/services/provider-presets.ts +++ b/src/api/services/provider-presets.ts @@ -17,6 +17,8 @@ export interface ProviderPreset { apiKeyPlaceholder: string; apiKeyHint: string; category: PresetCategory; + /** Whether API key is required (false for local providers like Ollama) */ + requiresApiKey?: boolean; /** Additional env vars for thinking mode, etc. */ extraEnv?: Record; /** Enable always thinking mode */ @@ -42,6 +44,7 @@ export const PROVIDER_PRESETS: ProviderPreset[] = [ apiKeyPlaceholder: 'sk-or-...', apiKeyHint: 'Get your API key at openrouter.ai/keys', category: 'recommended', + requiresApiKey: true, }, { id: 'ollama', @@ -53,6 +56,7 @@ export const PROVIDER_PRESETS: ProviderPreset[] = [ apiKeyPlaceholder: 'ollama', apiKeyHint: 'Install Ollama from ollama.com - no API key needed for local', category: 'recommended', + requiresApiKey: false, }, // Alternative providers { @@ -152,6 +156,7 @@ export const PROVIDER_PRESETS: ProviderPreset[] = [ apiKeyPlaceholder: 'YOUR_OLLAMA_CLOUD_API_KEY', apiKeyHint: 'Get your API key at ollama.com', category: 'alternative', + requiresApiKey: true, }, ]; diff --git a/src/commands/api-command.ts b/src/commands/api-command.ts index a96707a0..b7934bf7 100644 --- a/src/commands/api-command.ts +++ b/src/commands/api-command.ts @@ -181,9 +181,15 @@ async function handleCreate(args: string[]): Promise { console.log(dim('Note: For OpenRouter, ANTHROPIC_API_KEY should be empty.')); } - // Step 3: API Key + // Step 3: API Key (skip if preset doesn't require one) let apiKey = parsedArgs.apiKey; - if (!apiKey) { + const requiresApiKey = preset?.requiresApiKey !== false; + + if (!requiresApiKey) { + // Preset doesn't require API key (e.g., local Ollama) + console.log(info('No API key required for local Ollama')); + apiKey = ''; // Empty string for local providers + } else if (!apiKey) { const keyPrompt = preset?.apiKeyHint ? `API Key (${preset.apiKeyHint})` : 'API Key'; apiKey = await InteractivePrompt.password(keyPrompt); if (!apiKey) {