{"record":{"id":"1aea4c043a8127da","repo":"nikivdev/code","slug":"openrouter-api-key-not-set-get-one-at-https-ope","errorCode":null,"errorMessage":"OPENROUTER_API_KEY not set. Get one at https://openrouter.ai/keys","messagePattern":"OPENROUTER_API_KEY not set\\. Get one at https://openrouter\\.ai/keys","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/commit.rs","lineNumber":13170,"sourceCode":"\nfn openrouter_api_key() -> Result<String> {\n    if let Ok(value) = std::env::var(\"OPENROUTER_API_KEY\") {\n        if !value.trim().is_empty() {\n            return Ok(value);\n        }\n    }\n\n    if is_local_env_backend() {\n        if let Ok(vars) = crate::env::fetch_personal_env_vars(&[\"OPENROUTER_API_KEY\".to_string()]) {\n            if let Some(value) = vars.get(\"OPENROUTER_API_KEY\") {\n                if !value.trim().is_empty() {\n                    return Ok(value.clone());\n                }\n            }\n        }\n    }\n\n    bail!(\"OPENROUTER_API_KEY not set. Get one at https://openrouter.ai/keys\");\n}\n\nfn parse_review_json(output: &str) -> Option<ReviewJson> {\n    let trimmed = output.trim();\n    if trimmed.is_empty() {\n        return None;\n    }\n\n    if let Ok(parsed) = serde_json::from_str::<ReviewJson>(trimmed) {\n        return Some(parsed);\n    }\n\n    let start = trimmed.find('{')?;\n    let end = trimmed.rfind('}')?;\n    if end <= start {\n        return None;\n    }\n    let candidate = &trimmed[start..=end];","sourceCodeStart":13152,"sourceCodeEnd":13188,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/commit.rs#L13152-L13188","documentation":"Thrown when the commit review/generation feature needs an OpenRouter API key but none can be found in the environment or config lookup. The message includes a link to obtain a key at https://openrouter.ai/keys. The library never silently proceeds without credentials for the AI-backed path.","triggerScenarios":"Invoking the AI commit-message/review flow when OPENROUTER_API_KEY is absent from the process environment and no alternate config location checked by the key-lookup loop provides a value.","commonSituations":"Fresh clone on a new machine without .env, CI pipeline missing the secret, key stored under a different variable name (e.g. OPENAI_API_KEY), or shell not sourcing the profile that exports the key.","solutions":["Export the key: `export OPENROUTER_API_KEY=sk-or-...` (get one at https://openrouter.ai/keys)","Add the key to your CI secrets / .env file so automated runs get it","Verify with `echo ${OPENROUTER_API_KEY:+set}` that the variable is visible to the process","If you meant a different provider, configure that provider's key/env name instead"],"exampleFix":"// before (shell)\ncargo run -- commit --ai\n// error: OPENROUTER_API_KEY not set\n// after (shell)\nexport OPENROUTER_API_KEY=sk-or-v1-...\ncargo run -- commit --ai","handlingStrategy":"validation","validationCode":"// run before invoking AI-backed commands\nif std::env::var(\"OPENROUTER_API_KEY\").map_or(true, |v| v.trim().is_empty()) {\n    eprintln!(\"OPENROUTER_API_KEY not set — get one at https://openrouter.ai/keys\");\n    std::process::exit(1);\n}","typeGuard":null,"tryCatchPattern":"match run_ai_commit() {\n    Err(e) if e.to_string().contains(\"OPENROUTER_API_KEY\") => {\n        eprintln!(\"Set OPENROUTER_API_KEY (https://openrouter.ai/keys), then retry.\");\n        std::process::exit(2);\n    }\n    other => other,\n}","preventionTips":["Commit a documented .env.example listing OPENROUTER_API_KEY","Declare the secret in CI (GitHub Actions secrets) before enabling AI features","Source your profile or use direnv so the key is set in every shell","Never commit the real key; rotate if leaked"],"tags":["environment","api-key","openrouter","configuration"],"backgroundTag":"missing-env-var","analyzedSha":"a747e741ae92c09071d0ae946ab48488adcff1ce","analyzedAt":"2026-09-01T22:43:55.719Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}