pbakaus/impeccable · error

generate-image: no image in response

Error message

generate-image: no image in response

What it means

The API call succeeded (2xx) but the JSON response contained no usable image: the `data[0].b64_json` field was missing or empty. generate-image cannot write an output file without it, so it reports "no image in response" and exits 1.

Source

Thrown at crates/context/src/generate_image.rs:369

        Ok(r) => {
            let st = r.status();
            (st, r.into_string().unwrap_or_default())
        }
        Err(ureq::Error::Status(code, r)) => (code, r.into_string().unwrap_or_default()),
        Err(e) => {
            io.err(&format!("TypeError: fetch failed: {}\n", e));
            return 1;
        }
    };
    if !(200..300).contains(&status) {
        let snippet: String = text.chars().take(300).collect();
        io.err(&format!("generate-image: API error {}: {}\n", status, snippet));
        return 1;
    }
    let json: Value = serde_json::from_str(&text).unwrap_or(Value::Null);
    let b64 = json.get("data").and_then(|d| d.get(0)).and_then(|d| d.get("b64_json")).and_then(|b| b.as_str()).filter(|s| !s.is_empty());
    let Some(b64) = b64 else {
        io.err("generate-image: no image in response\n");
        return 1;
    };
    let bytes = base64_decode(b64);
    let _ = std::fs::write(abs(&out), bytes);
    // best-effort embed + sidecar
    // JS-PARITY: generate-image.mjs#676 reports whether the embed actually
    // succeeded. The install-path-with-spaces half of #676 is a JS-only
    // subprocess concern (fileURLToPath vs URL.pathname); the engine embeds
    // in-process, so only the success tracking and message carry over here.
    let embedded;
    {
        let mut sub_io = Io::captured("", io.cwd.clone(), io.env.clone()).0;
        let ret = crate::embed_prompt::run(&[out.clone(), "--prompt".to_string(), prompt.clone()], &mut sub_io);
        embedded = ret == 0;
        if !embedded {
            io.err("generate-image: failed to embed prompt in the image\n");
        }
        let mut m = Map::new();

View on GitHub (pinned to 2bc2879276)

Solutions

  1. Re-run with a different, clearly safe prompt to rule out content-filter suppression.
  2. Verify you are using the supported model/endpoint whose response includes b64_json; adjust model/parameters if the API version changed.
  3. Inspect the raw response (network log) to see whether data contains url instead of b64_json and adapt the workflow accordingly.
  4. Check for proxy/gateway interference that strips or rewrites the JSON body.
  5. Retry — occasionally transient API-side issues return empty payloads.

Example fix

// before
// response: {"data":[{"url":"https://..."}]} → no image in response
// after
// request the format that returns base64 (b64_json) for the model in use, then rerun:
impeccable generate-image --prompt "..." --out o.png
Defensive patterns

Strategy: fallback

Type guard

function hasB64Image(json) {
  return typeof json?.data?.[0]?.b64_json === "string" && json.data[0].b64_json.length > 0;
}
// if the raw response is available: if (!hasB64Image(parsed)) handleEmpty();

Try / catch

const r = spawnSync("impeccable", ["generate-image", ...], { encoding: "utf8" });
if (r.status !== 0 && r.stderr.includes("no image in response")) {
  // inspect response shape / adjust model or prompt, then retry once with a safe prompt
  retryWithSafePrompt();
}

Prevention

When it happens

Trigger: The response JSON parses but `json["data"][0]["b64_json"]` is absent or an empty string — e.g. the API returned a URL instead of base64 (response_format mismatch), the request was content-filtered with an empty data array, or an unexpected schema from a different/updated endpoint.

Common situations: Model or API version changes that alter the response shape; prompts flagged by the safety system returning empty results; a gateway/interceptor (corporate proxy) rewriting the response; account settings returning URLs rather than b64 payloads.

Understand the failure class

Background: "invalid response format", "malformed payload", "missing data field": when an API returns 200 but the response shape is wrong — this error's family across 23 libraries.

Related errors


AI-assisted analysis of pbakaus/impeccable@2bc2879276 (2026-09-08). Data as JSON: /api/errors/2f19e98ff6011a8a. Report an issue: GitHub.