> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.rasen.ai/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.rasen.ai/_mcp/server.

# Archive and restore an agent

> Archive an agent to stop its calls and start its 14-day deletion window, then restore it with unarchive before the deadline.

## Summary

This guide archives an agent, finds it in the archived list and restores it before it is deleted.
It covers `archiveAgent`, the archive window and `unarchiveAgent`. It does not cover phone number
assignment after a restore; see [Route phone calls](/guides/phone-numbers).

## Facts

| Item                  | Value                                                                                                          |
| --------------------- | -------------------------------------------------------------------------------------------------------------- |
| Operations            | `archiveAgent`, `listAgents`, `unarchiveAgent`                                                                 |
| Paths                 | `POST /agents/{agent_id}/archive`, `GET /agents?state=archived`, `POST /agents/{agent_id}/unarchive`           |
| Capability            | `agents.write` for archive and unarchive; `config.read` for `listAgents`                                       |
| Required headers      | `Authorization` on every request; `Idempotency-Key` on archive and unarchive                                   |
| Request body          | None                                                                                                           |
| Answer                | `200` with the `Agent`                                                                                         |
| Archive window        | 14 days: `archive_deadline` is `archived_at` plus exactly 14 days                                              |
| Archived agent fields | `state: archived`, `archived_at` and `archive_deadline` set; both are `null` for an agent that is not archived |
| `ETag`                | Archive and unarchive do not change the agent's `ETag`                                                         |
| Environment           | `RASEN_API_BASE` (the base URL, ending in `/v1`), `RASEN_API_KEY`, `AGENT_ID`                                  |
| Python                | 3.10 or later, with the `httpx` package                                                                        |
| TypeScript            | Node.js 22 or later (built-in `fetch`)                                                                         |

## Steps

Set `AGENT_ID` to the `id` of the agent, from `listAgents` or from the answer of `createAgent`.

### 1. Archive the agent

**`curl`**

```bash curl
curl -sS -X POST "$RASEN_API_BASE/agents/$AGENT_ID/archive" \
  -H "Authorization: Bearer $RASEN_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)"
```

**`Python`**

```python Python
import os
import uuid

import httpx

BASE = os.environ["RASEN_API_BASE"]
KEY = os.environ["RASEN_API_KEY"]
AGENT_ID = os.environ["AGENT_ID"]

response = httpx.post(
    f"{BASE}/agents/{AGENT_ID}/archive",
    headers={"Authorization": f"Bearer {KEY}", "Idempotency-Key": str(uuid.uuid4())},
)
response.raise_for_status()
agent = response.json()
print(agent["state"], agent["archived_at"], agent["archive_deadline"])
```

**`TypeScript`**

```typescript TypeScript
const { RASEN_API_BASE, RASEN_API_KEY, AGENT_ID } = process.env;

const response = await fetch(`${RASEN_API_BASE}/agents/${AGENT_ID}/archive`, {
  method: "POST",
  headers: {
    Authorization: `Bearer ${RASEN_API_KEY}`,
    "Idempotency-Key": crypto.randomUUID(),
  },
});
if (!response.ok) throw new Error(`HTTP ${response.status}`);
const agent = await response.json();
console.log(agent.state, agent.archived_at, agent.archive_deadline);
```

The answer is the agent with `state: archived`, `archived_at` and `archive_deadline`. From this
moment:

* The agent takes no new calls.
* Its phone numbers are released. They keep their history and you can assign them to another
  agent.
* Draft edits, publication and rollback answer `409 agent_archived`.
* `listAgents` leaves the agent out unless you ask for `state=archived`. `getAgent` still reads it
  by ID.

### 2. Find archived agents

**`curl`**

```bash curl
curl -sS "$RASEN_API_BASE/agents?state=archived" \
  -H "Authorization: Bearer $RASEN_API_KEY"
```

**`Python`**

```python Python
import os

import httpx

BASE = os.environ["RASEN_API_BASE"]
KEY = os.environ["RASEN_API_KEY"]

response = httpx.get(
    f"{BASE}/agents",
    params={"state": "archived"},
    headers={"Authorization": f"Bearer {KEY}"},
)
response.raise_for_status()
for agent in response.json()["items"]:
    print(agent["id"], agent["name"], agent["archive_deadline"])
```

**`TypeScript`**

```typescript TypeScript
const { RASEN_API_BASE, RASEN_API_KEY } = process.env;

const response = await fetch(`${RASEN_API_BASE}/agents?state=archived`, {
  headers: { Authorization: `Bearer ${RASEN_API_KEY}` },
});
if (!response.ok) throw new Error(`HTTP ${response.status}`);
const page = await response.json();
for (const agent of page.items) {
  console.log(agent.id, agent.name, agent.archive_deadline);
}
```

Each item shows its `archive_deadline`. From that time, the agent and its configuration are
deleted for good. Call evidence is kept, hidden. After the deletion, the agent reads as
`404 not_found`.

### 3. Restore the agent

**`curl`**

```bash curl
curl -sS -X POST "$RASEN_API_BASE/agents/$AGENT_ID/unarchive" \
  -H "Authorization: Bearer $RASEN_API_KEY" \
  -H "Idempotency-Key: $(uuidgen)"
```

**`Python`**

```python Python
import os
import uuid

import httpx

BASE = os.environ["RASEN_API_BASE"]
KEY = os.environ["RASEN_API_KEY"]
AGENT_ID = os.environ["AGENT_ID"]

response = httpx.post(
    f"{BASE}/agents/{AGENT_ID}/unarchive",
    headers={"Authorization": f"Bearer {KEY}", "Idempotency-Key": str(uuid.uuid4())},
)
response.raise_for_status()
agent = response.json()
print(agent["state"], agent["archived_at"], agent["archive_deadline"])
```

**`TypeScript`**

```typescript TypeScript
const { RASEN_API_BASE, RASEN_API_KEY, AGENT_ID } = process.env;

const response = await fetch(`${RASEN_API_BASE}/agents/${AGENT_ID}/unarchive`, {
  method: "POST",
  headers: {
    Authorization: `Bearer ${RASEN_API_KEY}`,
    "Idempotency-Key": crypto.randomUUID(),
  },
});
if (!response.ok) throw new Error(`HTTP ${response.status}`);
const agent = await response.json();
console.log(agent.state, agent.archived_at, agent.archive_deadline);
```

The agent returns to its state before the archive: `draft`, `live` or `paused`. A `live` agent
takes calls again at once. `archived_at` and `archive_deadline` are `null` again. The released phone
numbers are not assigned again: assign them with the phone number operations.

## Rules

* MUST let running work end before you archive. While a call, a campaign or another job of the
  agent runs, archive answers `409 archive_blocked`.
* MUST send a new `Idempotency-Key` after `archive_blocked`, because the first attempt had no
  effect.
* MUST unarchive before the deletion starts. Unarchive works until then, also after
  `archive_deadline` while a running call, campaign or legal hold delays the deletion.
* MUST NOT expect archive to keep the agent's phone numbers. Assign them again after a restore.
* Any key or member of the workspace can unarchive an agent, whoever archived it.

## Verify

```bash
curl -sS "$RASEN_API_BASE/agents/$AGENT_ID" \
  -H "Authorization: Bearer $RASEN_API_KEY"
```

Expected output after step 3: the agent with its earlier `state` and no archive dates.

```json
{"id": "agent_01j00000000000000000000000", "state": "live", "archived_at": null, "archive_deadline": null}
```

## Errors

| Code                                                   | Cause                                                                                     | Fix                                                                              |
| ------------------------------------------------------ | ----------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- |
| `archive_blocked` (`details.reason: active_calls`)     | A call of the agent is live.                                                              | Wait for the call to end, then archive with a new `Idempotency-Key`.             |
| `archive_blocked` (`details.reason: active_campaigns`) | A campaign of the agent is planned, admitted, dialing, paused or stalled.                 | Cancel the campaign or let it finish, then archive with a new `Idempotency-Key`. |
| `archive_blocked` (`details.reason: active_jobs`)      | Other work of the agent is running.                                                       | Wait for the work to end, then archive with a new `Idempotency-Key`.             |
| `archive_blocked` (`details.reason: account_calls`)    | An inbound number of the agent is on a carrier account that has a live call.              | Wait for that call to end, then archive with a new `Idempotency-Key`.            |
| `agent_archived`                                       | The agent is already archived, or you edited, published or rolled back an archived agent. | Read the agent. Unarchive it first if you need to change it.                     |
| `conflict` (`details.reason: not_archived`)            | You sent unarchive for an agent that is not archived.                                     | Nothing to restore. Read the agent for its `state`.                              |
| `agent_deleting`                                       | The permanent deletion of the agent has started.                                          | The agent cannot be restored. Create a new agent.                                |
| `not_found`                                            | The agent does not exist, or its deletion has finished.                                   | Check `AGENT_ID`. A deleted agent cannot be restored.                            |

`details.reason` of `archive_blocked` is an open vocabulary: treat an unknown value like the ones
above and retry after the work ends.

## Related

* [Build and publish an agent](/guides/agents)
* [Route phone calls](/guides/phone-numbers)
* [Idempotency and replay](/concepts/idempotency)
* [Errors](/concepts/errors)