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

> Delete a terminal optimization run and its trials

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

## Overview

This endpoint deletes a terminal optimization and its trials. Only a terminal run; that is, one
whose status is `completed`, `failed`, or `cancelled` can be deleted. Anything else returns an
HTTP status code `409`.

The winner-promoted blueprint, if any, is a separate row and is left in place — deleting the run
that produced it does not remove it from the catalog.

<Note>
  Deleting an optimization run also deletes its completed trials. A blueprint promoted from one
  of those trials is a separate row and survives.
</Note>

A run that is still `pending` or `running` returns `409`. Cancel it first using the
[Cancel Optimization](/api-reference/agents/optimizations/cancel-optimization) endpoint.

## Request

<ParamField path="optimization_id" type="string" required>
  Optimization `opt_` ID.
</ParamField>

## Response

Returns `204 No Content` with an empty body on success. Check the status code rather than
parsing a response.

<RequestExample>
  ```bash cURL theme={"system"}
  curl -X DELETE "$ATAI_API_URL/agents/optimizations/opt_01jcb1m3t7v5xq8nr2h6kdzs4w" \
    -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.delete(
      f"{base_url}/agents/optimizations/opt_01jcb1m3t7v5xq8nr2h6kdzs4w",
      headers={"Authorization": f"Bearer {api_key}"},
  )

  if response.status_code == 204:
      print("Optimization deleted")
  elif response.status_code == 409:
      print("Optimization is not terminal — cancel it first")
  else:
      print(f"Error: {response.json()['errors']}")
  ```

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

  if (response.status === 204) {
    console.log('Optimization deleted');
  } else if (response.status === 409) {
    console.error('Optimization is not terminal — cancel it first');
  } else {
    const body = await response.json();
    console.error('Error:', body.errors);
  }
  ```
</RequestExample>

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

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

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


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