invoke-ai/InvokeAI · error · HTTPException

Failed to add images to board

Error message

Failed to add images to board

What it means

HTTP 500 raised by POST /board_images/batch (add_images_to_board) when the bulk add flow throws any exception that is not an HTTPException. Unlike per-image HTTP errors which are collected in failed_images, unexpected service/DB failures bubble up as this generic 500.

Source

Thrown at invokeai/app/api/routers/board_images.py:324

                # reverted on reload.
                #
                # Except that a name deleted between the ownership check and the insert lands
                # here too, and not as something recognizable: board_images.image_name is a
                # foreign key onto images.image_name, so the INSERT fails with a bare
                # sqlite3.IntegrityError. Nothing in the exception says "gone", so the record
                # is probed instead — only on this path, so the happy path pays nothing.
                if not _image_record_exists(image_name):
                    continue
                failed_images.add(image_name)
        return AddImagesToBoardResult(
            added_images=list(added_images),
            failed_images=list(failed_images),
            affected_boards=list(affected_boards),
        )
    except HTTPException:
        raise
    except Exception:
        raise HTTPException(status_code=500, detail="Failed to add images to board")


@board_images_router.post(
    "/batch/delete",
    operation_id="remove_images_from_board",
    responses={
        201: {"description": "Images were removed from board successfully"},
    },
    status_code=201,
    response_model=RemoveImagesFromBoardResult,
)
def remove_images_from_board(
    current_user: CurrentUserOrDefault,
    image_names: list[ImageName] = Body(
        description="The names of the images to remove", embed=True, max_length=MAX_IMAGE_BATCH_SIZE
    ),
) -> RemoveImagesFromBoardResult:
    """Removes a list of images from their board, if they had one"""

View on GitHub (pinned to 0b6a024f2f)

Solutions

  1. Inspect server logs for the original exception trace
  2. Validate board_id exists first via GET /boards/{board_id}
  3. Re-run the batch for only the images missing from failed_images
  4. Check database connectivity and disk space
  5. Update InvokeAI if hits persist on a current board_id

Example fix

// before
await api.post('/board_images/batch', { image_names, board_id });
// after
const board = await api.get(`/boards/${board_id}`); // 404 early if board gone
await api.post('/board_images/batch', { image_names, board_id });
Defensive patterns

Strategy: validation

Validate before calling

const board = await api.get(`/boards/${boardId}`).catch(() => null);
if (!board) throw new Error(`Board ${boardId} not found; aborting batch add`);

Type guard

const isBoardMissing = (e) => e?.response?.status === 404;

Try / catch

try {
  await api.post('/board_images/batch', { image_names, board_id });
} catch (e) {
  if (e.response?.status === 500) {
    // retry per-image to isolate failures
    await Promise.allSettled(image_names.map(n => api.post('/board_images/', { image_name: n, board_id })));
    return;
  }
  throw e;
}

Prevention

When it happens

Trigger: POST /board_images/batch with body {image_names: [...], board_id} where the boards service throws while adding associations — e.g. board_id deleted concurrently, database error, or a service-layer exception.

Common situations: Board deleted by another client between UI load and batch add, Postgres/SQLite connection drop, invalid board_id containing characters that break the lookup, or invoking the batch while the DB is under migration.

Related errors


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