From dc6977d32e5511b24f6a403f609507e9cd19af19 Mon Sep 17 00:00:00 2001 From: Huynh Duc Dung Date: Thu, 22 Jan 2026 17:29:32 +0800 Subject: [PATCH] fix(api): skip API key prompt for local Ollama using noApiKey flag Local Ollama doesn't require an API key, but the CLI was still prompting for one. This adds a `noApiKey` flag to provider presets to mark providers that don't need authentication. - Add `noApiKey?: boolean` property to ProviderPreset interface - Set `noApiKey: true` for local Ollama (no key needed) - All other presets unchanged (default to requiring API key) - Skip API key prompt and show info message when noApiKey is true Co-Authored-By: Claude --- src/api/services/provider-presets.ts | 8 +++----- src/commands/api-command.ts | 5 ++--- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/api/services/provider-presets.ts b/src/api/services/provider-presets.ts index fd986a4d..0a518e3b 100644 --- a/src/api/services/provider-presets.ts +++ b/src/api/services/provider-presets.ts @@ -17,8 +17,8 @@ export interface ProviderPreset { apiKeyPlaceholder: string; apiKeyHint: string; category: PresetCategory; - /** Whether API key is required (false for local providers like Ollama) */ - requiresApiKey?: boolean; + /** Set to true for local providers that don't need API key */ + noApiKey?: boolean; /** Additional env vars for thinking mode, etc. */ extraEnv?: Record; /** Enable always thinking mode */ @@ -44,7 +44,6 @@ export const PROVIDER_PRESETS: ProviderPreset[] = [ apiKeyPlaceholder: 'sk-or-...', apiKeyHint: 'Get your API key at openrouter.ai/keys', category: 'recommended', - requiresApiKey: true, }, { id: 'ollama', @@ -56,7 +55,7 @@ export const PROVIDER_PRESETS: ProviderPreset[] = [ apiKeyPlaceholder: 'ollama', apiKeyHint: 'Install Ollama from ollama.com - no API key needed for local', category: 'recommended', - requiresApiKey: false, + noApiKey: true, }, // Alternative providers { @@ -156,7 +155,6 @@ 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 b7934bf7..0327978d 100644 --- a/src/commands/api-command.ts +++ b/src/commands/api-command.ts @@ -181,11 +181,10 @@ async function handleCreate(args: string[]): Promise { console.log(dim('Note: For OpenRouter, ANTHROPIC_API_KEY should be empty.')); } - // Step 3: API Key (skip if preset doesn't require one) + // Step 3: API Key (skip if preset has noApiKey flag) let apiKey = parsedArgs.apiKey; - const requiresApiKey = preset?.requiresApiKey !== false; - if (!requiresApiKey) { + if (preset?.noApiKey) { // 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