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 <noreply@anthropic.com>
This commit is contained in:
Huynh Duc Dung
2026-01-22 17:34:12 +08:00
co-authored by Claude
parent ef2c8bba12
commit dc6977d32e
2 changed files with 5 additions and 8 deletions
+3 -5
View File
@@ -17,8 +17,8 @@ export interface ProviderPreset {
apiKeyPlaceholder: string; apiKeyPlaceholder: string;
apiKeyHint: string; apiKeyHint: string;
category: PresetCategory; category: PresetCategory;
/** Whether API key is required (false for local providers like Ollama) */ /** Set to true for local providers that don't need API key */
requiresApiKey?: boolean; noApiKey?: boolean;
/** Additional env vars for thinking mode, etc. */ /** Additional env vars for thinking mode, etc. */
extraEnv?: Record<string, string>; extraEnv?: Record<string, string>;
/** Enable always thinking mode */ /** Enable always thinking mode */
@@ -44,7 +44,6 @@ export const PROVIDER_PRESETS: ProviderPreset[] = [
apiKeyPlaceholder: 'sk-or-...', apiKeyPlaceholder: 'sk-or-...',
apiKeyHint: 'Get your API key at openrouter.ai/keys', apiKeyHint: 'Get your API key at openrouter.ai/keys',
category: 'recommended', category: 'recommended',
requiresApiKey: true,
}, },
{ {
id: 'ollama', id: 'ollama',
@@ -56,7 +55,7 @@ export const PROVIDER_PRESETS: ProviderPreset[] = [
apiKeyPlaceholder: 'ollama', apiKeyPlaceholder: 'ollama',
apiKeyHint: 'Install Ollama from ollama.com - no API key needed for local', apiKeyHint: 'Install Ollama from ollama.com - no API key needed for local',
category: 'recommended', category: 'recommended',
requiresApiKey: false, noApiKey: true,
}, },
// Alternative providers // Alternative providers
{ {
@@ -156,7 +155,6 @@ export const PROVIDER_PRESETS: ProviderPreset[] = [
apiKeyPlaceholder: 'YOUR_OLLAMA_CLOUD_API_KEY', apiKeyPlaceholder: 'YOUR_OLLAMA_CLOUD_API_KEY',
apiKeyHint: 'Get your API key at ollama.com', apiKeyHint: 'Get your API key at ollama.com',
category: 'alternative', category: 'alternative',
requiresApiKey: true,
}, },
]; ];
+2 -3
View File
@@ -181,11 +181,10 @@ async function handleCreate(args: string[]): Promise<void> {
console.log(dim('Note: For OpenRouter, ANTHROPIC_API_KEY should be empty.')); 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; let apiKey = parsedArgs.apiKey;
const requiresApiKey = preset?.requiresApiKey !== false;
if (!requiresApiKey) { if (preset?.noApiKey) {
// Preset doesn't require API key (e.g., local Ollama) // Preset doesn't require API key (e.g., local Ollama)
console.log(info('No API key required for local Ollama')); console.log(info('No API key required for local Ollama'));
apiKey = ''; // Empty string for local providers apiKey = ''; // Empty string for local providers