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

> ## Agent Instructions
> Start with /introduction/getting-started. Use the Direct Query API (POST /query) with the Newton Fusion model (text, image, and video reasoning) or the Newton Omega encoder (time-series embeddings). ATAI_API_ENDPOINT must include the version path: /v0.5 for most APIs, /v0.6 for the Fine-Tuning Service. Pages whose descriptions are marked (Archived) document the legacy Lens runtime — do not use them for new projects.

# Cancel Agent

> Cancel a running or paused agent run

<Callout icon="clock" color="#3064E3" iconType="solid">
  Requires [version 1.1.9](/release-notes/1.1.x#v1-1-9) or later of the Archetype platform.
</Callout>

## Overview

This endpoint cancels an agent run and returns the updated agent.

You can only cancel agents whose status is either `running` or `paused`. If the agent has
already reached one of the terminal states (`completed`, `failed`, or `canceled`), this returns
HTTP status code `409`.

<Info>
  Once an agent has been canceled, it cannot be resumed or restarted. If you want to temporarily
  stop an agent, pause it using the [Pause Agent](/api-reference/agents/pause-agent) endpoint.
</Info>

<Note>
  You must cancel agents which are running or paused before deleting them.
</Note>

## Request

<ParamField path="agent_id" type="string" required>
  TypeID-encoded agent identifier (starting with the prefix `agt_`).
</ParamField>

## Response

Returns the canceled agent.

<ResponseField name="id" type="string" required>
  TypeID-encoded agent identifier of the canceled agent.
</ResponseField>

<ResponseField name="name" type="string" required>
  Name of the agent (a run's name is its bundle's name).
</ResponseField>

<ResponseField name="org_id" type="string" required>
  Organization identifier the agent belongs to.
</ResponseField>

<ResponseField name="bundle_id" type="string" required>
  The bundle this agent was run from (provenance).
</ResponseField>

<ResponseField name="blueprint" type="string" required>
  Human-readable pinned blueprint reference (its key), e.g. `osm`.
</ResponseField>

<ResponseField name="blueprint_id" type="string" required>
  Immutable blueprint ID the bundle pinned.
</ResponseField>

<ResponseField name="status" type="string" required>
  Agent lifecycle status; `canceled` after a successful cancel.
</ResponseField>

<ResponseField name="created_at" type="string" required>
  Creation timestamp (date-time).
</ResponseField>

<ResponseField name="connectors" type="object">
  The I/O binding this run was started with; `null` when none is recorded.
</ResponseField>

<ResponseField name="job_id" type="string">
  External executor's job ID for the current run (a JOS `job_` ID). Present once the run has been dispatched.
</ResponseField>

<ResponseField name="started_at" type="string">
  When the run started; `null` before then.
</ResponseField>

<ResponseField name="completed_at" type="string">
  When the run finished; `null` while unfinished.
</ResponseField>

<ResponseField name="error" type="string">
  Failure detail; `null` unless the run failed.
</ResponseField>

<RequestExample>
  ```bash cURL theme={"system"}
  curl -X POST "$ATAI_API_URL/agents/instances/agt_01jc9q8v5nm3ry7t2bkz4dhs6f/cancel" \
    -H "Authorization: Bearer $ATAI_API_KEY"
  ```

  ```python Python theme={"system"}
  import os
  import requests

  base_url = os.environ["ATAI_API_URL"]
  api_key = os.environ["ATAI_API_KEY"]

  response = requests.post(
      f"{base_url}/agents/instances/agt_01jc9q8v5nm3ry7t2bkz4dhs6f/cancel",
      headers={"Authorization": f"Bearer {api_key}"},
  )

  if response.status_code == 200:
      agent = response.json()
      print(f"Agent {agent['id']} is now {agent['status']}")
  else:
      print(f"Error: {response.json()['errors']}")
  ```

  ```javascript JavaScript theme={"system"}
  const response = await fetch(
    `${process.env.ATAI_API_URL}/agents/instances/agt_01jc9q8v5nm3ry7t2bkz4dhs6f/cancel`,
    {
      method: 'POST',
      headers: {
        'Authorization': `Bearer ${process.env.ATAI_API_KEY}`
      }
    }
  );

  const body = await response.json();

  if (response.ok) {
    console.log(`Agent ${body.id} is now ${body.status}`);
  } else {
    console.error('Error:', body.errors);
  }
  ```
</RequestExample>

<ResponseExample>
  ```json 200 - Agent canceled theme={"system"}
  {
    "id": "agt_01jc9q8v5nm3ry7t2bkz4dhs6f",
    "name": "Pump A monitor",
    "org_id": "org_01jc8m5r2vq9xt4bn7h3kdzs6w",
    "bundle_id": "bnd_01jc9pd42kzq7v8n3h5m6rtx0w",
    "blueprint": "osm",
    "blueprint_id": "blp_01jc9n7k3xf8mbq2v5t0ary6de",
    "connectors": {
      "source": [
        {"type": "file", "id": "file_abc123", "format": "csv"}
      ],
      "sink": null
    },
    "status": "canceled",
    "job_id": "job_01jc9q9k4t8v2mnr5xh7bdzy3s",
    "created_at": "2026-08-11T15:10:00Z",
    "started_at": "2026-08-11T15:10:04Z",
    "completed_at": "2026-08-11T15:14:02Z",
    "error": null
  }
  ```

  ```json 404 - Agent not found theme={"system"}
  {
    "errors": [
      {
        "code": "<error_code>",
        "message": "Agent not found.",
        "suggestion": null,
        "error_uid": "err-xxxxxxxx"
      }
    ]
  }
  ```

  ```json 409 - Agent already terminal theme={"system"}
  {
    "errors": [
      {
        "code": "<error_code>",
        "message": "Agent already terminal.",
        "suggestion": null,
        "error_uid": "err-xxxxxxxx"
      }
    ]
  }
  ```
</ResponseExample>
