{"record":{"id":"6342c18d7ddbeead","repo":"zeroclaw-labs/zeroclaw","slug":"imagen-failed-status-body-text","errorCode":null,"errorMessage":"Imagen failed ({status}): {body_text}","messagePattern":"Imagen failed \\((.+?)\\): (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/zeroclaw-tools/src/linkedin_client.rs","lineNumber":1032,"sourceCode":"            \"parameters\": {\n                \"sampleCount\": 1,\n                \"aspectRatio\": \"1:1\"\n            }\n        });\n\n        let resp = client\n            .post(&url)\n            .header(\"Authorization\", format!(\"Bearer {api_key}\"))\n            .header(\"Content-Type\", \"application/json\")\n            .json(&body)\n            .send()\n            .await\n            .context(\"Imagen request failed\")?;\n\n        let status = resp.status();\n        if !status.is_success() {\n            let body_text = resp.text().await.unwrap_or_default();\n            anyhow::bail!(\"Imagen failed ({status}): {body_text}\");\n        }\n\n        let json: serde_json::Value = resp.json().await?;\n        let b64 = json\n            .pointer(\"/predictions/0/bytesBase64Encoded\")\n            .and_then(|v| v.as_str())\n            .ok_or_else(|| {\n                ::zeroclaw_log::record!(\n                    ERROR,\n                    ::zeroclaw_log::Event::new(module_path!(), ::zeroclaw_log::Action::Fail)\n                        .with_outcome(::zeroclaw_log::EventOutcome::Failure)\n                        .with_attrs(::serde_json::json!({\"image_provider\": \"imagen\"})),\n                    \"linkedin_client: Imagen response missing image data\"\n                );\n                anyhow::Error::msg(\"No image data in Imagen response\")\n            })?;\n\n        let bytes = base64_decode(b64)?;","sourceCodeStart":1014,"sourceCodeEnd":1050,"githubUrl":"https://github.com/zeroclaw-labs/zeroclaw/blob/88bb9c8533fc57ed7a03e36ca7c9ed2bf8336dcc/crates/zeroclaw-tools/src/linkedin_client.rs#L1014-L1050","documentation":"try_imagen calls Google's Imagen predict endpoint and bails on any non-2xx status with the body embedded. It runs after the configured Imagen key/token was found in .env, so this error is about the API call: authentication, project setup, model access, or prompt safety filtering.","triggerScenarios":"401/403 when the OAuth credential or API key is invalid, the project never enabled the Imagen API, or the model is not allowlisted; 400 for unsupported aspect ratio, sample count, or malformed instances; prompts blocked by safety filters return a 4xx with a blocked reason in the body.","commonSituations":"Service account JSON rotated but the .env copy is stale; using a personal API key against a Vertex endpoint (or vice versa); region/project mismatch; prompts with person references tripping safety filters.","solutions":["Read the embedded body_text — Google's error names the reason (auth, model access, safety block) precisely","Verify the key/token env var named by imagen.api_key_env holds a current credential for the same project where the API is enabled","Enable the Imagen model on the project and confirm region + model id in the configured endpoint","Rephrase the prompt if the body indicates a safety block, and keep another provider configured as a fallback"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"Treat as a per-provider failure consumed by generate(); if it is the last provider, catch generate()'s error and check the earlier WARN log for the Imagen status/body before deciding between fixing credentials and rephrasing the prompt.","preventionTips":["Verify the Google project has the Imagen API enabled before relying on it","Rotate service credentials into .env on the same schedule as the cloud project","Avoid prompt phrasing that trips safety filters when a fallback provider is not configured"],"tags":["google-imagen","image-generation","http","api-key"],"backgroundTag":"image-generation-api-error","analyzedSha":"88bb9c8533fc57ed7a03e36ca7c9ed2bf8336dcc","analyzedAt":"2026-08-23T01:07:41.857Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}