gitbutlerapp/gitbutler · error

Could not determine Anthropic credential source

Error message

Could not determine Anthropic credential source

What it means

Analogous to the OpenAI path: when configuring Anthropic in `but config ai`, the 'Select Anthropic credential source' prompt returning `None` raises this anyhow error, since model and key prompts depend on the selected `AiKeyOption`.

Solutions

  1. Re-run `but config ai` in an interactive terminal and complete the Anthropic selection
  2. Configure the Anthropic key non-interactively (env var such as ANTHROPIC_API_KEY or the git-config keys the provider reads) to bypass the prompt
  3. Fix terminal/pty environment so the select prompt can capture input
  4. Pick a credential source and continue instead of cancelling; cancellation maps to this error

Example fix

// before: cancelling at the Anthropic prompt
but config ai  # Error: Could not determine Anthropic credential source

// after: non-interactive alternative via environment
export ANTHROPIC_API_KEY=sk-ant-...
but config ai
Defensive patterns

Strategy: try-catch

Validate before calling

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

Try / catch

match result {
    Err(e) if e.to_string().contains("Anthropic credential source") => {
        eprintln!("Anthropic credential prompt aborted; set key via env instead.");
    }
    r => r?,
}

Prevention

When it happens

Trigger: User cancels/aborts the Anthropic credential-source selection; prompt runs with non-interactive stdin so prompt_select yields None; broken terminal select UI.

Common situations: Mid-setup cancellation in `but config ai`; CI/scripted invocations without TTY; remote shells without pty allocation breaking the picker.

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/89c39ca6422e164a. Report an issue: GitHub.

Appendix: source

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

                        .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![
                ("Use GitButler API", AiKeyOption::ButlerApi),
                ("Bring your own key", AiKeyOption::BringYourOwn)
            ];
            let key_option = inout
                .prompt_select("Select Anthropic credential source", &key_options)?
                .copied()
                .ok_or_else(|| {
                    anyhow::anyhow!("Could not determine Anthropic credential source")
                })?;

            let model = inout.prompt("Preferred Anthropic model (leave empty for default):")?;
            let secret = if matches!(key_option, AiKeyOption::BringYourOwn) {
                Some(
                    inout
                        .prompt_secret("Enter Anthropic API key:")?
                        .context("No API key provided. Aborting configuration.")?,
                )
            } else {
                None
            };

            apply_anthropic_config(repo, scope, key_option, model, secret)?;
        }
        LLMProviderKind::Ollama => {
            let endpoint = inout.prompt("Ollama endpoint host:port (optional):")?;
            let model = inout.prompt("Preferred Ollama model (optional):")?;

View on GitHub (pinned to 58e5313667)