{"record":{"id":"e3cf63088af1738e","repo":"Hmbown/CodeWhale","slug":"this-command-authenticates-with-a-codewhale-account-api-key","errorCode":null,"errorMessage":"This command authenticates with a Codewhale account API key. Set {MACHINE_KEY_ENV}, or create one with `codewhale account api-keys create` after `codewhale login`.","messagePattern":"This command authenticates with a Codewhale account API key\\. Set (.+?), or create one with `codewhale account api-keys create` after `codewhale login`\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/cli/src/cloud/machine.rs","lineNumber":204,"sourceCode":"                .filter(|value| !value.trim().is_empty()),\n        }\n    }\n\n    /// Whether a machine credential is present at all, valid or not.\n    #[must_use]\n    pub(crate) fn is_present(&self) -> bool {\n        self.raw.is_some()\n    }\n\n    /// Validate the key if one is set.\n    pub(crate) fn resolve(&self) -> Result<Option<MachineKey>> {\n        self.raw.as_deref().map(MachineKey::parse).transpose()\n    }\n\n    /// Validate the key, requiring one to be set.\n    pub(crate) fn require(&self) -> Result<MachineKey> {\n        self.resolve()?.ok_or_else(|| {\n            anyhow!(\n                \"This command authenticates with a Codewhale account API key. \\\nSet {MACHINE_KEY_ENV}, or create one with `codewhale account api-keys create` after \\\n`codewhale login`.\"\n            )\n        })\n    }\n}\n\n// ---------------------------------------------------------------------------\n// Base URL\n// ---------------------------------------------------------------------------\n\n/// Resolve the account API origin.\n///\n/// Order: explicit `--api-base`, then `CODEWHALE_API_BASE`, then whatever the\n/// device flow already uses, then the production default. The flag outranks\n/// the variable for the same reason `--api-key` would outrank the environment:\n/// the nearer, more deliberate signal wins.","sourceCodeStart":186,"sourceCodeEnd":222,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/73e0f67d83c59909b571efdfc88c4bc28c309cb1/crates/cli/src/cloud/machine.rs#L186-L222","documentation":"`MachineKeyStore::require` validates and returns the configured Codewhale machine API key; if none is set (the resolved secret is empty/unset), it throws this message telling the user how to supply one via the environment variable or by creating it with the CLI.","triggerScenarios":"Running a cloud-account command that calls `require()` while MACHINE_KEY_ENV is unset, empty, or reads as empty from the secret store.","commonSituations":"Fresh machine/CI environment without the key exported; key exported under the wrong variable name; a secret-store slot that exists but holds an empty string.","solutions":["Export the key: set MACHINE_KEY_ENV to a valid Codewhale API key.","Create one if needed: `codewhale login` then `codewhale account api-keys create`.","If a secret-store slot exists but is empty, re-set it (`codewhale account keys set`) or bypass with the env var."],"exampleFix":"// before (CI)\ncodewhale account providers list\n// after\nexport MACHINE_KEY_ENV=\"cw_...\"  # actual var name per docs\ncodewhale account providers list","handlingStrategy":"validation","validationCode":"let key = std::env::var(\"MACHINE_KEY_ENV\").unwrap_or_default();\nif key.trim().is_empty() {\n    eprintln!(\"set MACHINE_KEY_ENV or run: codewhale account api-keys create\");\n    std::process::exit(2);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Export the key in shell profiles or CI secrets before invoking cloud commands.","Verify non-empty (not just set) in automation.","Fall back to `codewhale login` + `api-keys create` for onboarding."],"tags":["authentication","api-key","cli","environment"],"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-22T11:17:16.035Z"}