Hmbown/CodeWhale · error
no runtime-effective API key
Error message
no runtime-effective API key
What it means
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.
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.
Example fix
// before $ codewhale credential handoff Error: no runtime-effective API key // after $ export OPENROUTER_API_KEY=sk-... $ codewhale credential handoff sk-...
Defensive patterns
Strategy: validation
Validate before calling
fn has_api_key_ready(active_provider: &str, env: &Env, store: &SecretStore) -> bool {
!env.get(format!("{}_API_KEY", active_provider.to_uppercase())).unwrap_or("").trim().is_empty()
|| store.get(active_provider).map(|k| !k.trim().is_empty()).unwrap_or(false)
} Type guard
fn is_bearer_auth(auth_mode: Option<&str>) -> bool {
auth_mode.map(|m| m.eq_ignore_ascii_case("bearer")).unwrap_or(false)
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
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
- api_key cannot be empty string
- API key contains invalid control characters
- API key id must be lowercase hex characters — the part…
- API key must be - UTF-8 bytes
- API key name must be 1
AI-assisted analysis of Hmbown/CodeWhale@73e0f67d83 (2026-09-22).
Data as JSON: /api/errors/84e497b4bca83cc1.
Report an issue: GitHub.
Appendix: source
Thrown at crates/cli/src/credential_handoff.rs:52
if resolved.provider != provider {
bail!("resolved a different provider");
}
let source = resolved.api_key_source;
if source != Some(RuntimeApiKeySource::Cli) {
if provider == ProviderKind::OpenaiCodex {
bail!("bearer credentials are not an API key");
}
let uses_api_key = provider != ProviderKind::Xai
|| xai_auth_diagnostics(store, runtime_overrides).evaluates_runtime_api_key();
ensure!(uses_api_key, "OAuth bearer credentials are not an API key");
let kimi_bearer = provider == ProviderKind::Moonshot
&& resolved
.auth_mode
.as_deref()
.is_some_and(auth_mode_uses_kimi_imported_token);
ensure!(!kimi_bearer, "bearer credentials are not an API key");
}
ensure!(source.is_some(), "no runtime-effective API key");
resolved
.api_key
.filter(|value| !value.trim().is_empty())
.context("no usable runtime-effective API key")
}
pub(crate) fn handoff_secret_line(
writer: &mut impl Write,
stdout_is_terminal: bool,
resolve: impl FnOnce() -> Result<String>,
) -> Result<()> {
prepare_stdout(stdout_is_terminal)?;
let secret = Zeroizing::new(resolve().map_err(|_| anyhow::anyhow!("unavailable credential"))?);
ensure!(!secret.trim().is_empty(), "credential handoff was empty");
let written = writeln!(writer, "{}", secret.as_str());
if written.is_ok() || written.is_err_and(|error| error.kind() == ErrorKind::BrokenPipe) {
return Ok(());
}View on GitHub (pinned to 73e0f67d83)