Adds pagination to chat list endpoints to prevent Out of Memory (OOM) crashes when users have large numbers of chats.
Problem
When calling /api/v1/chats/all or /api/v1/chats/all/archived without pagination, the server loads ALL chats into memory. For users with thousands of chats, this can cause OOM crashes.
Changes
models/chats.py: Added skip and limit parameters to get_chats() and get_archived_chats_by_user_id()
routers/chats.py: Updated /chats/all, /chats/all/archived, /chats/all/db endpoints with pagination parameters
Default limit of 50 prevents loading unbounded data
API Changes
GET /api/v1/chats/all?skip=0&limit=50
GET /api/v1/chats/all/archived?skip=0&limit=50
GET /api/v1/chats/all/db?skip=0&limit=50
By submitting this pull request, I confirm that my contributions are made under the Apache 2.0 license.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.
## 📋 Pull Request Information
**Original PR:** https://github.com/open-webui/open-webui/pull/23046
**Author:** [@yang1002378395-cmyk](https://github.com/yang1002378395-cmyk)
**Created:** 3/26/2026
**Status:** ❌ Closed
**Base:** `dev` ← **Head:** `fix-oom-pagination`
---
### 📝 Commits (1)
- [`efb0f9a`](https://github.com/open-webui/open-webui/commit/efb0f9a6f29ce9afa1ee50b7e6bb3d628e636fd2) fix: add pagination to chat list endpoints to prevent OOM
### 📊 Changes
**2 files changed** (+34 additions, -15 deletions)
<details>
<summary>View changed files</summary>
📝 `backend/open_webui/models/chats.py` (+19 -9)
📝 `backend/open_webui/routers/chats.py` (+15 -6)
</details>
### 📄 Description
## Summary
Fixes #22206
Adds pagination to chat list endpoints to prevent Out of Memory (OOM) crashes when users have large numbers of chats.
## Problem
When calling `/api/v1/chats/all` or `/api/v1/chats/all/archived` without pagination, the server loads ALL chats into memory. For users with thousands of chats, this can cause OOM crashes.
## Changes
- **models/chats.py**: Added `skip` and `limit` parameters to `get_chats()` and `get_archived_chats_by_user_id()`
- **routers/chats.py**: Updated `/chats/all`, `/chats/all/archived`, `/chats/all/db` endpoints with pagination parameters
- Default limit of 50 prevents loading unbounded data
## API Changes
```
GET /api/v1/chats/all?skip=0&limit=50
GET /api/v1/chats/all/archived?skip=0&limit=50
GET /api/v1/chats/all/db?skip=0&limit=50
```
## Testing
Tested locally with:
- 1000+ chats in database
- Verified memory usage stays constant
- Verified pagination returns correct subsets
## Related
Based on closed PR #22464 with formatting fixes.
---
### Contributor License Agreement
By submitting this pull request, I confirm that my contributions are made under the Apache 2.0 license.
---
<sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
📋 Pull Request Information
Original PR: https://github.com/open-webui/open-webui/pull/23046
Author: @yang1002378395-cmyk
Created: 3/26/2026
Status: ❌ Closed
Base:
dev← Head:fix-oom-pagination📝 Commits (1)
efb0f9afix: add pagination to chat list endpoints to prevent OOM📊 Changes
2 files changed (+34 additions, -15 deletions)
View changed files
📝
backend/open_webui/models/chats.py(+19 -9)📝
backend/open_webui/routers/chats.py(+15 -6)📄 Description
Summary
Fixes #22206
Adds pagination to chat list endpoints to prevent Out of Memory (OOM) crashes when users have large numbers of chats.
Problem
When calling
/api/v1/chats/allor/api/v1/chats/all/archivedwithout pagination, the server loads ALL chats into memory. For users with thousands of chats, this can cause OOM crashes.Changes
skipandlimitparameters toget_chats()andget_archived_chats_by_user_id()/chats/all,/chats/all/archived,/chats/all/dbendpoints with pagination parametersAPI Changes
Testing
Tested locally with:
Related
Based on closed PR #22464 with formatting fixes.
Contributor License Agreement
By submitting this pull request, I confirm that my contributions are made under the Apache 2.0 license.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.