> ## 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.

# Delete Agent

> Delete a terminal 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 deletes an agent (bundle run) by its `agt_` id.

Only terminal runs can be deleted. A run that is still `running` or `paused` returns `409` — cancel it first with `POST /agents/instances/{agent_id}/cancel`.

## Request

<ParamField path="agent_id" type="string" required>
  Agent `agt_` id.
</ParamField>

## Response

Returns `204 No Content` with an empty body on success.

<RequestExample>
  ```bash cURL theme={"system"}
  curl -X DELETE "$ATAI_API_URL/agents/instances/agt_01jc9q8v5nm3ry7t2bkz4dhs6f" \
    -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"]
  headers = {"Authorization": f"Bearer {api_key}"}
  agent_url = f"{base_url}/agents/instances/agt_01jc9q8v5nm3ry7t2bkz4dhs6f"

  response = requests.delete(agent_url, headers=headers)

  if response.status_code == 204:
      print("Agent deleted")
  elif response.status_code == 409:
      # Not terminal yet — cancel, then delete.
      requests.post(f"{agent_url}/cancel", headers=headers)
      requests.delete(agent_url, headers=headers)
  else:
      print(f"Error: {response.json()['errors']}")
  ```

  ```javascript JavaScript theme={"system"}
  const agentUrl = `${process.env.ATAI_API_URL}/agents/instances/agt_01jc9q8v5nm3ry7t2bkz4dhs6f`;
  const headers = { 'Authorization': `Bearer ${process.env.ATAI_API_KEY}` };

  const response = await fetch(agentUrl, { method: 'DELETE', headers });

  if (response.status === 204) {
    console.log('Agent deleted');
  } else if (response.status === 409) {
    // Not terminal yet — cancel, then delete.
    await fetch(`${agentUrl}/cancel`, { method: 'POST', headers });
    await fetch(agentUrl, { method: 'DELETE', headers });
  } else {
    const body = await response.json();
    console.error('Error:', body.errors);
  }
  ```
</RequestExample>

<ResponseExample>
  ```json 204 - Agent deleted theme={"system"}
  ```

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

  ```json 409 - Agent is not in a terminal state theme={"system"}
  {
    "errors": [
      {
        "code": "<error_code>",
        "message": "Agent is not in a terminal state (cancel it first).",
        "suggestion": null,
        "error_uid": "err-xxxxxxxx"
      }
    ]
  }
  ```
</ResponseExample>

## Important Notes

<Note>
  * Terminal statuses are `completed`, `failed`, and `canceled`. A `running` or `paused` agent must be canceled before it can be deleted.
  * Success returns `204` with no body — check the status code rather than parsing a response.
</Note>
