Hmbown/CodeWhale · error
empty API key provided
Error message
empty API key provided
What it means
The interactive API-key reader prints `Enter API key for <slot>:` (or reads quietly when stdin is not a terminal), trims the line, and rejects an empty result. An empty key would silently produce a broken provider configuration, so Codewhale fails fast with `empty API key provided` instead of storing nothing.
Source
Thrown at crates/cli/src/lib.rs:4008
None => "n/a",
}
}
fn prompt_api_key(slot: &str) -> Result<String> {
use std::io::{IsTerminal, Write};
eprint!("Enter API key for {slot}: ");
io::stderr().flush().ok();
if !io::stdin().is_terminal() {
// Non-interactive: read directly without prompting twice.
return read_api_key_from_stdin();
}
let mut buf = String::new();
io::stdin()
.read_line(&mut buf)
.context("failed to read API key from stdin")?;
let key = buf.trim().to_string();
if key.is_empty() {
bail!("empty API key provided");
}
Ok(key)
}
/// Move plaintext keys from config.toml into the configured secret store.
/// Hidden in v0.8.8 because the normal setup path is config/env only.
fn run_auth_migrate(store: &mut ConfigStore, secrets: &Secrets, dry_run: bool) -> Result<()> {
let mut migrated: Vec<(ProviderKind, &'static str)> = Vec::new();
let mut warnings: Vec<String> = Vec::new();
let literal =
|value: &String| classify_config_api_key_value(value) == ConfigApiKeyValueKind::Literal;
for provider in ProviderKind::ALL {
let slot = provider_slot(provider);
let from_provider_block = store
.config
.providers
.for_provider(provider)View on GitHub (pinned to 0c42157ee5)
Solutions
- Re-run and paste a real, non-empty API key for the slot named in the prompt
- Provide the key non-interactively: pipe it (`printf '%s\n' "$KEY" | codewhale auth api-key ...`) or use the provider's env var
- Check the key in the provider console and re-copy it without stray whitespace
Example fix
# before Enter API key for deepseek: <Enter> # empty API key provided # after Enter API key for deepseek: sk-********
Defensive patterns
Strategy: validation
Validate before calling
#!/usr/bin/env bash
key="${DEEPSEEK_API_KEY:-}"
[ -n "${key// /}" ] || { read -rs -p "API key: " key; echo; }
[ -n "${key// /}" ] || { echo "empty API key" >&2; exit 1; }
printf '%s\n' "$key" | codewhale auth api-key --provider deepseek Type guard
fn is_valid_api_key(s: &str) -> bool {
!s.trim().is_empty()
} Prevention
- Pre-validate `key.trim()` is non-empty before piping or prompting
- Pull keys from a real secret store; never assume the env var is populated
When it happens
Trigger: Pressing Enter without typing at the API-key prompt; pasting only whitespace/newlines; a terminal where the paste lands after the read; piping blank input into the interactive path.
Common situations: Password managers failing to auto-fill the hidden prompt; users intending to skip key entry; trailing-newline-only stdin from a wrapper script; keys copied with only whitespace.
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
- No API key provided via stdin.
- Kimi is API-key-only in Codewhale. Create a key at https://p
- Model name cannot be empty
- No API key provided. Pass --api-key or pipe one via stdin.
- The Codewhale service returned an unexpectedly large respons
AI-assisted analysis of Hmbown/CodeWhale@0c42157ee5 (2026-08-20).
Data as JSON: /api/errors/0b2287b7487146c3.
Report an issue: GitHub.