zeroclaw-labs/zeroclaw · error · anyhow::Error

Imagen failed ({status}): {body_text}

Error message

Imagen failed ({status}): {body_text}

What it means

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.

Source

Thrown at crates/zeroclaw-tools/src/linkedin_client.rs:1032

            "parameters": {
                "sampleCount": 1,
                "aspectRatio": "1:1"
            }
        });

        let resp = client
            .post(&url)
            .header("Authorization", format!("Bearer {api_key}"))
            .header("Content-Type", "application/json")
            .json(&body)
            .send()
            .await
            .context("Imagen request failed")?;

        let status = resp.status();
        if !status.is_success() {
            let body_text = resp.text().await.unwrap_or_default();
            anyhow::bail!("Imagen failed ({status}): {body_text}");
        }

        let json: serde_json::Value = resp.json().await?;
        let b64 = json
            .pointer("/predictions/0/bytesBase64Encoded")
            .and_then(|v| v.as_str())
            .ok_or_else(|| {
                ::zeroclaw_log::record!(
                    ERROR,
                    ::zeroclaw_log::Event::new(module_path!(), ::zeroclaw_log::Action::Fail)
                        .with_outcome(::zeroclaw_log::EventOutcome::Failure)
                        .with_attrs(::serde_json::json!({"image_provider": "imagen"})),
                    "linkedin_client: Imagen response missing image data"
                );
                anyhow::Error::msg("No image data in Imagen response")
            })?;

        let bytes = base64_decode(b64)?;

View on GitHub (pinned to 88bb9c8533)

Solutions

  1. Read the embedded body_text — Google's error names the reason (auth, model access, safety block) precisely
  2. 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
  3. Enable the Imagen model on the project and confirm region + model id in the configured endpoint
  4. Rephrase the prompt if the body indicates a safety block, and keep another provider configured as a fallback
Defensive patterns

Strategy: fallback

Try / catch

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.

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of zeroclaw-labs/zeroclaw@88bb9c8533 (2026-08-23). Data as JSON: /api/errors/6342c18d7ddbeead. Report an issue: GitHub.