import { createClient } from "@mailsai/sdk";
const client = createClient(); // reads MAILS_API_KEY
const result = await client.threads.remove(
"thrd_01JZX8K3M9Q4P7VN2YB6RTDC0E",
);
console.log(result);from mailsai import create_client
client = create_client() # reads MAILS_API_KEY
result = client.delete_thread(
"thrd_01JZX8K3M9Q4P7VN2YB6RTDC0E",
)
print(result)curl -X DELETE 'https://api.mails.ai/v1/threads/thrd_01JZX8K3M9Q4P7VN2YB6RTDC0E' \
-H "Authorization: Bearer $MAILS_API_KEY"mails threads delete thrd_01JABC
mails threads delete thrd_01JABC --permanent --yes{
"name": "mails_threads_delete",
"arguments": {
"thread_id": "thrd_01JZX8K3M9Q4P7VN2YB6RTDC0E"
}
}{
"id": "thrd_01JZX8K3M9Q4P7VN2YB6RTDC0E",
"agent_id": "agt_01JZX8K3M9Q4P7VN2YB6RTDC0E",
"subject": "<subject>",
"root_message_id": "msg_01JZX8K3M9Q4P7VN2YB6RTDC0E",
"last_message_id": "msg_01JZX8K3M9Q4P7VN2YB6RTDC0E",
"last_message_at": "2026-10-04T12:00:00.000Z",
"message_count": 0,
"participants": ["jordan@example.com"],
"labels": ["<labels>"],
"label_ids": ["lbl_01JZX8K3M9Q4P7VN2YB6RTDC0E"],
"status": "open",
"read": false,
"folder": "inbox",
"trashed_at": "2026-10-04T12:00:00.000Z",
"test_mode": false,
"created_at": "2026-10-04T12:00:00.000Z",
"updated_at": "2026-10-04T12:00:00.000Z",
"deleted": false
}200 The trashed thread, or the id of the thread deleted
for good.
400 Invalid request — malformed JSON or a field failed
validation. Also feature_not_enabled when this
server has a feature switched off (custom domains
before they are available).
401 Missing or invalid API key.
403 The API key lacks the required scope
(insufficient_scope), or the token belongs to an
app connected by sign-in and this operation is
closed to connected apps
(connected_app_not_allowed).
404 Resource not found in this workspace, or the agent
a send names is archived (agent_archived).
409 Conflict — duplicate resource, an in-progress
idempotent request, a draft or scheduled message
that started sending while it was being changed, or
a thread deleted for good while one of its messages
is being sent (duplicate_resource); or an agent
name more than one agent has (agent_name_conflict:
use the agent's id); or a status change on an
archived agent, since archiving cannot be undone
(agent_archived).
500 Internal server error.Trash or delete a thread
Moves the thread to trash (
deleted: false, the thread returned).import { createClient } from "@mailsai/sdk";
const client = createClient(); // reads MAILS_API_KEY
const result = await client.threads.remove(
"thrd_01JZX8K3M9Q4P7VN2YB6RTDC0E",
);
console.log(result);from mailsai import create_client
client = create_client() # reads MAILS_API_KEY
result = client.delete_thread(
"thrd_01JZX8K3M9Q4P7VN2YB6RTDC0E",
)
print(result)curl -X DELETE 'https://api.mails.ai/v1/threads/thrd_01JZX8K3M9Q4P7VN2YB6RTDC0E' \
-H "Authorization: Bearer $MAILS_API_KEY"mails threads delete thrd_01JABC
mails threads delete thrd_01JABC --permanent --yes{
"name": "mails_threads_delete",
"arguments": {
"thread_id": "thrd_01JZX8K3M9Q4P7VN2YB6RTDC0E"
}
}{
"id": "thrd_01JZX8K3M9Q4P7VN2YB6RTDC0E",
"agent_id": "agt_01JZX8K3M9Q4P7VN2YB6RTDC0E",
"subject": "<subject>",
"root_message_id": "msg_01JZX8K3M9Q4P7VN2YB6RTDC0E",
"last_message_id": "msg_01JZX8K3M9Q4P7VN2YB6RTDC0E",
"last_message_at": "2026-10-04T12:00:00.000Z",
"message_count": 0,
"participants": ["jordan@example.com"],
"labels": ["<labels>"],
"label_ids": ["lbl_01JZX8K3M9Q4P7VN2YB6RTDC0E"],
"status": "open",
"read": false,
"folder": "inbox",
"trashed_at": "2026-10-04T12:00:00.000Z",
"test_mode": false,
"created_at": "2026-10-04T12:00:00.000Z",
"updated_at": "2026-10-04T12:00:00.000Z",
"deleted": false
}200 The trashed thread, or the id of the thread deleted
for good.
400 Invalid request — malformed JSON or a field failed
validation. Also feature_not_enabled when this
server has a feature switched off (custom domains
before they are available).
401 Missing or invalid API key.
403 The API key lacks the required scope
(insufficient_scope), or the token belongs to an
app connected by sign-in and this operation is
closed to connected apps
(connected_app_not_allowed).
404 Resource not found in this workspace, or the agent
a send names is archived (agent_archived).
409 Conflict — duplicate resource, an in-progress
idempotent request, a draft or scheduled message
that started sending while it was being changed, or
a thread deleted for good while one of its messages
is being sent (duplicate_resource); or an agent
name more than one agent has (agent_name_conflict:
use the agent's id); or a status change on an
archived agent, since archiving cannot be undone
(agent_archived).
500 Internal server error.Path Parameters
idstringrequired
Thread id.
Query Parameters
permanentboolean
true deletes the thread for good instead of moving it to trash.
Sent again for a thread already in trash it changes nothing, so a retried request never destroys mail. With permanent=true it deletes the thread for good, from any folder: its messages' content, raw email and attachments are removed, and thread.deleted is emitted. Trash is also emptied automatically 30 days after a thread was moved there. A test key cannot trash or delete a thread holding live mail (403 live_mode_required). An app connected by sign-in may move a thread to trash but not delete it for good: with permanent=true it gets 403 connected_app_not_allowed.
Was this page helpful?