# Cancel a job

> Stop a queued or running job and get a refund.

Source: https://developers.mnml.ai/docs/cancel

`POST https://api.mnml.ai/v2/jobs/{id}/cancel`

## Example request

**curl**

```bash
curl -X POST https://api.mnml.ai/v2/jobs/10482/cancel \
  -H "Authorization: Bearer $MNML_API_KEY"
```

**TypeScript**

```ts
const res = await fetch("https://api.mnml.ai/v2/jobs/10482/cancel", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.MNML_API_KEY}`,
  },
});

const data = await res.json();
```

**Python**

```python
import os, requests

res = requests.post(
    "https://api.mnml.ai/v2/jobs/10482/cancel",
    headers={"Authorization": f"Bearer {os.environ['MNML_API_KEY']}"},
)

data = res.json()
```

## Example response (200)

```json
{
  "success": true,
  "data": {
    "id": "10482",
    "outcome": "refunded",
    "refunded_usd": 0.2475,
    "credits_refunded": 25
  }
}
```

## Headers

- `Authorization` (string, required): `Bearer mk_live_…`: your API key. See [Authentication](https://developers.mnml.ai/docs/authentication).

## Path parameters

- `id` (string, required): The job id a create call answered with.

## Outcomes

| outcome | Meaning |
| --- | --- |
| refunded | Stopped before it started; `credits_refunded` are back now. |
| requested | Already running: asked to stop, and refunded if nothing is delivered. |
| too-late | It had already finished. Nothing changes. |
| already-settled | It had already failed or been cancelled. Nothing changes. |

## Response

On success (`200`): What the cancel did. The JSON is `{ "success": true, "data": … }`, and inside `data`:

- `id` (string, required): The job.
- `outcome` (string, required): What the cancel did: see the table above. Values: `refunded`, `requested`, `too-late`, `already-settled`.
- `refunded_usd` (number, required): What was refunded now, in US dollars; 0 when a refund waits on the job stopping.

**Response headers (4)**

- `X-Request-Id` (string): This request, for support and the console log.
- `RateLimit-Limit` (integer): Requests this key may make per minute.
- `RateLimit-Remaining` (integer): Requests left in the current minute.
- `RateLimit-Reset` (integer): Seconds until the current minute resets.

## Status codes

| Status | Meaning |
| --- | --- |
| 200 | What the cancel did. |
| 401 | The API key is missing, malformed, unknown or revoked. |
| 429 | A limit was reached: requests per minute, or a daily or concurrency limit. |
| Other | Any other error, in the same envelope. |

Every error answers `{ "success": false, "error": { "code", "message" } }`. What each code means, and what to do, is on [Errors](https://developers.mnml.ai/docs/errors).
