{"record":{"id":"2f19e98ff6011a8a","repo":"pbakaus/impeccable","slug":"generate-image-no-image-in-response","errorCode":null,"errorMessage":"generate-image: no image in response\n","messagePattern":"generate-image: no image in response\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/context/src/generate_image.rs","lineNumber":369,"sourceCode":"        Ok(r) => {\n            let st = r.status();\n            (st, r.into_string().unwrap_or_default())\n        }\n        Err(ureq::Error::Status(code, r)) => (code, r.into_string().unwrap_or_default()),\n        Err(e) => {\n            io.err(&format!(\"TypeError: fetch failed: {}\\n\", e));\n            return 1;\n        }\n    };\n    if !(200..300).contains(&status) {\n        let snippet: String = text.chars().take(300).collect();\n        io.err(&format!(\"generate-image: API error {}: {}\\n\", status, snippet));\n        return 1;\n    }\n    let json: Value = serde_json::from_str(&text).unwrap_or(Value::Null);\n    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());\n    let Some(b64) = b64 else {\n        io.err(\"generate-image: no image in response\\n\");\n        return 1;\n    };\n    let bytes = base64_decode(b64);\n    let _ = std::fs::write(abs(&out), bytes);\n    // best-effort embed + sidecar\n    // JS-PARITY: generate-image.mjs#676 reports whether the embed actually\n    // succeeded. The install-path-with-spaces half of #676 is a JS-only\n    // subprocess concern (fileURLToPath vs URL.pathname); the engine embeds\n    // in-process, so only the success tracking and message carry over here.\n    let embedded;\n    {\n        let mut sub_io = Io::captured(\"\", io.cwd.clone(), io.env.clone()).0;\n        let ret = crate::embed_prompt::run(&[out.clone(), \"--prompt\".to_string(), prompt.clone()], &mut sub_io);\n        embedded = ret == 0;\n        if !embedded {\n            io.err(\"generate-image: failed to embed prompt in the image\\n\");\n        }\n        let mut m = Map::new();","sourceCodeStart":351,"sourceCodeEnd":387,"githubUrl":"https://github.com/pbakaus/impeccable/blob/2bc2879276c1f321a53c4ca99d3371e411329b52/crates/context/src/generate_image.rs#L351-L387","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Re-run with a different, clearly safe prompt to rule out content-filter suppression.","Verify you are using the supported model/endpoint whose response includes b64_json; adjust model/parameters if the API version changed.","Inspect the raw response (network log) to see whether data contains url instead of b64_json and adapt the workflow accordingly.","Check for proxy/gateway interference that strips or rewrites the JSON body.","Retry — occasionally transient API-side issues return empty payloads."],"exampleFix":"// before\n// response: {\"data\":[{\"url\":\"https://...\"}]} → no image in response\n// after\n// request the format that returns base64 (b64_json) for the model in use, then rerun:\nimpeccable generate-image --prompt \"...\" --out o.png","handlingStrategy":"fallback","validationCode":null,"typeGuard":"function hasB64Image(json) {\n  return typeof json?.data?.[0]?.b64_json === \"string\" && json.data[0].b64_json.length > 0;\n}\n// if the raw response is available: if (!hasB64Image(parsed)) handleEmpty();","tryCatchPattern":"const r = spawnSync(\"impeccable\", [\"generate-image\", ...], { encoding: \"utf8\" });\nif (r.status !== 0 && r.stderr.includes(\"no image in response\")) {\n  // inspect response shape / adjust model or prompt, then retry once with a safe prompt\n  retryWithSafePrompt();\n}","preventionTips":["Pin the model/endpoint version whose responses include b64_json.","Avoid prompts likely to trip content filters when automation must succeed.","Log raw API responses in wrappers to diagnose schema changes quickly.","Beware proxies that rewrite JSON bodies."],"tags":["api","response-parsing","openai"],"backgroundTag":"unexpected-api-response-shape","analyzedSha":"2bc2879276c1f321a53c4ca99d3371e411329b52","analyzedAt":"2026-09-08T04:51:14.109Z","contentChangedAt":"2026-09-08T04:51:14.109Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}