{"record":{"id":"bd4d4b0e0a94c57b","repo":"AUTOMATIC1111/stable-diffusion-webui","slug":"init-image-not-found","errorCode":null,"errorMessage":"Init image not found","messagePattern":"Init image not found","errorType":"http","errorClass":"HTTPException","httpStatus":404,"severity":"error","filePath":"modules/api/api.py","lineNumber":497,"sourceCode":"                        processed = scripts.scripts_txt2img.run(p, *p.script_args) # Need to pass args as list here\n                    else:\n                        p.script_args = tuple(script_args) # Need to pass args as tuple here\n                        processed = process_images(p)\n                    finish_task(task_id)\n                finally:\n                    shared.state.end()\n                    shared.total_tqdm.clear()\n\n        b64images = list(map(encode_pil_to_base64, processed.images)) if send_images else []\n\n        return models.TextToImageResponse(images=b64images, parameters=vars(txt2imgreq), info=processed.js())\n\n    def img2imgapi(self, img2imgreq: models.StableDiffusionImg2ImgProcessingAPI):\n        task_id = img2imgreq.force_task_id or create_task_id(\"img2img\")\n\n        init_images = img2imgreq.init_images\n        if init_images is None:\n            raise HTTPException(status_code=404, detail=\"Init image not found\")\n\n        mask = img2imgreq.mask\n        if mask:\n            mask = decode_base64_to_image(mask)\n\n        script_runner = scripts.scripts_img2img\n\n        infotext_script_args = {}\n        self.apply_infotext(img2imgreq, \"img2img\", script_runner=script_runner, mentioned_script_args=infotext_script_args)\n\n        selectable_scripts, selectable_script_idx = self.get_selectable_script(img2imgreq.script_name, script_runner)\n        sampler, scheduler = sd_samplers.get_sampler_and_scheduler(img2imgreq.sampler_name or img2imgreq.sampler_index, img2imgreq.scheduler)\n\n        populate = img2imgreq.copy(update={  # Override __init__ params\n            \"sampler_name\": validate_sampler_name(sampler),\n            \"do_not_save_samples\": not img2imgreq.save_images,\n            \"do_not_save_grid\": not img2imgreq.save_images,\n            \"mask\": mask,","sourceCodeStart":479,"sourceCodeEnd":515,"githubUrl":"https://github.com/AUTOMATIC1111/stable-diffusion-webui/blob/82a973c04367123ae98bd9abdf80d9eda9b910e2/modules/api/api.py#L479-L515","documentation":"HTTP 404 raised at the start of img2imgapi when the StableDiffusionImg2ImgProcessingAPI request object has init_images set to None. init_images is the required list of base64 images to redraw; the API model marks it optional (None default) so FastAPI does not auto-reject, and this explicit check catches the omission.","triggerScenarios":"POST /sdapi/v1/img2img (or /sdapi/v1/png-info -> img2img flow) with a JSON body lacking the init_images key, or explicitly \"init_images\": null; also clients that build the payload dynamically and skip the field when no image was selected.","commonSituations":"Upstream UI bugs where the user clicked img2img without attaching an image; automation scripts reusing txt2img payloads; field renamed/typo'd (image vs init_images) by client code.","solutions":["Include init_images as a list of base64-encoded image strings: {'init_images': [b64, ...]}","Validate the payload before sending: assert payload.get('init_images')"],"exampleFix":"# before\njson={'prompt':'cat','denoising_strength':0.7}\n\n# after\nimport base64\nb64 = base64.b64encode(open('input.png','rb').read()).decode()\njson={'prompt':'cat','denoising_strength':0.7,'init_images':[b64]}","handlingStrategy":"validation","validationCode":"assert payload.get('init_images'), 'img2img requires init_images: [b64, ...]'\nassert all(isinstance(x, str) and len(x) > 32 for x in payload['init_images'])","typeGuard":"def is_valid_img2img_payload(p: dict) -> bool:\n    return isinstance(p.get('init_images'), list) and len(p['init_images']) > 0","tryCatchPattern":null,"preventionTips":["Client-side required-field checks before POST","Disable the img2img submit path until an image is attached","Keep a payload schema (pydantic model) mirroring the API in client code"],"tags":["api","img2img","http-404","validation","stable-diffusion-webui"],"backgroundTag":null,"analyzedSha":"82a973c04367123ae98bd9abdf80d9eda9b910e2","analyzedAt":"2026-08-14T16:46:43.225Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}