{"record":{"id":"7b8fe99a9ab06a40","repo":"Kuberwastaken/claurst","slug":"no-api-key-found","errorCode":null,"errorMessage":"No API key found","messagePattern":"No API key found","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src-rust/crates/api/src/lib.rs","lineNumber":674,"sourceCode":"        }\r\n\r\n        /// Build a new client. Uses a `wreq`/BoringSSL client whose TLS\r\n        /// fingerprint matches Bun (the official client). An empty key is\r\n        /// allowed; validation is deferred to the first call.\r\n        pub fn new(config: ClientConfig) -> anyhow::Result<Self> {\r\n            let http = crate::bun_tls::build_anthropic_client(config.request_timeout)?;\r\n            Ok(Self {\r\n                http,\r\n                config,\r\n                session_id: uuid::Uuid::new_v4().to_string(),\r\n            })\r\n        }\r\n\r\n        /// Convenience constructor that resolves the key from config/env.\r\n        pub fn from_config(cfg: &claurst_core::config::Config) -> anyhow::Result<Self> {\r\n            let api_key = cfg\r\n                .resolve_api_key()\r\n                .ok_or_else(|| anyhow::anyhow!(\"No API key found\"))?;\r\n            let api_base = cfg.resolve_api_base();\r\n\r\n            Self::new(ClientConfig {\r\n                api_key,\r\n                api_base,\r\n                ..Default::default()\r\n            })\r\n        }\r\n\r\n        // ---- Non-streaming create message --------------------------------\r\n\r\n        /// Send a non-streaming `POST /v1/messages` and return the full response.\r\n        pub async fn create_message(\r\n            &self,\r\n            mut request: CreateMessageRequest,\r\n        ) -> Result<CreateMessageResponse, ClaudeError> {\r\n            // Deferred key validation — fail here rather than at construction\r\n            // so that non-Anthropic provider setups don't crash on startup.\r","sourceCodeStart":656,"sourceCodeEnd":692,"githubUrl":"https://github.com/Kuberwastaken/claurst/blob/b0637c97ec34144387cbf2f74f65df6d16a6cef1/src-rust/crates/api/src/lib.rs#L656-L692","documentation":"The API client's convenience constructor `from_config` requires an API key resolved from the app configuration or environment. When `cfg.resolve_api_key()` returns `None` — no key in config files and no relevant environment variable set — construction fails with this error. It is a fail-fast guard so requests are never sent without credentials.","triggerScenarios":"Calling `Client::from_config(&config)` where the `Config` has no API key: `resolve_api_key()` finds neither a settings-file key nor a provider env var (e.g. ANTHROPIC_API_KEY).","commonSituations":"Fresh checkout / new machine without exporting the API key env var; settings.json missing the `apiKey` field; using a provider that needs OAuth (Claude Pro/Max) instead of an API key; typos in the env var name; CI environment without secrets injected.","solutions":["Export the provider's API key env var (e.g. `export ANTHROPIC_API_KEY=sk-ant-...`) before launching.","Set the API key in the app's settings/config file that `claurst_core::config::Config` reads.","If you have the key programmatically, use `Client::new(ClientConfig { api_key, .. })` instead of `from_config`.","In CI, add the secret to the pipeline environment rather than hardcoding it."],"exampleFix":"// before\nlet client = ApiClient::from_config(&cfg)?; // panics at runtime: No API key found\n// after\nif cfg.resolve_api_key().is_none() {\n    eprintln!(\"Set ANTHROPIC_API_KEY before starting\");\n    std::process::exit(1);\n}\nlet client = ApiClient::from_config(&cfg)?;","handlingStrategy":"validation","validationCode":"// Fail fast before constructing the client\nif cfg.resolve_api_key().is_none() {\n    anyhow::bail!(\"No API key: set ANTHROPIC_API_KEY or add apiKey to settings\");\n}","typeGuard":null,"tryCatchPattern":"let client = ApiClient::from_config(&cfg)\n    .map_err(|e| e.context(\"configure ANTHROPIC_API_KEY before using the API\"))?;","preventionTips":["Export the API key env var in shell profile or CI secrets as a setup step.","Validate config at startup (check resolve_api_key) before any feature that needs the client.","Prefer the explicit Client::new(ClientConfig{api_key}) path in code so the requirement is visible.","Document the required env var in README/onboarding docs."],"tags":["api","authentication","config","missing-api-key"],"backgroundTag":"missing-api-key","analyzedSha":"b0637c97ec34144387cbf2f74f65df6d16a6cef1","analyzedAt":"2026-09-10T00:24:58.650Z","contentChangedAt":"2026-09-10T00:24:58.650Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}