{"record":{"id":"3a2438b3cc78f5f6","repo":"tonhowtf/omniget","slug":"xai-http","errorCode":null,"errorMessage":"xAI HTTP {}: {}","messagePattern":"xAI HTTP (.+?): (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src-tauri/omniget-core/src/core/tools/x/grok.rs","lineNumber":200,"sourceCode":"    let resp = client\n        .post(\"https://api.x.ai/v1/responses\")\n        .bearer_auth(&cfg.xai_key)\n        .json(&body)\n        .send()\n        .await?;\n    let status = resp.status();\n    let v: Value = resp\n        .json()\n        .await\n        .map_err(|e| anyhow!(\"xAI: resposta invalida ({})\", e))?;\n    if !status.is_success() {\n        let msg = v\n            .pointer(\"/error/message\")\n            .or_else(|| v.get(\"error\"))\n            .and_then(|m| m.as_str())\n            .unwrap_or(\"erro\")\n            .to_string();\n        return Err(anyhow!(\"xAI HTTP {}: {}\", status, msg));\n    }\n    let mut text = String::new();\n    let mut citations: Vec<Citation> = Vec::new();\n    for item in v\n        .get(\"output\")\n        .and_then(|o| o.as_array())\n        .into_iter()\n        .flatten()\n    {\n        if item.get(\"type\").and_then(|t| t.as_str()) != Some(\"message\") {\n            continue;\n        }\n        for c in item\n            .get(\"content\")\n            .and_then(|c| c.as_array())\n            .into_iter()\n            .flatten()\n        {","sourceCodeStart":182,"sourceCodeEnd":218,"githubUrl":"https://github.com/tonhowtf/omniget/blob/8600b91f4246848bac346874daa9e61c1fc5677a/src-tauri/omniget-core/src/core/tools/x/grok.rs#L182-L218","documentation":"ask_xai calls the official xAI API (POST https://api.x.ai/v1/responses) and, when the HTTP status is not a success (2xx), it extracts the error message from the JSON body (error.message or error) and returns `xAI HTTP <status>: <message>`. This is the library's generic wrapper for any non-2xx response from the xAI API — auth failures, bad model names, rate limits, invalid parameters all surface through it.","triggerScenarios":"The /v1/responses call returns 401 (invalid/expired xai_key), 400 (unknown xai_model, malformed tools/instructions payload), 403, 429 (rate limit), or 5xx; any non-success status with a JSON body triggers this error.","commonSituations":"Stale or missing XAI API key after rotation; typo'd or retired model name in grok.json (xai_model); exceeding xAI quota/rate limits; passing search tools the account/plan does not allow.","solutions":["Check the status code and message in the error text: 401/403 means fix the xai_key (re-run grok set with a fresh key from console.x.ai).","If 400/404 mentions the model, set a valid xai_model (e.g. grok-4.6) in grok.json or pass req.model.","If 429, wait and retry with backoff or reduce request frequency.","If 5xx, retry later; it is a server-side xAI outage.","Verify network/proxy settings if the status indicates connectivity errors."],"exampleFix":"// before\nbody = json!({ \"model\": \"grok-2-121345\", ... })  // retired model -> xAI HTTP 400\n// after\nbody = json!({ \"model\": \"grok-4.6\", ... })  // valid current model","handlingStrategy":"try-catch","validationCode":"let cfg = grok_config();\nif cfg.xai_key.trim().is_empty() { return Err(\"configure xai_key first\"); }\nif !cfg.xai_model.starts_with(\"grok-\") { return Err(\"xai_model looks invalid\"); }","typeGuard":"fn status_is_retryable(status: u16) -> bool { status == 429 || status >= 500 }","tryCatchPattern":"match grok::ask(req).await {\n    Ok(a) => use_answer(a),\n    Err(e) if e.to_string().contains(\"xAI HTTP 401\") => reconfigure_key_and_retry(),\n    Err(e) if e.to_string().contains(\"xAI HTTP 429\") => sleep_backoff_and_retry(),\n    Err(e) => log_error(e),\n}","preventionTips":["Keep xai_key fresh and scoped; rotate before expiry","Pin xai_model to a model confirmed live on console.x.ai","Handle 429 with exponential backoff rather than tight retries","Validate prompt/tools payload sizes before sending"],"tags":["http","api","xai","rust"],"backgroundTag":"http-error-response","analyzedSha":"8600b91f4246848bac346874daa9e61c1fc5677a","analyzedAt":"2026-09-12T14:29:19.317Z","contentChangedAt":"2026-09-12T14:29:19.317Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}