Hmbown/CodeWhale · error

Kimi Code membership-plan API key not found. Get a plan key

Error message

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.

What it means

The Kimi Code membership-plan route (api.kimi.com/coding/v1) requires a Kimi Code plan API key and, unlike generic Moonshot routes, will not import Kimi CLI credentials. When no such key is bound, credential resolution bails before any request is sent.

Solutions

  1. Get a Kimi Code plan key at the console URL in the message and run: codewhale auth set --provider moonshot
  2. Set the Moonshot env var shown by env_vars_label() in the launching shell.
  3. Add api_key = "..." under [providers.moonshot] in ~/.codewhale/config.toml.
  4. Do not attempt Kimi CLI credential import — it is intentionally unsupported for this route.

Example fix

// before
[providers.moonshot]
base_url = "https://api.kimi.com/coding/v1"
model = "kimi-for-coding"

// after
[providers.moonshot]
base_url = "https://api.kimi.com/coding/v1"
model = "kimi-for-coding"
api_key = "sk-..."
Defensive patterns

Strategy: validation

Validate before calling

fn kimi_code_route_has_key(cfg: &ProviderCfg) -> bool {
    cfg.base_url.as_deref() == Some("https://api.kimi.com/coding/v1")
        && (cfg.api_key.is_some() || cfg.api_key_env.is_some())
}

Try / catch

match result {
    Err(e) if e.to_string().contains("Kimi Code membership-plan API key not found") => {
        eprintln!("get a plan key and set [providers.moonshot] api_key; kimi CLI import is unsupported");
    }
    other => other?,
}

Prevention

When it happens

Trigger: Provider is ApiProvider::Moonshot and moonshot_base_url_is_exact_kimi_code() matches the active base URL (exactly https://api.kimi.com/coding/v1) while no api_key/api_key_env/env var/stored key is present.

Common situations: Subscribing to a Kimi Code plan and pointing base_url at the coding endpoint but never creating/pasting the plan key; expecting an existing Kimi CLI login to cover the coding endpoint.

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

Appendix: source

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

                   • 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),
                        provider.env_vars_label(),
                        provider_config_table_name(provider)?
                    );
                }
                anyhow::bail!(
                    "Moonshot/Kimi API key not found. Get a key: {}. Run 'codewhale auth set --provider moonshot', \
                     set {}, or add [{}] api_key. \
                     For a Kimi Code plan key, set [providers.moonshot] base_url = \
                     \"https://api.kimi.com/coding/v1\" and model = \"kimi-for-coding\".",
                    credential_help
                        .credential_url
                        .unwrap_or("https://platform.kimi.ai/console/api-keys"),
                    provider.env_vars_label(),
                    provider_config_table_name(provider)?

View on GitHub (pinned to 73e0f67d83)