{"record":{"id":"76cbbf6d35991914","repo":"oobabooga/textgen","slug":"image-generation-failed-or-produced-no-images","errorCode":null,"errorMessage":"Image generation failed or produced no images.","messagePattern":"Image generation failed or produced no images\\.","errorType":"exception","errorClass":"ServiceUnavailableError","httpStatus":503,"severity":"error","filePath":"modules/api/images.py","lineNumber":50,"sourceCode":"        'image_prompt': request.prompt,\n        'image_neg_prompt': request.negative_prompt,\n        'image_width': width,\n        'image_height': height,\n        'image_steps': request.steps,\n        'image_seed': request.image_seed,\n        'image_batch_size': request.batch_size,\n        'image_batch_count': request.batch_count,\n        'image_cfg_scale': request.cfg_scale,\n        'image_llm_variations': False,\n    })\n\n    # Exhaust generator, keep final result\n    images = []\n    for images, _ in generate(state, save_images=False):\n        pass\n\n    if not images:\n        raise ServiceUnavailableError(\"Image generation failed or produced no images.\")\n\n    # Build response with per-batch metadata (seed increments per batch)\n    base_seed = state.get('image_seed_resolved', state['image_seed'])\n    batch_size = int(state['image_batch_size'])\n\n    resp = {'created': int(time.time()), 'data': []}\n    for idx, img in enumerate(images):\n        batch_seed = base_seed + idx // batch_size\n        metadata = build_generation_metadata(state, batch_seed)\n        metadata_json = json.dumps(metadata, ensure_ascii=False)\n        png_info = PngInfo()\n        png_info.add_text(\"image_gen_settings\", metadata_json)\n        b64 = _image_to_base64(img, png_info)\n\n        image_obj = {'revised_prompt': request.prompt}\n\n        if request.response_format == 'b64_json':\n            image_obj['b64_json'] = b64","sourceCodeStart":32,"sourceCodeEnd":68,"githubUrl":"https://github.com/oobabooga/textgen/blob/ed888c71f221df552750e1834b3654abab8ae345/modules/api/images.py#L32-L68","documentation":"After running the image generation pipeline (generator is exhausted with save_images=False), the endpoint expects at least one produced image. If the generator yields nothing or its final result is an empty list, ServiceUnavailableError (503) is raised, signaling the diffusion run failed silently (bad seed/step/cfg config, OOM, or pipeline error swallowed by the generator).","triggerScenarios":"POST image generation where the underlying generate(state) generator completes without yielding images: e.g. resolution/steps values the loaded model rejects, VRAM exhaustion mid-batch, a corrupted model, or request params (steps=0, degenerate width/height) that short-circuit the pipeline.","commonSituations":"Requesting sizes the diffusion model does not support; too-large batch_size/count exhausting VRAM; model checkpoint partially downloaded; prompt pipeline errors that the UI would surface as a red error but the API surfaces as empty output.","solutions":["Retry the exact same generation through the UI image tab to see the real underlying error message.","Reduce load: lower width/height, steps, batch_size and batch_count to baseline values.","Re-download/re-verify the diffusion model checkpoint (hash/size) if generations consistently return empty.","Check server logs around the request for CUDA OOM or pipeline exceptions."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"def sane_image_request(req: dict) -> bool:\n    return (req.get('steps', 20) >= 1\n            and 64 <= req.get('width', 512) <= 2048\n            and 64 <= req.get('height', 512) <= 2048\n            and 1 <= req.get('batch_size', 1) <= 4)","typeGuard":null,"tryCatchPattern":"try:\n    img = client.images.generate(model='x', prompt=p, size='512x512')\nexcept openai.APIStatusError as e:\n    if e.status_code == 503 and 'produced no images' in str(e):\n        # one retry with reduced load, then surface the pipeline failure\n        img = client.images.generate(model='x', prompt=p, size='256x256', steps=20)\n    else:\n        raise","preventionTips":["Validate width/height/steps/batch against the loaded model's supported ranges before calling.","Watch server logs for the real cause (OOM, pipeline exception) whenever the API returns empty.","Keep batch_size small on limited VRAM; scale up only after a successful probe generation."],"tags":["image-generation","service-unavailable","diffusion","empty-result"],"backgroundTag":null,"analyzedSha":"ed888c71f221df552750e1834b3654abab8ae345","analyzedAt":"2026-08-15T05:24:21.000Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}