Hmbown/CodeWhale · error · anyhow::Error
No API key provided via stdin.
Error message
No API key provided via stdin.
What it means
The stdin branch of read_api_key_from_stdin(): stdin was piped (not a TTY) but its content trimmed to an empty string. The CLI distinguishes this from the no-pipe case (error 469) so scripts can tell an empty pipe from a missing one. Even a newline-only pipe trims to empty and fails.
Source
Thrown at crates/tui/src/lib.rs:7773
/// silently falling back to a route classifier or an older config.toml value.
fn apply_saved_reasoning_preference(config: &mut Config, settings: &crate::settings::Settings) {
let Some(reasoning_effort) = settings.reasoning_effort.as_ref() else {
return;
};
config.reasoning_effort = Some(reasoning_effort.clone());
config.reasoning_effort_inferred_from_legacy_alias = false;
}
fn read_api_key_from_stdin() -> Result<String> {
let mut stdin = io::stdin();
if stdin.is_terminal() {
bail!("No API key provided. Pass --api-key or pipe one via stdin.");
}
let mut buffer = String::new();
stdin.read_to_string(&mut buffer)?;
let api_key = buffer.trim().to_string();
if api_key.is_empty() {
bail!("No API key provided via stdin.");
}
Ok(api_key)
}
fn run_login(api_key: Option<String>) -> Result<()> {
let api_key = match api_key {
Some(key) => key,
None => read_api_key_from_stdin()?,
};
let saved = config::save_api_key(&api_key)?;
println!("Saved API key to {}", saved.describe());
Ok(())
}
fn run_logout() -> Result<()> {
config::clear_api_key()?;
println!("Cleared saved API key.");
Ok(())View on GitHub (pinned to 0c42157ee5)
Solutions
- Guard the source: `: "${VAR:?msg}"` fails fast on unset/empty variables
- Verify a piped file is non-empty: `[ -s key.txt ]`
- Or bypass stdin entirely with `codewhale login --api-key <key>`
Example fix
// before: VAR unset -> pipe delivers only a newline
$ echo "$MY_KEY" | codewhale login
Error: No API key provided via stdin.
// after
$ : "${MY_KEY:?MY_KEY is empty}" && printf '%s' "$MY_KEY" | codewhale login Defensive patterns
Strategy: validation
Validate before calling
[ -n "${CODEWHALE_API_KEY:-}" ] || { echo 'key variable empty' >&2; exit 2; }
printf '%s' "$CODEWHALE_API_KEY" | codewhale login Prevention
- Use : "${VAR:?msg}" and `[ -s file ]` checks before piping
- Log pipe provenance in CI so an empty secret is obvious
When it happens
Trigger: `codewhale login` with no --api-key and stdin piped but blank: an unset/empty variable (`echo "$VAR" |`), an empty file redirect, or a producer that emitted only whitespace.
Common situations: CI job where the secret's variable name is misspelled or the secret was never injected; piping from a failed command's empty output; redirecting an empty key file.
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. Pass --api-key or pipe one via stdin.
- empty API key provided
- API key input is unexpectedly large
- interactive key entry requires a terminal; use `--api-key-st
- Kimi is API-key-only in Codewhale. Create a key at https://p
AI-assisted analysis of Hmbown/CodeWhale@0c42157ee5 (2026-08-20).
Data as JSON: /api/errors/a4a5ed2ec3abc0e2.
Report an issue: GitHub.