# Delete a saved agent.

`DELETE /o/{org}/agents/{agent}`

The agent starts no new session and is no longer listed or readable. Sessions already started from it run to the end. Only the creator can delete, or an org admin once the creator has left the org (with `If-Match` optional, even for an agent the admin cannot see). `If-Match` is optional for an API key, as on an edit. Deleting an agent made from a template disconnects every account connected to it. A Google account and an MCP server with a revoke endpoint are revoked at the vendor first, unless another of your live agents or your own account holds the same Google account. A connection whose revoke did not go through stays stored, still answered `200`, until a later `DELETE` of the agent by its id (a name reaches only a live agent) or Rush's operator sweep revokes it; no run of the agent can use it meanwhile. A template that agents are still made from is `409 TEMPLATE_IN_USE`, with their count in `agents`, and an agent that automations run on is `409 AGENT_IN_USE`, with their count in `automations`.

## Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `org` | path | string | yes | The org's slug or id. A caller with no role in the org gets `404`. |
| `agent` | path | string | yes | The saved agent's id, or its exact name (a plain agent or one made from a template). Two agents of that name are `422 INVALID_BODY`; send the id. `available` and `community` are paths beside this one, so no agent may be named either. An archived agent, and an orphaned agent an org admin cannot see, are reached by id only. |
| `if-match` | header | string | no | The `ETag` of the revision you read; another revision is `412 STALE_ETAG`. |

## Example request

```bash
curl -X DELETE "https://api.phoenix.so/o/$RUSH_ORG/agents/$AGENT" \
  -H "Authorization: Bearer $RUSH_TOKEN"
```

```typescript
const org = process.env.RUSH_ORG;
const agent = process.env.AGENT;

const res = await fetch(`https://api.phoenix.so/o/${org}/agents/${agent}`, {
  method: "DELETE",
  headers: {
    Authorization: `Bearer ${process.env.RUSH_TOKEN}`,
  },
});

console.log(res.status, await res.json());
```

```python
import os

import requests

org = os.environ["RUSH_ORG"]
agent = os.environ["AGENT"]

res = requests.delete(
    f"https://api.phoenix.so/o/{org}/agents/{agent}",
    headers={"Authorization": f"Bearer {os.environ['RUSH_TOKEN']}"},
)

print(res.status_code, res.json())
```

## Responses

### 200

The agent is deleted.

- `id` (string, required)
- `deleted` (boolean, required, one of `true`)

### 401

No bearer, an unknown, revoked or expired one, or an API key on a route keys cannot call.

### 403

A visible agent belongs to another creator (`FORBIDDEN`).

### 404

No such agent visible to you, or one already deleted (`NOT_FOUND`).

### 409

Agents are still made from this template (`TEMPLATE_IN_USE`), or automations run on this agent (`AGENT_IN_USE`); move or delete them first.

### 412

A concurrent edit won (`STALE_ETAG`); read the agent and delete it again.

### 428

A signed-in caller sent no `If-Match` (`IF_MATCH_REQUIRED`).

### 429

The account is over its request budget, 1,800 a minute shared by the person's API keys and console on every API host (`RATE_LIMITED`). The error names the limit. Wait `Retry-After` seconds.

## Example response (200)

```json
{
  "id": "6244972a-14cc-4592-a0e3-c7a0ab45b07b",
  "deleted": true
}
```
