# cancel_job

Source: https://modulify.ai/docs/api/chat/cancel-job

Stops a generation that is currently running on a site.

- Title: Cancel a running generation
- Scope: `chat:write`
- Access: Makes changes
- Endpoint: `POST /v1/cancel_job`

Work the agent has already written to the site is kept. Leave out `jobId` to cancel whichever generation is running in the chat, which is `main`, the chat every site comes with, unless you pass `chatId`. When none is, the call answers `404` with `There is no generation running in this chat!` when you passed a `chatId`, and with `There is no generation running for this site!` when you did not. Generations running in other chats of the site keep running. The response carries `chatId`, the chat the cancelled generation ran in, even when you passed only a `jobId`.

Stopping a generation parks that chat's message queue, so anything queued in it waits until `resume_queue` releases it. Set `clearSession` to also reset the agent session of that chat, so its next message starts a fresh conversation. On a site with several chats, what the agent already wrote is merged into the site the same way as at the end of a turn. See [Stop a run](https://modulify.ai/docs/build/site-chat#stop-a-run) and [Merging when a turn ends](https://modulify.ai/docs/build/multiple-chats#merging-when-a-turn-ends).

## Request

Call it with a `POST` to `https://api.modulify.ai/v1/cancel_job`, sending the inputs below as a JSON object. The token needs the `chat:write` scope.

It makes changes, so send an [Idempotency-Key](https://modulify.ai/docs/api/idempotency) header whenever you might retry it. A retry with the same key gets the first answer back instead of running again.

```bash
curl -X POST https://api.modulify.ai/v1/cancel_job \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"projectId":"PROJECT_ID"}'
```

Over MCP, the same method is the [cancel_job tool](https://modulify.ai/docs/mcp/chat/cancel-job).

## Inputs

| Input | Type | Required | Description |
| --- | --- | --- | --- |
| `projectId` | string | Yes | The site id. |
| `jobId` | string | No | The generation to cancel. Leave it out for the one running now. |
| `clearSession` | boolean | No | True to also reset the agent session of that chat, so its next message starts a fresh conversation. |
| `chatId` | string | No | The chat whose running generation to cancel when `jobId` is left out: `main` for the chat every site comes with, or the `chatKey` of another chat from `list_chats`. Defaults to `main`. |

## Response

Every call answers with the [JSON envelope](https://modulify.ai/docs/api/requests-and-responses#the-response) of `success`, `message`, `data`, `code` and `version`. `data` holds the result described above, and on a method that returns a total, `count` carries it. The [response headers](https://modulify.ai/docs/api/requests-and-responses#headers-on-every-method-call) carry the call's `X-Request-Id` and what is left of your per-minute budget in `X-RateLimit-Limit`, `X-RateLimit-Remaining` and `X-RateLimit-Reset`. [Errors](https://modulify.ai/docs/api/errors) explains every status code a call can answer with.