{"record":{"id":"84e497b4bca83cc1","repo":"Hmbown/CodeWhale","slug":"no-runtime-effective-api-key","errorCode":null,"errorMessage":"no runtime-effective API key","messagePattern":"no runtime-effective API key","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/cli/src/credential_handoff.rs","lineNumber":52,"sourceCode":"    if resolved.provider != provider {\n        bail!(\"resolved a different provider\");\n    }\n    let source = resolved.api_key_source;\n    if source != Some(RuntimeApiKeySource::Cli) {\n        if provider == ProviderKind::OpenaiCodex {\n            bail!(\"bearer credentials are not an API key\");\n        }\n        let uses_api_key = provider != ProviderKind::Xai\n            || xai_auth_diagnostics(store, runtime_overrides).evaluates_runtime_api_key();\n        ensure!(uses_api_key, \"OAuth bearer credentials are not an API key\");\n        let kimi_bearer = provider == ProviderKind::Moonshot\n            && resolved\n                .auth_mode\n                .as_deref()\n                .is_some_and(auth_mode_uses_kimi_imported_token);\n        ensure!(!kimi_bearer, \"bearer credentials are not an API key\");\n    }\n    ensure!(source.is_some(), \"no runtime-effective API key\");\n    resolved\n        .api_key\n        .filter(|value| !value.trim().is_empty())\n        .context(\"no usable runtime-effective API key\")\n}\n\npub(crate) fn handoff_secret_line(\n    writer: &mut impl Write,\n    stdout_is_terminal: bool,\n    resolve: impl FnOnce() -> Result<String>,\n) -> Result<()> {\n    prepare_stdout(stdout_is_terminal)?;\n    let secret = Zeroizing::new(resolve().map_err(|_| anyhow::anyhow!(\"unavailable credential\"))?);\n    ensure!(!secret.trim().is_empty(), \"credential handoff was empty\");\n    let written = writeln!(writer, \"{}\", secret.as_str());\n    if written.is_ok() || written.is_err_and(|error| error.kind() == ErrorKind::BrokenPipe) {\n        return Ok(());\n    }","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/cli/src/credential_handoff.rs#L34-L70","documentation":"resolve_api_key in the CLI credential-handoff module could not find a runtime-effective API key from any configured source (env, shared secret store, endpoint config, CLI override). The function requires at least one non-empty key source to be active after applying precedence rules, and it also rejects bearer-owned auth (e.g. Kimi-imported tokens) because those are not API keys. It guards the handoff path so only a genuine key is ever piped to a consumer.","triggerScenarios":"Calling the CLI credential handoff (which invokes resolve_api_key) when: no key source matched at all (source is None); the provider's auth_mode is bearer-based (kimi imported token) so the key path is rejected; or the resolved api_key slot exists but is empty/whitespace-only.","commonSituations":"Running the handoff command before ever logging in or configuring a provider; OPENROUTER/other env keys absent in a hermetic CI environment; the provider only has bearer credentials (imported token) and no API key; a custom endpoint is configured but its endpoint-bound key was not supplied and no CLI override was passed.","solutions":["Set the API key for the active provider (env var, shared secret store entry, or CLI --api-key override) and retry.","Check which provider/route is active: if auth_mode is bearer-based (e.g. Kimi imported token), this command intentionally fails — configure an actual API key instead.","If using a custom endpoint, supply the endpoint-bound key for that endpoint; a key from a different provider will not resolve.","Run any of the diagnostics/tests (api_key_resolves_the_runtime_provider_slot_without_printing_it) to confirm which precedence layer is missing the credential."],"exampleFix":"// before\n$ codewhale credential handoff\nError: no runtime-effective API key\n\n// after\n$ export OPENROUTER_API_KEY=sk-...\n$ codewhale credential handoff\nsk-...","handlingStrategy":"validation","validationCode":"fn has_api_key_ready(active_provider: &str, env: &Env, store: &SecretStore) -> bool {\n    !env.get(format!(\"{}_API_KEY\", active_provider.to_uppercase())).unwrap_or(\"\").trim().is_empty()\n        || store.get(active_provider).map(|k| !k.trim().is_empty()).unwrap_or(false)\n}","typeGuard":"fn is_bearer_auth(auth_mode: Option<&str>) -> bool {\n    auth_mode.map(|m| m.eq_ignore_ascii_case(\"bearer\")).unwrap_or(false)\n}","tryCatchPattern":null,"preventionTips":["Run the login/credential setup step before any handoff command.","Validate key presence (non-empty, non-bearer auth mode) as a startup precondition in scripts.","In CI, provision the provider key via secrets rather than relying on ambient environment.","Prefer CLI --api-key override in one-shot scripts to make the source explicit."],"tags":["cli","credentials","api-key","configuration"],"backgroundTag":"missing-api-key","analyzedSha":"73e0f67d83c59909b571efdfc88c4bc28c309cb1","analyzedAt":"2026-09-22T01:30:00.501Z","contentChangedAt":"2026-09-22T01:30:00.501Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}