AUTOMATIC1111/stable-diffusion-webui · error · HTTPException

Init image not found

Error message

Init image not found

What it means

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.

Source

Thrown at modules/api/api.py:497

                        processed = scripts.scripts_txt2img.run(p, *p.script_args) # Need to pass args as list here
                    else:
                        p.script_args = tuple(script_args) # Need to pass args as tuple here
                        processed = process_images(p)
                    finish_task(task_id)
                finally:
                    shared.state.end()
                    shared.total_tqdm.clear()

        b64images = list(map(encode_pil_to_base64, processed.images)) if send_images else []

        return models.TextToImageResponse(images=b64images, parameters=vars(txt2imgreq), info=processed.js())

    def img2imgapi(self, img2imgreq: models.StableDiffusionImg2ImgProcessingAPI):
        task_id = img2imgreq.force_task_id or create_task_id("img2img")

        init_images = img2imgreq.init_images
        if init_images is None:
            raise HTTPException(status_code=404, detail="Init image not found")

        mask = img2imgreq.mask
        if mask:
            mask = decode_base64_to_image(mask)

        script_runner = scripts.scripts_img2img

        infotext_script_args = {}
        self.apply_infotext(img2imgreq, "img2img", script_runner=script_runner, mentioned_script_args=infotext_script_args)

        selectable_scripts, selectable_script_idx = self.get_selectable_script(img2imgreq.script_name, script_runner)
        sampler, scheduler = sd_samplers.get_sampler_and_scheduler(img2imgreq.sampler_name or img2imgreq.sampler_index, img2imgreq.scheduler)

        populate = img2imgreq.copy(update={  # Override __init__ params
            "sampler_name": validate_sampler_name(sampler),
            "do_not_save_samples": not img2imgreq.save_images,
            "do_not_save_grid": not img2imgreq.save_images,
            "mask": mask,

View on GitHub (pinned to 82a973c043)

Solutions

  1. Include init_images as a list of base64-encoded image strings: {'init_images': [b64, ...]}
  2. Validate the payload before sending: assert payload.get('init_images')

Example fix

# before
json={'prompt':'cat','denoising_strength':0.7}

# after
import base64
b64 = base64.b64encode(open('input.png','rb').read()).decode()
json={'prompt':'cat','denoising_strength':0.7,'init_images':[b64]}
Defensive patterns

Strategy: validation

Validate before calling

assert payload.get('init_images'), 'img2img requires init_images: [b64, ...]'
assert all(isinstance(x, str) and len(x) > 32 for x in payload['init_images'])

Type guard

def is_valid_img2img_payload(p: dict) -> bool:
    return isinstance(p.get('init_images'), list) and len(p['init_images']) > 0

Prevention

When it happens

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

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

Related errors


AI-assisted analysis of AUTOMATIC1111/stable-diffusion-webui@82a973c043 (2026-08-14). Data as JSON: /api/errors/bd4d4b0e0a94c57b. Report an issue: GitHub.