{"record":{"id":"a5ed613d19207b22","repo":"Kuberwastaken/claurst","slug":"unable-to-parse-api-key-for-http-header","errorCode":null,"errorMessage":"unable to parse api key for http header","messagePattern":"unable to parse api key for http header","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"src-rust/crates/api/src/providers/minimax.rs","lineNumber":37,"sourceCode":"};\nuse crate::types::{ApiMessage, ApiToolDefinition, CreateMessageRequest, ThinkingConfig};\n\nuse super::message_normalization::normalize_anthropic_messages;\n\npub struct MinimaxProvider {\n    http_client: Client,\n    api_key: String,\n    api_base: String,\n    service_tier: Option<String>,\n    id: ProviderId,\n}\n\nimpl MinimaxProvider {\n    pub fn new(api_key: String) -> Self {\n        let api_base = std::env::var(\"MINIMAX_BASE_URL\")\n            .unwrap_or_else(|_| claurst_core::constants::MINIMAX_ANTHROPIC_API_BASE.to_string());\n        let mut headers = header::HeaderMap::new();\n        headers.insert(\"X-Api-Key\", header::HeaderValue::from_str(&api_key).expect(\"unable to parse api key for http header\"));\n        let http_client = Client::builder()\n            .default_headers(headers)\n            .timeout(crate::request_timeout())\n            .build()\n            .expect(\"MinimaxProvider: failed to build HTTP client\");\n\n        Self {\n            http_client,\n            api_key,\n            api_base,\n            service_tier: None,\n            id: ProviderId::new(ProviderId::MINIMAX),\n        }\n    }\n\n    pub fn with_base_url(mut self, api_base: impl Into<String>) -> Self {\n        self.api_base = api_base.into();\n        self","sourceCodeStart":19,"sourceCodeEnd":55,"githubUrl":"https://github.com/Kuberwastaken/claurst/blob/b0637c97ec34144387cbf2f74f65df6d16a6cef1/src-rust/crates/api/src/providers/minimax.rs#L19-L55","documentation":"MinimaxProvider::new inserts the API key as an X-Api-Key default header using HeaderValue::from_str(&api_key).expect(...). HTTP header values must contain only visible ASCII (bytes 0x20–0x7E, plus a few others); if the key contains whitespace control chars, newlines, or non-ASCII bytes, from_str fails and the provider panics with this message.","triggerScenarios":"Passing an api_key containing non-ASCII or control characters (e.g. a newline from a mis-trimmed env var, a paste with trailing CR, or a UTF-8 multi-byte character) into MinimaxProvider::new.","commonSituations":"Copying an API key with a trailing newline into an env file; shell quoting adding whitespace; using a base64-encoded or otherwise transformed key that includes padding/newlines; terminal paste artifacts.","solutions":["Trim whitespace/newlines from the API key before constructing the provider: api_key.trim().","Verify the key with `od -c` or similar to detect hidden control characters or non-ASCII bytes.","Regenerate/copy the key directly from the provider dashboard without transformation (no base64, no wrapping).","If constructing in your own code, validate with HeaderValue::from_str first and return a proper error instead of panicking."],"exampleFix":"// before\nlet provider = MinimaxProvider::new(std::env::var(\"MINIMAX_API_KEY\")?);\n// after\nlet key = std::env::var(\"MINIMAX_API_KEY\")?;\nlet key = key.trim().to_string();\nheader::HeaderValue::from_str(&key)\n    .context(\"MINIMAX_API_KEY contains invalid characters for an HTTP header\")?;\nlet provider = MinimaxProvider::new(key);","handlingStrategy":"validation","validationCode":"fn valid_header_value(s: &str) -> bool {\n    !s.is_empty() && s.bytes().all(|b| (0x20..=0x7E).contains(&b) || b == 0x09)\n}\n// before constructing:\nlet key = api_key.trim();\nif !valid_header_value(key) { return Err(anyhow!(\"MINIMAX_API_KEY contains characters invalid in an HTTP header\")); }","typeGuard":"fn as_header_value(s: &str) -> Option<reqwest::header::HeaderValue> {\n    reqwest::header::HeaderValue::from_str(s.trim()).ok()\n}","tryCatchPattern":"// this panic cannot be caught in Rust; pre-validate instead\nlet key = api_key.trim();\nmatch reqwest::header::HeaderValue::from_str(key) {\n    Ok(_) => MinimaxProvider::new(key.to_string()),\n    Err(e) => return Err(anyhow!(\"invalid MINIMAX_API_KEY header value: {e}\")),\n}","preventionTips":["Always trim() API keys read from env vars or files.","Never base64-encode or newline-wrap keys destined for header values.","Inspect suspicious keys with `od -c` for hidden control characters.","Copy keys straight from the provider dashboard without intermediate editors.","Pre-validate with HeaderValue::from_str before constructing the provider."],"tags":["panic","http-headers","api-key","validation"],"backgroundTag":"invalid-argument-format","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"}