Overview
Deletes a thread and all associated data including messages and agent runs. If the thread is the last one in its project, the project and its sandbox are also deleted automatically.Request
The unique identifier of the thread to delete
Authentication
Requires write access to the thread. The endpoint usesrequire_thread_write_access which validates:
- Valid JWT token
- User owns the thread OR has write access through account membership
cURL
Python SDK
JavaScript SDK
Response
Confirmation message
The ID of the deleted thread
Response Example
Deletion Process
The endpoint performs the following operations in order:1. Thread Data Deletion
- Deletes all agent runs associated with the thread
- Deletes all messages in the thread
- Deletes the thread record itself
2. Vector Store Cleanup
Removes thread embeddings from the semantic search vector store (non-blocking, logs warning if fails).3. Cache Invalidation
- Decrements thread count in slot manager (Redis cache)
- Invalidates runtime thread count cache
- Invalidates account state cache for billing
4. Project Cleanup (Conditional)
If this was the last thread in the project:Delete Sandbox
If a sandbox exists for the project:
- Retrieves sandbox resource information
- Calls sandbox deletion API
- Logs any errors (non-blocking)
Error Responses
Implementation Notes
Cascade Deletion
The following data is deleted when a thread is removed:- Agent Runs: All execution runs for the thread
- Messages: All messages (user, assistant, tool, etc.)
- Thread Embeddings: Vector embeddings for semantic search
- Thread Record: The thread database entry
Conditional Project Deletion
Projects are only deleted when:- The thread being deleted is the last thread in the project
- The project has no other references
Sandbox Cleanup
Sandbox deletion is attempted but errors are logged and don’t block the thread deletion. This ensures threads can be deleted even if sandbox cleanup fails.Cache Management
Multiple cache systems are updated:- Slot Manager: Real-time Redis counters for limits
- Runtime Cache: Legacy caching system (backward compatibility)
- Account State Cache: Billing and quota information
Source Reference
Implementation:/workspace/source/backend/core/threads/api.py:960Repository functions:
delete_thread_data:/workspace/source/backend/core/threads/repo.py:137count_project_threads:/workspace/source/backend/core/threads/repo.py:158delete_project:/workspace/source/backend/core/threads/repo.py:164