Hmbown/CodeWhale · error

Ollama Cloud API key not found. Get a key

Error message

Ollama Cloud API key not found. Get a key: {}. Run 'codewhale auth set --provider ollama', set OLLAMA_API_KEY, or add [providers.ollama] api_key in ~/.codewhale/config.toml.

What it means

Thrown when the Ollama provider is selected but no Ollama Cloud API key is configured. The config layer builds the error using credential_help_for_provider_route so the displayed key URL matches the active route's base URL, defaulting to OLLAMA_CLOUD_API_KEY_URL. It fails loud because an Ollama Cloud request without a key would be rejected upstream.

Solutions

  1. Set the OLLAMA_API_KEY environment variable
  2. Run `codewhale auth set --provider ollama`
  3. Add `api_key = "..."` under [providers.ollama] in ~/.codewhale/config.toml
  4. Get a key from the URL shown in the error (OLLAMA_CLOUD_API_KEY_URL or route-specific)

Example fix

// before
[providers.ollama]
// after
[providers.ollama]
api_key = "your-ollama-cloud-key"
Defensive patterns

Strategy: validation

Validate before calling

let ok = std::env::var("OLLAMA_API_KEY").map(|v| !v.trim().is_empty()).unwrap_or(false);
if !ok { eprintln!("Ollama Cloud key missing: set OLLAMA_API_KEY or [providers.ollama] api_key"); }
else { /* proceed */ }

Try / catch

match result {
    Err(e) if e.to_string().contains("Ollama Cloud API key not found") => configure_ollama_key_and_retry(),
    other => other?,
}

Prevention

When it happens

Trigger: Using provider `ollama` (Ollama Cloud route) when OLLAMA_API_KEY is unset and [providers.ollama] has no api_key in ~/.codewhale/config.toml.

Common situations: Local Ollama users pointing at Ollama Cloud models without realizing the cloud route needs a key; CI environments lacking the env var; typos in the env var name in config.

Understand the failure class

Background: "API key is required" / "API key not found" / "No API key was set": the missing-api-key error family across 16 libraries — this error's family across 16 libraries.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22). Data as JSON: /api/errors/fd3659670ba4ced1. Report an issue: GitHub.

Appendix: source

Thrown at crates/tui/src/config.rs:7410

            }
            ApiProvider::OpenaiCodex => anyhow::bail!(
                "{}",
                crate::oauth::missing_auth_message(crate::oauth::OAuthProvider::Chatgpt)
            ),
            ApiProvider::Xai => {
                // Prefer OAuth guidance when auth_mode requests it or Grok CLI
                // tokens already exist; otherwise show both API-key and OAuth.
                if self
                    .provider_config_for(provider)
                    .is_some_and(provider_config_uses_xai_oauth)
                    || crate::oauth::credentials_present(crate::oauth::OAuthProvider::Xai, self)
                {
                    anyhow::bail!(
                        "{}",
                        crate::oauth::missing_auth_message(crate::oauth::OAuthProvider::Xai)
                    );
                }
                anyhow::bail!(
                    "xAI API key not found. Get a key: https://console.x.ai/\n\
                     Run 'codewhale auth set --provider xai', set XAI_API_KEY, or add \
                     [providers.xai] api_key.\n\
                     OAuth alternative: run `codewhale auth xai-device` for \
                     Codewhale-owned storage and set [providers.xai] auth_mode = \"oauth\"."
                );
            }
            // Self-hosted deployments commonly run without auth on localhost.
            // Return an empty key and let the client omit the Authorization header.
            ApiProvider::Sglang | ApiProvider::Vllm => Ok(String::new()),
            ApiProvider::Ollama
                if provider_route_is_keyless_self_hosted(
                    provider,
                    &self.active_route_base_url(),
                ) =>
            {
                Ok(String::new())
            }

View on GitHub (pinned to 73e0f67d83)