gitbutlerapp/gitbutler · error

Could not determine OpenAI credential source

Error message

Could not determine OpenAI credential source

What it means

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.

Solutions

  1. Re-run `but config ai` in an interactive terminal and choose a credential source
  2. Pre-set OpenAI credentials externally (e.g. OPENAI_API_KEY env var or git config) to avoid the interactive path
  3. Fix pty/terminal setup (use `ssh -t`, a capable TERM) if the prompt cannot capture input
  4. Complete the prompt rather than cancelling; cancelling surfaces this hard error by design

Example fix

// before: aborted prompt
but config ai  # cancel at 'Select OpenAI credential source' -> Error

// after: provide key via environment to skip interactive credential-source prompt
export OPENAI_API_KEY=sk-...
but config ai
Defensive patterns

Strategy: try-catch

Validate before calling

if [ -z "$OPENAI_API_KEY" ] && [ ! -t 0 ]; then echo "set OPENAI_API_KEY or run interactively"; exit 1; fi

Try / catch

match result {
    Err(e) if e.to_string().contains("OpenAI credential source") => {
        eprintln!("Credential-source prompt aborted; set OPENAI_API_KEY instead.");
    }
    r => r?,
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "Must pass :limit option" / "Missing required option" — required option errors explained — this error's family across 41 libraries.

Related errors


AI-assisted analysis of gitbutlerapp/gitbutler@58e5313667 (2026-09-18). Data as JSON: /api/errors/e75498b0f1f0f582. Report an issue: GitHub.

Appendix: source

Thrown at crates/but/src/command/config.rs:1559

        ("Ollama", LLMProviderKind::Ollama),
        ("LM Studio", LLMProviderKind::LMStudio),
        ("OpenRouter", LLMProviderKind::OpenRouter)
    ];
    let provider = inout
        .prompt_select("Select an AI provider", &providers)?
        .cloned()
        .ok_or_else(|| anyhow::anyhow!("Could not determine selected AI provider"))?;

    match provider {
        LLMProviderKind::OpenAi => {
            let key_options = nonempty::nonempty![
                ("Use GitButler API", AiKeyOption::ButlerApi),
                ("Bring your own key", AiKeyOption::BringYourOwn)
            ];
            let key_option = inout
                .prompt_select("Select OpenAI credential source", &key_options)?
                .copied()
                .ok_or_else(|| anyhow::anyhow!("Could not determine OpenAI credential source"))?;

            let model = inout.prompt("Preferred OpenAI model (leave empty for default):")?;
            let endpoint = inout.prompt("Custom endpoint URL (optional):")?;

            let secret = if matches!(key_option, AiKeyOption::BringYourOwn) {
                Some(
                    inout
                        .prompt_secret("Enter OpenAI API key:")?
                        .context("No API key provided. Aborting configuration.")?,
                )
            } else {
                None
            };

            apply_openai_config(repo, scope, key_option, model, endpoint, secret)?;
        }
        LLMProviderKind::Anthropic => {
            let key_options = nonempty::nonempty![

View on GitHub (pinned to 58e5313667)