{"record":{"id":"06d98c44553676d2","repo":"aaif-goose/goose","slug":"missing-required-key","errorCode":null,"errorMessage":"missing required key {}: {}","messagePattern":"missing required key (.+?): (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/goose-providers/src/anthropic.rs","lineNumber":414,"sourceCode":"        None\n    };\n\n    if config.dynamic_models == Some(false) && custom_models.is_none() {\n        return Err(anyhow::anyhow!(\n            \"Provider '{}' has dynamic_models: false but no static models listed; \\\n             at least one entry in `models` is required.\",\n            config.name\n        ));\n    }\n\n    let api_key = if config.api_key_env.is_empty() {\n        None\n    } else {\n        match key_resolver.resolve_key(config.api_key_env.as_str()) {\n            Ok(key) => Some(key),\n            Err(err) => {\n                if config.requires_auth {\n                    anyhow::bail!(\"missing required key {}: {}\", config.api_key_env, err);\n                }\n                None\n            }\n        }\n    };\n\n    let auth = match api_key {\n        Some(key) if !key.is_empty() => AuthMethod::ApiKey {\n            header_name: \"x-api-key\".to_string(),\n            key,\n        },\n        _ => AuthMethod::NoAuth,\n    };\n\n    let format_options = format_options_for_provider(config.preserves_thinking);\n\n    let timeout_secs = config\n        .timeout_seconds","sourceCodeStart":396,"sourceCodeEnd":432,"githubUrl":"https://github.com/aaif-goose/goose/blob/3810898a7447ec3299be72e223d3570a7aabf0ab/crates/goose-providers/src/anthropic.rs#L396-L432","documentation":"While constructing the Anthropic provider, goose resolves the API key through a key resolver using the env var named by the provider's api_key_env (for the built-in anthropic provider this is ANTHROPIC_API_KEY). If resolution fails and the config is marked requires_auth, provider construction bails with 'missing required key {ENV}: {cause}' instead of silently continuing unauthenticated.","triggerScenarios":"Starting goose (or first use of the provider) with the named environment variable unset, empty, or unreadable in the process environment, while requires_auth is true (default for the hosted Anthropic API). resolve_key returns Err and the bail fires immediately.","commonSituations":"ANTHROPIC_API_KEY not exported in the shell/daemon environment (systemd unit, cron, container missing env); typo in a custom api_key_env value; key stored in a launcher script but goose launched from another context; CI runners without secrets injected.","solutions":["Export the key in the environment goose runs in: export ANTHROPIC_API_KEY=sk-ant-... (or the custom api_key_env name from the config)","For services/containers, add the variable to the unit file, compose file, or CI secrets so the goose process sees it","Check the api_key_env spelling in providers.yaml matches the variable you actually set","Only if the endpoint truly needs no auth (local gateway), set requires_auth: false on that provider entry"],"exampleFix":"# before (shell)\n$ goose session\nError: missing required key ANTHROPIC_API_KEY: environment variable not found\n\n# after\n$ export ANTHROPIC_API_KEY=\"sk-ant-...\"\n$ goose session","handlingStrategy":"validation","validationCode":"let env_name = &cfg.api_key_env; // e.g. ANTHROPIC_API_KEY\nif cfg.requires_auth {\n    let present = std::env::var(env_name).map(|v| !v.trim().is_empty()).unwrap_or(false);\n    anyhow::ensure!(present, \"set {env_name} before starting goose\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Set required key env vars in the exact launcher context (shell profile, systemd Environment=, container env, CI secrets)","Double-check api_key_env spelling against the variable you export","Add a startup preflight that checks required_auth providers have resolvable keys","For local no-auth gateways, set requires_auth: false deliberately rather than exporting dummy keys"],"tags":["rust","anthropic","auth","api-key","environment","startup"],"backgroundTag":null,"analyzedSha":"3810898a7447ec3299be72e223d3570a7aabf0ab","analyzedAt":"2026-08-16T10:14:26.282Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}