invoke-ai/InvokeAI · warning · HTTPException

Style preset not found

Error message

Style preset not found

What it means

This HTTP 404 is raised by _load_record_or_404 when the style preset records service throws StylePresetNotFoundError, i.e. no preset exists with the given style_preset_id. It is shared by get, delete, and image-fetch endpoints so unknown IDs consistently return 404.

Source

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

    raise HTTPException(status_code=403, detail="Not authorized to access this style preset")


def _assert_preset_write(record: StylePresetRecordDTO, current_user: TokenData) -> None:
    """Allow write access only for admin or owner. Defaults are immutable for non-admins."""
    if current_user.is_admin:
        return
    if record.type == PresetType.Default:
        raise HTTPException(status_code=403, detail="Default style presets cannot be modified")
    if record.user_id == current_user.user_id:
        return
    raise HTTPException(status_code=403, detail="Not authorized to modify this style preset")


def _load_record_or_404(style_preset_id: str) -> StylePresetRecordDTO:
    try:
        return ApiDependencies.invoker.services.style_preset_records.get(style_preset_id)
    except StylePresetNotFoundError:
        raise HTTPException(status_code=404, detail="Style preset not found")


@style_presets_router.get(
    "/i/{style_preset_id}",
    operation_id="get_style_preset",
    responses={
        200: {"model": StylePresetRecordWithImage},
    },
)
def get_style_preset(
    current_user: CurrentUserOrDefault,
    style_preset_id: str = Path(description="The style preset to get"),
) -> StylePresetRecordWithImage:
    """Gets a style preset"""
    record = _load_record_or_404(style_preset_id)
    _assert_preset_read(record, current_user)
    image = ApiDependencies.invoker.services.style_preset_image_files.get_url(style_preset_id)
    return StylePresetRecordWithImage(image=image, **record.model_dump())

View on GitHub (pinned to 0b6a024f2f)

Solutions

  1. List available presets (GET /style_presets/) and confirm the ID exists
  2. Refresh client-side cached preset references; remove stale IDs from persisted state
  3. Treat 404 as final for deleted presets — re-import the preset from its export file if still needed
  4. Double-check the ID string for truncation or copying errors

Example fix

// before
const preset = await api.get(`/style_presets/i/${id}`); // throws if deleted
// after
try {
  const preset = await api.get(`/style_presets/i/${id}`);
} catch (e) {
  if (e.response?.status === 404) {
    localStorage.removeItem('lastPresetId');
    const all = await api.get('/style_presets/');
    return all.data;
  }
  throw e;
}
Defensive patterns

Strategy: try-catch

Validate before calling

const all = (await api.get('/style_presets/')).data;
if (!all.some(p => p.id === stylePresetId)) {
  console.warn(`Preset ${stylePresetId} not in current preset list; it may be deleted`);
}

Type guard

function isKnownPreset(presetList, id) {
  return Array.isArray(presetList) && presetList.some(p => p?.id === id);
}

Try / catch

try {
  return (await api.get(`/style_presets/i/${id}`)).data;
} catch (e) {
  if (e.response?.status === 404) {
    invalidateCachedPreset(id);
    return null;
  }
  throw e;
}

Prevention

When it happens

Trigger: GET/DELETE on /style_presets/i/{style_preset_id} with an ID that was deleted, never existed, or is mistyped.

Common situations: Preset deleted by another user/admin while a client still references it; stale ID stored in browser localStorage after a DB reset or fresh install; IDs from a different InvokeAI instance or an exported file from another deployment.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


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