cURL
curl --request POST \
--url https://api.mage.space/v1/requests/{request_id}/cancel \
--header 'Authorization: Bearer <token>'import Mage from '@mage-space/sdk';
const mage = new Mage(); // reads MAGE_API_KEY
const request = await mage.requests.cancel('REQUEST_ID');
console.log(request.status); // cancelledfrom mage_space import Mage
mage = Mage() # reads MAGE_API_KEY
request = mage.requests.cancel("REQUEST_ID")
print(request["status"]) # cancelledconst options = {method: 'POST', headers: {Authorization: 'Bearer <token>'}};
fetch('https://api.mage.space/v1/requests/{request_id}/cancel', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));{
"request_id": "d7e6c0f3-6699-4f6c-bb45-2ad7fd9158ff",
"status": "cancelled",
"architecture": "flux2",
"model_id": "flux2-dev",
"created_at": "2026-09-17T14:52:48.000Z",
"updated_at": "2026-09-17T14:52:55.000Z",
"billing": {
"mode": "gems",
"gems_charged": 40
},
"result": null,
"error": null,
"status_url": "https://api.mage.space/v1/requests/d7e6c0f3-6699-4f6c-bb45-2ad7fd9158ff/status",
"cancel_url": "https://api.mage.space/v1/requests/d7e6c0f3-6699-4f6c-bb45-2ad7fd9158ff/cancel"
}{
"error": {
"code": "unauthorized",
"message": "The API key is invalid or has been revoked."
}
}{
"error": {
"code": "payment_required",
"message": "The Mage API and MCP server need a successful payment on this account first: buy any Gem pack or start a plan at https://www.mage.space/gems, then retry. Signup bonus Gems work in the Mage app only."
}
}{
"error": {
"code": "request_not_found",
"message": "No request with this id belongs to the account."
}
}{
"error": {
"code": "request_finished",
"message": "The request has already finished and cannot be cancelled."
}
}{
"error": {
"code": "internal_error",
"message": "Something went wrong on our side. Retry, and contact support if it persists."
}
}Endpoints
Cancel request
Stop a live Mage API request through its cancel URL. Gems are not refunded on cancellation.
POST
/
v1
/
requests
/
{request_id}
/
cancel
cURL
curl --request POST \
--url https://api.mage.space/v1/requests/{request_id}/cancel \
--header 'Authorization: Bearer <token>'import Mage from '@mage-space/sdk';
const mage = new Mage(); // reads MAGE_API_KEY
const request = await mage.requests.cancel('REQUEST_ID');
console.log(request.status); // cancelledfrom mage_space import Mage
mage = Mage() # reads MAGE_API_KEY
request = mage.requests.cancel("REQUEST_ID")
print(request["status"]) # cancelledconst options = {method: 'POST', headers: {Authorization: 'Bearer <token>'}};
fetch('https://api.mage.space/v1/requests/{request_id}/cancel', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));{
"request_id": "d7e6c0f3-6699-4f6c-bb45-2ad7fd9158ff",
"status": "cancelled",
"architecture": "flux2",
"model_id": "flux2-dev",
"created_at": "2026-09-17T14:52:48.000Z",
"updated_at": "2026-09-17T14:52:55.000Z",
"billing": {
"mode": "gems",
"gems_charged": 40
},
"result": null,
"error": null,
"status_url": "https://api.mage.space/v1/requests/d7e6c0f3-6699-4f6c-bb45-2ad7fd9158ff/status",
"cancel_url": "https://api.mage.space/v1/requests/d7e6c0f3-6699-4f6c-bb45-2ad7fd9158ff/cancel"
}{
"error": {
"code": "unauthorized",
"message": "The API key is invalid or has been revoked."
}
}{
"error": {
"code": "payment_required",
"message": "The Mage API and MCP server need a successful payment on this account first: buy any Gem pack or start a plan at https://www.mage.space/gems, then retry. Signup bonus Gems work in the Mage app only."
}
}{
"error": {
"code": "request_not_found",
"message": "No request with this id belongs to the account."
}
}{
"error": {
"code": "request_finished",
"message": "The request has already finished and cannot be cancelled."
}
}{
"error": {
"code": "internal_error",
"message": "Something went wrong on our side. Retry, and contact support if it persists."
}
}Stop a live request. The run is marked cancelled and the generation backend is asked to stop; the response is the request’s state afterwards. Gems are not returned on cancellation, as in the web app.
Cancelling a request that already finished is a
409 request_finished. Cancelling one that is already cancelled does nothing and returns its state.Authorizations
Create a key in API → API Keys: select Create API key, name it in the popup, then select Create key. Copy the one-time key and send it as Authorization: Bearer mage_sk_…. Keys are for server-side code only.
Response
The request's state after the cancellation.
Last modified on September 23, 2026

