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

# Cancelling a Job

> Cancel a batch inference job by its job_id

<Warning>Using the API directly is not recommended for most users. Instead, we recommend using the [Python SDK](/python-sdk/setup).</Warning>

Cancel a batch inference job by its job\_id.

## Request Parameters

<ParamField path="job_id" type="string" required>
  The job\_id returned when you submitted the batch inference job
</ParamField>

## Headers

<ParamField header="Authorization" type="string" required>
  Your Sutro API key using Key authentication scheme.

  Format: `Key YOUR_API_KEY`

  Example: `Authorization: Key sk_live_abc123...`
</ParamField>

## Response

Returns the cancellation status of the job.

<ResponseField name="cancelled" type="boolean">
  True if the job was cancelled, False otherwise
</ResponseField>

<ResponseField name="message" type="string">
  Verbose message describing the job's cancellation status
</ResponseField>

<ResponseExample>
  ```json Job Successfully Cancelled theme={null}
  {
    "cancelled": true,
    "message": "Job batch_job_12345 has been successfully cancelled"
  }
  ```

  ```json Job Could Not Be Cancelled theme={null}
  {
    "cancelled": false,
    "message": "Job batch_job_12345 could not be cancelled because it has already completed"
  }
  ```

  ```json Job Not Found theme={null}
  {
    "cancelled": false,
    "message": "Job batch_job_12345 not found"
  }
  ```
</ResponseExample>

## Code Examples

<CodeGroup>
  ```python Python theme={null}
  import requests

  job_id = "batch_job_12345"

  response = requests.post(
      f'https://api.sutro.sh/job-cancel/{job_id}',
      headers={
          'Authorization': 'Key YOUR_SUTRO_API_KEY',
          'Content-Type': 'application/json'
      }
  )

  result = response.json()
  if result['cancelled']:
      print(f"Job {job_id} was successfully cancelled")
  else:
      print(f"Failed to cancel job: {result['message']}")
  ```

  ```javascript Node.js theme={null}
  const jobId = 'batch_job_12345';

  const response = await fetch(`https://api.sutro.sh/job-cancel/${jobId}`, {
    method: 'POST',
    headers: {
      'Authorization': 'Key YOUR_SUTRO_API_KEY',
      'Content-Type': 'application/json'
    }
  });

  const result = await response.json();
  if (result.cancelled) {
    console.log(`Job ${jobId} was successfully cancelled`);
  } else {
    console.log(`Failed to cancel job: ${result.message}`);
  }
  ```

  ```curl cURL theme={null}
  curl -X POST https://api.sutro.sh/job-cancel/batch_job_12345 \
    -H "Authorization: Key YOUR_SUTRO_API_KEY" \
    -H "Content-Type: application/json"
  ```
</CodeGroup>

## Notes

* Jobs can only be cancelled if they are in a cancellable state (e.g., pending, submitted, starting, or running)
* Jobs that have already completed, failed, or been previously cancelled cannot be cancelled
* The cancellation is asynchronous - the job may take a moment to fully stop after receiving the cancellation request
