{"record":{"id":"39b3e2c588afd89b","repo":"thedotmack/claude-mem","slug":"non-interactive-providerlabel-configuration-is","errorCode":null,"errorMessage":"Non-interactive ${providerLabel} configuration is missing a personal API key.","messagePattern":"Non-interactive (.+?) configuration is missing a personal API key\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/npx-cli/commands/install.ts","lineNumber":1213,"sourceCode":"  const providerLabel = selectedProvider === 'gemini' ? 'Gemini' : 'OpenRouter';\n  const keyEnvName = selectedProvider === 'gemini'\n    ? 'CLAUDE_MEM_GEMINI_API_KEY'\n    : 'CLAUDE_MEM_OPENROUTER_API_KEY';\n\n  const existingKey = getSetting(keyEnvName as keyof SettingsDefaults) as string | undefined;\n  const existingOpenRouterBaseUrl = selectedProvider === 'openrouter'\n    ? String(getSetting('CLAUDE_MEM_OPENROUTER_BASE_URL') ?? '')\n    : '';\n  const existingKeyIsCmem = selectedProvider === 'openrouter'\n    && isCmemGatewayUrl(existingOpenRouterBaseUrl);\n  if (existingKey && existingKey.trim().length > 0 && !existingKeyIsCmem) {\n    const wrote = mergeSettings({ CLAUDE_MEM_PROVIDER: selectedProvider });\n    if (wrote) log.info(`Saved provider=${selectedProvider} to ~/.claude-mem/settings.json`);\n    return selectedProvider;\n  }\n\n  if (!isInteractive) {\n    throw new Error(`Non-interactive ${providerLabel} configuration is missing a personal API key.`);\n  }\n\n  const apiKeyResult = await p.password({\n    message: `Paste your ${providerLabel} API key:`,\n    mask: '*',\n    validate: (v?: string) => (!v || v.trim().length === 0) ? 'API key required' : undefined,\n  });\n\n  if (p.isCancel(apiKeyResult)) {\n    log.warn(`API key prompt cancelled — falling back to Claude provider.`);\n    persistClaudeProvider();\n    return 'claude';\n  }\n\n  const apiKey = String(apiKeyResult).trim();\n  const updates = selectedProvider === 'openrouter'\n    ? buildPersonalOpenRouterSettings(\n      apiKey,","sourceCodeStart":1195,"sourceCodeEnd":1231,"githubUrl":"https://github.com/thedotmack/claude-mem/blob/d8bc9755e74915e5c3b999181e10a67c889bce2a/src/npx-cli/commands/install.ts#L1195-L1231","documentation":"Non-'claude' providers (OpenRouter/OpenAI-compatible) need a personal API key. In non-interactive mode there is no password prompt to collect one, so install throws this error when no key is available from settings/env for the selected provider. Interactive sessions instead prompt the user for the key.","triggerScenarios":"Running non-interactive install with --provider set to a key-based provider while the provider's API key is absent from settings (~/.claude-mem/settings.json) and environment, and isInteractive is false.","commonSituations":"CI/automation installs that set --provider openrouter but forgot the key env/settings; key stored under the wrong settings field name; fresh machine without migrated settings.","solutions":["Provide the key non-interactively: set the provider's API key in ~/.claude-mem/settings.json or the corresponding env var before running install.","Run install in an interactive terminal so the password prompt can collect the key.","Verify the key field name matches what the selected provider expects (e.g. CLAUDE_MEM_OPENROUTER_API_KEY)."],"exampleFix":"# before\ncmem install --provider openrouter --yes   # no key anywhere\n# after\nprintf '{\"CLAUDE_MEM_OPENROUTER_API_KEY\":\"sk-or-v1-...\"}' > ~/.claude-mem/settings.json\ncmem install --provider openrouter --yes","handlingStrategy":"validation","validationCode":"const key = settings.CLAUDE_MEM_OPENROUTER_API_KEY ?? process.env.CLAUDE_MEM_OPENROUTER_API_KEY;\nif (!process.stdin.isTTY && provider !== 'claude' && !key) throw new Error(`non-interactive ${provider} install needs an API key in settings/env`);","typeGuard":"const hasKey = (s: SettingsLike): s is SettingsLike & { [k: string]: string } => typeof s.CLAUDE_MEM_OPENROUTER_API_KEY === 'string' && s.CLAUDE_MEM_OPENROUTER_API_KEY.length > 0;","tryCatchPattern":"try { await install(options); } catch (e) { if (e.message.includes('missing a personal API key')) { writeKeyToSettings(await promptForKeyElsewhere()); await install(options); } else throw e; }","preventionTips":["Seed settings.json or env with the key before automated installs","Keep key field names consistent across machines (dotfiles/config management)","Smoke-test installs with `cmd < /dev/null` to catch missing non-interactive inputs"],"tags":["cli","api-key","non-interactive"],"backgroundTag":"missing-api-key","analyzedSha":"d8bc9755e74915e5c3b999181e10a67c889bce2a","analyzedAt":"2026-09-17T16:40:26.182Z","contentChangedAt":"2026-09-17T16:40:26.182Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}