Hmbown/CodeWhale · error

SiliconFlow China API key not found. Get a key

Error message

SiliconFlow China API key not found. Get a key: {}. Run 'codewhale auth set --provider siliconflow-CN', set {}, or add [{}] api_key in ~/.codewhale/config.toml. [providers.siliconflow] remains a fallback when the CN table omits api_key.

What it means

The SiliconFlow China (siliconflow-CN) route requires its own API key. The resolver first consults the CN provider table; if it finds no key there it fails, noting that [providers.siliconflow] (the global endpoint) still acts as a fallback when the CN table omits api_key.

Solutions

  1. Get a key at https://cloud.siliconflow.com/account/ak and run: codewhale auth set --provider siliconflow-CN
  2. Set the SiliconFlow CN env var shown in the error in the launching shell.
  3. Add [providers.siliconflow-CN] api_key = "..." in ~/.codewhale/config.toml.
  4. Or ensure [providers.siliconflow] has api_key so the documented fallback applies when the CN table omits api_key.

Example fix

// before
[providers.siliconflow-CN]
base_url = "https://api.siliconflow.cn/v1"

// after
[providers.siliconflow-CN]
base_url = "https://api.siliconflow.cn/v1"
api_key = "sk-..."
Defensive patterns

Strategy: validation

Validate before calling

fn cn_route_has_key(cfg: &toml::Value) -> bool {
    cfg.get("providers").map(|p| {
        p.get("siliconflow-CN").and_then(|c| c.get("api_key")).is_some()
            || p.get("siliconflow").and_then(|c| c.get("api_key")).is_some()
    }).unwrap_or(false)
}

Try / catch

match result {
    Err(e) if e.to_string().contains("SiliconFlow China API key not found") => {
        eprintln!("create a China-region key at cloud.siliconflow.com and add [providers.siliconflow-CN] api_key");
    }
    other => other?,
}

Prevention

When it happens

Trigger: Provider resolves to ApiProvider::SiliconflowCn and neither the CN provider table, the SiliconFlow CN env var, nor config api_key supplies a credential.

Common situations: Users of the global SiliconFlow endpoint switching to the China region without creating a China-region key (the two regions use separate accounts/keys); env var typo'd or set only in an interactive shell.

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

Appendix: source

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

                    .credential_url()
                    .unwrap_or("https://app.codewhale.net/settings?section=api")
            ),
            ApiProvider::Deepseek | ApiProvider::DeepseekCN => anyhow::bail!(
                "DeepSeek API key not found.\n\
                 \n\
                 1. Get a key:  https://platform.deepseek.com/api_keys\n\
                 2. Save it (works in every folder, no OS prompts):\n\
                        codewhale auth set --provider deepseek\n\
                 \n\
                 Alternatives:\n\
                   • export DEEPSEEK_API_KEY=<your-key>      (current shell only;\n\
                     also note: zsh users — exports in ~/.zshrc only reach interactive\n\
                     shells, prefer ~/.zshenv for everything)\n\
                   • api_key = \"<your-key>\"  in ~/.codewhale/config.toml\n\
                   • already configured DeepSeek Harness? grant read-only access:\n\
                        codewhale auth external-consent --provider deepseek --mode read-only"
            ),
            ApiProvider::SiliconflowCn => anyhow::bail!(
                "SiliconFlow China API key not found. Get a key: {}. Run 'codewhale auth set --provider siliconflow-CN', \
                 set {}, or add [{}] api_key in ~/.codewhale/config.toml. \
                 [providers.siliconflow] remains a fallback when the CN table omits api_key.",
                provider
                    .credential_url()
                    .unwrap_or("https://cloud.siliconflow.com/account/ak"),
                provider.env_vars_label(),
                provider_config_table_name(provider)?
            ),
            ApiProvider::Moonshot => {
                let credential_help =
                    credential_help_for_provider_route(provider, &self.active_route_base_url());
                if moonshot_base_url_is_exact_kimi_code(&self.active_route_base_url()) {
                    anyhow::bail!(
                        "Kimi Code membership-plan API key not found. Get a plan key: {}. This route uses api.kimi.com/coding/v1 and does not import Kimi CLI credentials. Run 'codewhale auth set --provider moonshot', set {}, or add [{}] api_key.",
                        credential_help
                            .credential_url
                            .unwrap_or(KIMI_CODE_MEMBERSHIP_PLAN_CONSOLE_URL),

View on GitHub (pinned to 73e0f67d83)