import { createClient } from "@mailsai/sdk";
const client = createClient(); // reads MAILS_API_KEY
const result = await client.messages.cancel(
"msg_01JZX8K3M9Q4P7VN2YB6RTDC0E",
);
console.log(result);from mailsai import create_client
client = create_client() # reads MAILS_API_KEY
result = client.cancel_message(
"msg_01JZX8K3M9Q4P7VN2YB6RTDC0E",
)
print(result)curl -X POST 'https://api.mails.ai/v1/messages/msg_01JZX8K3M9Q4P7VN2YB6RTDC0E/cancel' \
-H "Authorization: Bearer $MAILS_API_KEY"mails emails cancel msg_01JABC{
"name": "mails_emails_cancel",
"arguments": {
"message_id": "msg_01JZX8K3M9Q4P7VN2YB6RTDC0E"
}
}{
"id": "msg_01JZX8K3M9Q4P7VN2YB6RTDC0E",
"status": "canceled",
"canceled_at": "2026-10-04T12:00:00.000Z"
}200 The canceled message.
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.Cancel a scheduled message
Cancels a send that is still scheduled, so it is never sent.
import { createClient } from "@mailsai/sdk";
const client = createClient(); // reads MAILS_API_KEY
const result = await client.messages.cancel(
"msg_01JZX8K3M9Q4P7VN2YB6RTDC0E",
);
console.log(result);from mailsai import create_client
client = create_client() # reads MAILS_API_KEY
result = client.cancel_message(
"msg_01JZX8K3M9Q4P7VN2YB6RTDC0E",
)
print(result)curl -X POST 'https://api.mails.ai/v1/messages/msg_01JZX8K3M9Q4P7VN2YB6RTDC0E/cancel' \
-H "Authorization: Bearer $MAILS_API_KEY"mails emails cancel msg_01JABC{
"name": "mails_emails_cancel",
"arguments": {
"message_id": "msg_01JZX8K3M9Q4P7VN2YB6RTDC0E"
}
}{
"id": "msg_01JZX8K3M9Q4P7VN2YB6RTDC0E",
"status": "canceled",
"canceled_at": "2026-10-04T12:00:00.000Z"
}200 The canceled message.
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
Sent message id with status scheduled.
Once the send starts going out it can no longer be canceled: the cancel changes nothing and answers 409 duplicate_resource, also when the send started while the cancel was running. A test key cannot cancel a send a live key scheduled (403 live_mode_required).
Response
idstring
Id of the canceled message (msg_…): the id in the path.
statusstring
Always canceled: the message will not be sent. Only a scheduled message can be canceled.
canceled_atstring
When the send was canceled: the time of this request, also kept as the message's canceled_at.
Was this page helpful?