open-webui/open-webui · error · HTTPException

ERROR_MESSAGES.NOT_FOUND

Error message

ERROR_MESSAGES.NOT_FOUND

What it means

404 raised by GET /api/v1/chats/stats/export/{chat_id} in export_single_chat_stats when Chats.get_chat_by_id(chat_id) returns no row. The endpoint exports per-chat statistics, so a nonexistent (or deleted) chat ID cannot produce a payload. Note the lookup is by chat_id, not share_id, and is not filtered by owner at this stage, so a wrong-ID typo is the dominant cause.

Source

Thrown at backend/open_webui/routers/chats.py:649

    user=Depends(get_verified_user),
    db: AsyncSession = Depends(get_async_session),
):
    """
    Export stats for exactly one chat by ID.
    Returns ChatStatsExport for the specified chat.
    """
    # Check if the user has permission to share/export chats
    if (user.role != 'admin') and (not await Config.get('ui.enable_community_sharing')):
        raise HTTPException(
            status_code=status.HTTP_401_UNAUTHORIZED,
            detail=ERROR_MESSAGES.ACCESS_PROHIBITED,
        )

    try:
        chat = await Chats.get_chat_by_id(chat_id, db=db)

        if not chat:
            raise HTTPException(
                status_code=status.HTTP_404_NOT_FOUND,
                detail=ERROR_MESSAGES.NOT_FOUND,
            )

        # Verify the chat belongs to the user (unless admin)
        if chat.user_id != user.id and user.role != 'admin':
            raise HTTPException(
                status_code=status.HTTP_401_UNAUTHORIZED,
                detail=ERROR_MESSAGES.ACCESS_PROHIBITED,
            )

        # Process the chat for export (pure computation, no DB)
        chat_stats = _process_chat_for_export(chat)

        if not chat_stats:
            raise HTTPException(
                status_code=status.HTTP_400_BAD_REQUEST,
                detail='Failed to process chat stats',

View on GitHub (pinned to 01f4282f1f)

Solutions

  1. Verify the chat exists first: GET /api/v1/chats/{id} (or check the chat list endpoint) before requesting the stats export.
  2. Confirm you are passing the internal chat id (chat.id), not the share_id.
  3. If the chat was deleted, remove it from your client state and stop retrying the export.

Example fix

// before
const stats = await fetch(`/api/v1/chats/stats/export/${chatId}`); // 404 on deleted chat

// after
const chat = await fetch(`/api/v1/chats/${chatId}`);
if (!chat.ok) { /* drop chatId from local state */ }
else { const stats = await fetch(`/api/v1/chats/stats/export/${chatId}`); }
Defensive patterns

Strategy: validation

Validate before calling

const res = await fetch(`/api/v1/chats/${chatId}`, { headers: authHeaders() });
if (res.status === 404 || res.status === 401) { removeChatFromState(chatId); return; }
// chat exists, safe to export stats
const stats = await fetch(`/api/v1/chats/stats/export/${chatId}`, { headers: authHeaders() });

Try / catch

try { await getStatsExport(chatId); } catch (e) { if (e.status === 404) removeChatFromState(chatId); else throw e; }

Prevention

When it happens

Trigger: Calling /api/v1/chats/stats/export/{chat_id} with a chat_id that does not exist in the chat table; using a share_id instead of the internal chat id; exporting a chat that was just deleted by the user or purged by an admin.

Common situations: Stale chat ID kept in client state after the chat was deleted; confusion between chat.id and chat.share_id in Open WebUI data model; deleted chats remaining in a cached frontend list.

Related errors


AI-assisted analysis of open-webui/open-webui@01f4282f1f (2026-08-14). Data as JSON: /api/errors/e9d851de6b22ef62. Report an issue: GitHub.