> ## Documentation Index
> Fetch the complete documentation index at: https://docs.galtea.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Cancel Job

> Cancel a queued or in-flight async Galtea job.

> [!WARNING]
>
> You are reading the docs of Galtea 5.11. [Read this page in the latest version](https://docs.galtea.ai/sdk/api/job/cancel.md).

Cancel an async job that is still queued or currently being processed. This is useful when an inference batch was started with the wrong configuration, when a version's endpoint is misconfigured, or when you simply need to stop a long-running job early to free up capacity.

## Cancellation semantics

* A **queued or delayed** job is removed from the queue and will never run.
* An **in-flight** job receives a cooperative cancellation signal. The worker stops dispatching further work at its next checkpoint. Work already dispatched when the signal is observed is **not** rolled back.
* The [Run](https://docs.galtea.ai/v5.11/concepts/product/run.md) that carried the job moves to `CANCELLED`. Only a Run the platform opened carries a job, so a Run you opened with `POST /runs` is never reached this way; it still ends only when you close it.
* Repeated cancels are **idempotent**: calling `cancel()` on an already-cancelled job still returns `state='cancelled'` rather than raising an error.

## Usage

```python theme={"system"}
    response = galtea.jobs.cancel(job_id=job_id)
    print(f"Job {response.id} is now {response.state}")
```

**Check status before cancelling:**

```python theme={"system"}
    # Check whether the job is still running before deciding to cancel
    status = galtea.jobs.get_status(job_id=job_id)
    print(f"Job state: {status.state}  progress: {status.progress}")

    terminal_states = {"completed", "failed", "cancelled"}
    if status.state not in terminal_states:
        try:
            response = galtea.jobs.cancel(job_id=job_id)
            print(f"Cancelled job {response.id}")
        except JobAlreadyTerminalException:
            # The job reached a terminal state between the get_status call and cancel — safe to ignore
            print("Job completed before the cancel request arrived.")
    else:
        print(f"Job already in terminal state: {status.state}")
```

## Parameters

**job\_id** `string` *required*

The ID of the job to cancel. Returned as `jobId` in the response from [`evaluations.run()`](https://docs.galtea.ai/v5.11/sdk/api/evaluation/run).

## Returns

A `JobCancelResponse` object:

**id** `string`

The job ID.

**state** `string`

Always `"cancelled"` on a successful response, whether this was the first or a repeated cancel request.

## Errors

| Error | Cause |
| - | - |
| `EntityNotFoundException` | The job does not exist, or belongs to a different organization (404). Import it with `from galtea import EntityNotFoundException`. |
| `JobAlreadyTerminalException` | The job has already reached `completed` or `failed` state and cannot be cancelled (409). Import it with `from galtea import JobAlreadyTerminalException`. |

> [!NOTE]
>
> `JobAlreadyTerminalException` is only raised for jobs that finished (`completed` or `failed`). Jobs that were already cancelled return `state='cancelled'` with a 200 response — repeated cancels are safe to call without checking status first.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.