Skip to content

Data pruning endpoint - #54

Open
jekuaitk wants to merge 3 commits into
upstream/v0.9.6from
feature/prune-endpoint
Open

Data pruning endpoint#54
jekuaitk wants to merge 3 commits into
upstream/v0.9.6from
feature/prune-endpoint

Conversation

@jekuaitk

@jekuaitk jekuaitk commented Jul 8, 2026

Copy link
Copy Markdown

Adds a admin-only POST endpoint:

POST  /api/v1/prune/chats?days=N&dry_run=&limit=

Deletes chats that have not been updated for a given number of days. Requires an admin token
(JWT or API key) in the Authorization: Bearer header — non-admin callers get 401.

Parameter Type Required Description
days int ≥ 1 yes Retention threshold: any chat whose updated_at is older than days days is a candidate for deletion.
dry_run bool no (default false) When true, only counts the matching chats and deletes nothing.
limit int ≥ 1 no (default unlimited) Caps how many chats are processed in this call. Candidates are processed oldest-first, so repeated limited calls work through the backlog chronologically.

Pinned chats are always spared, regardless of age. Archived chats are pruned like any other.
Deleting a chat also removes its messages and shared-link copies, and tags that end up unused
by any of the affected user's remaining chats are cleaned up.

Examples

# Preview what a 180-day retention policy would delete
curl -X POST '.../api/v1/prune/chats?days=180&dry_run=true' -H "Authorization: Bearer $TOKEN"

# Prune at most 500 chats
curl -X POST '.../api/v1/prune/chats?days=180&limit=500' -H "Authorization: Bearer $TOKEN"

@jekuaitk jekuaitk added WIP Work in progress Patch (do not merge) labels Jul 8, 2026
@jekuaitk
jekuaitk requested a review from cableman July 13, 2026 11:48

@cableman cableman left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about files user may have uploaded into chats? Do the project not have an "hook"/"function" to delete chats that purge all data involved. It exists in the front end as delete chat call?

UPDATE: Never mind

Comment thread backend/open_webui/routers/aak_prune.py Outdated
user=Depends(get_admin_user),
db: AsyncSession = Depends(get_async_session),
):
cutoff = int(time.time()) - days * 86400

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is cutoff? magic number

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added comment explaining!

@jekuaitk
jekuaitk force-pushed the feature/prune-endpoint branch from a07e538 to a03d547 Compare July 24, 2026 11:21
@jekuaitk
jekuaitk requested a review from cableman July 27, 2026 11:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants