{"record":{"id":"e9d851de6b22ef62","repo":"open-webui/open-webui","slug":"error-messages-not-found-e9d851","errorCode":null,"errorMessage":"ERROR_MESSAGES.NOT_FOUND","messagePattern":"ERROR_MESSAGES\\.NOT_FOUND","errorType":"http","errorClass":"HTTPException","httpStatus":404,"severity":"error","filePath":"backend/open_webui/routers/chats.py","lineNumber":649,"sourceCode":"    user=Depends(get_verified_user),\n    db: AsyncSession = Depends(get_async_session),\n):\n    \"\"\"\n    Export stats for exactly one chat by ID.\n    Returns ChatStatsExport for the specified chat.\n    \"\"\"\n    # Check if the user has permission to share/export chats\n    if (user.role != 'admin') and (not await Config.get('ui.enable_community_sharing')):\n        raise HTTPException(\n            status_code=status.HTTP_401_UNAUTHORIZED,\n            detail=ERROR_MESSAGES.ACCESS_PROHIBITED,\n        )\n\n    try:\n        chat = await Chats.get_chat_by_id(chat_id, db=db)\n\n        if not chat:\n            raise HTTPException(\n                status_code=status.HTTP_404_NOT_FOUND,\n                detail=ERROR_MESSAGES.NOT_FOUND,\n            )\n\n        # Verify the chat belongs to the user (unless admin)\n        if chat.user_id != user.id and user.role != 'admin':\n            raise HTTPException(\n                status_code=status.HTTP_401_UNAUTHORIZED,\n                detail=ERROR_MESSAGES.ACCESS_PROHIBITED,\n            )\n\n        # Process the chat for export (pure computation, no DB)\n        chat_stats = _process_chat_for_export(chat)\n\n        if not chat_stats:\n            raise HTTPException(\n                status_code=status.HTTP_400_BAD_REQUEST,\n                detail='Failed to process chat stats',","sourceCodeStart":631,"sourceCodeEnd":667,"githubUrl":"https://github.com/open-webui/open-webui/blob/01f4282f1ffe0d6212f58d3afbeae21fffd0c4be/backend/open_webui/routers/chats.py#L631-L667","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Verify the chat exists first: GET /api/v1/chats/{id} (or check the chat list endpoint) before requesting the stats export.","Confirm you are passing the internal chat id (chat.id), not the share_id.","If the chat was deleted, remove it from your client state and stop retrying the export."],"exampleFix":"// before\nconst stats = await fetch(`/api/v1/chats/stats/export/${chatId}`); // 404 on deleted chat\n\n// after\nconst chat = await fetch(`/api/v1/chats/${chatId}`);\nif (!chat.ok) { /* drop chatId from local state */ }\nelse { const stats = await fetch(`/api/v1/chats/stats/export/${chatId}`); }","handlingStrategy":"validation","validationCode":"const res = await fetch(`/api/v1/chats/${chatId}`, { headers: authHeaders() });\nif (res.status === 404 || res.status === 401) { removeChatFromState(chatId); return; }\n// chat exists, safe to export stats\nconst stats = await fetch(`/api/v1/chats/stats/export/${chatId}`, { headers: authHeaders() });","typeGuard":null,"tryCatchPattern":"try { await getStatsExport(chatId); } catch (e) { if (e.status === 404) removeChatFromState(chatId); else throw e; }","preventionTips":["Always use chat.id (never share_id) for stats export","Drop chat ids from client state when list endpoints stop returning them"],"tags":["http-404","chat-export","open-webui","rest-api"],"backgroundTag":null,"analyzedSha":"01f4282f1ffe0d6212f58d3afbeae21fffd0c4be","analyzedAt":"2026-08-14T18:25:22.715Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}