invoke-ai/InvokeAI · warning · HTTPException

str(e)

Error message

str(e)

What it means

When saving the preset image, style_preset_image_files.save raises ValueError (e.g. the service rejects the image, such as invalid dimensions/format constraints), and the endpoint re-raises it as HTTP 409 with the ValueError message as the detail. The generic 'str(e)' means the exact text comes from the file-saving service, not a fixed string.

Source

Thrown at invokeai/app/api/routers/style_presets.py:142

    if image is not None:
        if not image.content_type or not image.content_type.startswith("image"):
            raise HTTPException(status_code=415, detail="Not an image")

        contents = await image.read()
        try:
            pil_image = await asyncio.to_thread(Image.open, io.BytesIO(contents))

        except Exception:
            ApiDependencies.invoker.services.logger.error(traceback.format_exc())
            raise HTTPException(status_code=415, detail="Failed to read image")

        try:
            await asyncio.to_thread(
                ApiDependencies.invoker.services.style_preset_image_files.save, style_preset_id, pil_image
            )
        except ValueError as e:
            raise HTTPException(status_code=409, detail=str(e))
    else:
        try:
            await asyncio.to_thread(ApiDependencies.invoker.services.style_preset_image_files.delete, style_preset_id)
        except StylePresetImageFileNotFoundException:
            pass

    preset_data = PresetData(positive_prompt=positive_prompt, negative_prompt=negative_prompt)
    changes = StylePresetChanges(name=name, preset_data=preset_data, type=type, is_public=is_public)

    style_preset_image = await asyncio.to_thread(
        ApiDependencies.invoker.services.style_preset_image_files.get_url, style_preset_id
    )
    style_preset = await asyncio.to_thread(
        ApiDependencies.invoker.services.style_preset_records.update,
        style_preset_id=style_preset_id,
        changes=changes,
    )
    return StylePresetRecordWithImage(image=style_preset_image, **style_preset.model_dump())

View on GitHub (pinned to 0b6a024f2f)

Solutions

  1. Read the 409 detail string — it is the service's ValueError and usually names the violated constraint.
  2. Downscale or crop the image (e.g. to <=2048px) and re-upload as PNG/JPEG.
  3. Retry with a known-good small test image to confirm the constraint, then fix the source image accordingly.
  4. If the constraint seems wrong for your install, check the image file service configuration / InvokeAI version for changed limits.

Example fix

// before
const img = await loadImage(hugeFile); // 12000x8000 -> save() ValueError

// after
const img = await loadImage(hugeFile);
const scaled = scaleToFit(img, 2048, 2048); // respect saver constraints
await uploadImage(scaled);
Defensive patterns

Strategy: try-catch

Validate before calling

const MAX_DIM = 2048;
async function assertImageWithinLimits(file) {
  const bmp = await createImageBitmap(file);
  if (bmp.width > MAX_DIM || bmp.height > MAX_DIM || bmp.width <= 0 || bmp.height <= 0) {
    throw new Error(`image ${bmp.width}x${bmp.height} exceeds saver limits`);
  }
}

Type guard

function isWithinSaverLimits(img: { width: number; height: number }): boolean {
  return img.width > 0 && img.height > 0 && img.width <= 2048 && img.height <= 2048;
}

Try / catch

try {
  await api.updateStylePreset({ stylePresetId, data, image });
} catch (e) {
  if (e.status === 409) {
    // detail is the saver's ValueError message — show it and offer resize+retry
    const resized = await scaleToFit(image, 2048, 2048);
    await api.updateStylePreset({ stylePresetId, data, image: resized });
  } else throw e;
}

Prevention

When it happens

Trigger: PATCH /style_presets/i/{id} with a valid decodable image whose save is rejected by the image file service — typically images violating the service's constraints (oversized dimensions, format the saver refuses, path/validation checks inside save).

Common situations: Uploading extremely large or extreme-aspect images; a saver that enforces max dimensions (e.g. 2k/4k limit); calling update on a preset whose storage backend is in a bad state; version changes to the image file service's accepted constraints.

Related errors


AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29). Data as JSON: /api/errors/80aadecf36375f73. Report an issue: GitHub.