{"record":{"id":"e75498b0f1f0f582","repo":"gitbutlerapp/gitbutler","slug":"could-not-determine-openai-credential-source","errorCode":null,"errorMessage":"Could not determine OpenAI credential source","messagePattern":"Could not determine OpenAI credential source","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/but/src/command/config.rs","lineNumber":1559,"sourceCode":"        (\"Ollama\", LLMProviderKind::Ollama),\n        (\"LM Studio\", LLMProviderKind::LMStudio),\n        (\"OpenRouter\", LLMProviderKind::OpenRouter)\n    ];\n    let provider = inout\n        .prompt_select(\"Select an AI provider\", &providers)?\n        .cloned()\n        .ok_or_else(|| anyhow::anyhow!(\"Could not determine selected AI provider\"))?;\n\n    match provider {\n        LLMProviderKind::OpenAi => {\n            let key_options = nonempty::nonempty![\n                (\"Use GitButler API\", AiKeyOption::ButlerApi),\n                (\"Bring your own key\", AiKeyOption::BringYourOwn)\n            ];\n            let key_option = inout\n                .prompt_select(\"Select OpenAI credential source\", &key_options)?\n                .copied()\n                .ok_or_else(|| anyhow::anyhow!(\"Could not determine OpenAI credential source\"))?;\n\n            let model = inout.prompt(\"Preferred OpenAI model (leave empty for default):\")?;\n            let endpoint = inout.prompt(\"Custom endpoint URL (optional):\")?;\n\n            let secret = if matches!(key_option, AiKeyOption::BringYourOwn) {\n                Some(\n                    inout\n                        .prompt_secret(\"Enter OpenAI API key:\")?\n                        .context(\"No API key provided. Aborting configuration.\")?,\n                )\n            } else {\n                None\n            };\n\n            apply_openai_config(repo, scope, key_option, model, endpoint, secret)?;\n        }\n        LLMProviderKind::Anthropic => {\n            let key_options = nonempty::nonempty![","sourceCodeStart":1541,"sourceCodeEnd":1577,"githubUrl":"https://github.com/gitbutlerapp/gitbutler/blob/58e5313667b857ef39a730e380af31816a7b1768/crates/but/src/command/config.rs#L1541-L1577","documentation":"During OpenAI-specific setup inside `but config ai`, the CLI prompts for the credential source (GitButler proxy API vs bring-your-own key). `prompt_select` returning `None` (no answer) triggers this anyhow error, as the subsequent key/endpoint prompts depend on this choice.","triggerScenarios":"Cancelling or aborting the 'Select OpenAI credential source' prompt; running under a non-interactive stdin so prompt_select yields None; a terminal where the selection UI fails.","commonSituations":"Users backing out mid-way through OpenAI configuration; scripted runs of `but config ai` without a TTY; ssh sessions without proper pty where interactive selection cannot receive keystrokes.","solutions":["Re-run `but config ai` in an interactive terminal and choose a credential source","Pre-set OpenAI credentials externally (e.g. OPENAI_API_KEY env var or git config) to avoid the interactive path","Fix pty/terminal setup (use `ssh -t`, a capable TERM) if the prompt cannot capture input","Complete the prompt rather than cancelling; cancelling surfaces this hard error by design"],"exampleFix":"// before: aborted prompt\nbut config ai  # cancel at 'Select OpenAI credential source' -> Error\n\n// after: provide key via environment to skip interactive credential-source prompt\nexport OPENAI_API_KEY=sk-...\nbut config ai","handlingStrategy":"try-catch","validationCode":"if [ -z \"$OPENAI_API_KEY\" ] && [ ! -t 0 ]; then echo \"set OPENAI_API_KEY or run interactively\"; exit 1; fi","typeGuard":null,"tryCatchPattern":"match result {\n    Err(e) if e.to_string().contains(\"OpenAI credential source\") => {\n        eprintln!(\"Credential-source prompt aborted; set OPENAI_API_KEY instead.\");\n    }\n    r => r?,\n}","preventionTips":["Pre-set OPENAI_API_KEY so fewer interactive prompts appear","Avoid cancelling mid-way through the AI config wizard","Use ssh -t / proper pty in remote sessions"],"tags":["cli","interactive-prompt","openai","credentials"],"backgroundTag":"missing-required-option","analyzedSha":"58e5313667b857ef39a730e380af31816a7b1768","analyzedAt":"2026-09-18T06:50:32.052Z","contentChangedAt":"2026-09-18T06:50:32.052Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}