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

# Manage your platform's agents

> Create Agent identities from your server and request access to a connected business.

Your platform can create, read, update, suspend, resume, and deactivate its
Agent identities through the API. The Account that owns the platform credential
owns each Agent. An Agent needs a separate grant from a business before it can
act for that business.

Ionic must enable Agent management for your platform. Its Program must allow
delegated API access in your key's mode and include the requested Agent
permission in its permission ceiling.

## Prepare your platform

1. Have an owner or admin open **Agents** in the dashboard and claim your
   Account's handle prefix. This claim is permanent. A prefix of `acme` permits
   handles such as `acme-booking`.
2. Open your platform's credentials in the dashboard and select the **Agent
   management** preset for a new secret key. It contains `agents:read` and
   `agents:write`. Request only the permissions your integration needs.
3. Store the secret on your server. Send it as a bearer credential. Omit
   `Ionic-Account` and dashboard session cookies from Agent identity requests.

`agents:read` and `agents:write` are independent: write access does not include
read access. Ordinary Account keys and Agent runtime keys cannot use these
management operations.

> [!WARNING]
>
> Agent identity is shared by test and live. An authorized test key can update,
> suspend, resume, or deactivate the same Agent used in live mode. Grants and
> runtime credentials keep their existing mode boundaries.

## Create an Agent

Read the claimed prefix with `GET /v1/agents/handle_prefix`. If `prefix` is
`null`, claim it in the dashboard before creating an Agent. Creation without a
claimed prefix returns `409 AGENT_HANDLE_PREFIX_REQUIRED`.

```bash theme={null}
curl https://api.ionicfi.com/v1/agents \
  -H "Authorization: Bearer $IONIC_PLATFORM_SECRET_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: booking-agent-create-001" \
  -d '{"name":"Booking assistant","handle":"acme-booking","description":"Books visits","metadata":{"team":"front-desk"}}'
```

The `201` response is the Agent identity:

```json theme={null}
{
  "id": "agt_00000000000001",
  "object": "agent",
  "owner_account_id": "mer_00000000000001",
  "name": "Booking assistant",
  "handle": "@acme-booking",
  "description": "Books visits",
  "metadata": { "team": "front-desk" },
  "avatar_hue": null,
  "status": "active",
  "version": 1,
  "created_by": "sk_000000000000000000000001",
  "created_at": 1790294400,
  "updated_at": 1790294400,
  "last_active_at": null
}
```

Save `id` and `version`. `created_by` is the public credential record ID for an
API-created Agent: `sk_` followed by 24 letters or digits. A dashboard-created
Agent has a `user_` creator. These IDs contain no credential secret. Activity
attributes API changes to the credential, without assigning a human actor.

Agent runtime keys are issued, rotated, and revoked in the dashboard. Creating
an identity returns no runtime key.

## Read and change the identity

| Operation | Endpoint | Required permission |
| - | - | - |
| Create | `POST /v1/agents` | `agents:write` |
| List | `GET /v1/agents` | `agents:read` |
| Retrieve | `GET /v1/agents/{id}` | `agents:read` |
| Update | `POST /v1/agents/{id}` | `agents:write` |
| Suspend | `POST /v1/agents/{id}/suspend` | `agents:write` |
| Resume | `POST /v1/agents/{id}/resume` | `agents:write` |
| Deactivate | `POST /v1/agents/{id}/deactivate` | `agents:write` |
| Read handle prefix | `GET /v1/agents/handle_prefix` | `agents:read` |

The list returns `data`, `has_more`, and a `next_cursor` when another page
exists. Send that cursor as `starting_after`. `limit` defaults to 20 and accepts
1–100. The list includes your Account's Agents across both modes.

Updates require the current `expected_version` and at least one editable field:

```bash theme={null}
curl https://api.ionicfi.com/v1/agents/agt_00000000000001 \
  -H "Authorization: Bearer $IONIC_PLATFORM_SECRET_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: booking-agent-update-001" \
  -d '{"expected_version":1,"name":"Visit assistant","metadata":{"team":"reception"},"avatar_hue":null}'
```

Omitted fields stay unchanged. `metadata` replaces the entire map; send `{}` to
clear it. Set `avatar_hue` to an integer from 0 to 359, or to `null` to restore
the color derived from the handle. `description: null` clears the description.
The owner, handle, and creator are immutable.

Suspend, resume, and deactivate take `expected_version` and a nonblank `reason`:

```json theme={null}
{ "expected_version": 2, "reason": "Paused by the platform" }
```

Suspension applies the owner's restriction. Resume removes that restriction;
an Ionic system restriction can keep the returned status `suspended`.
Deactivation is permanent. A deactivated Agent cannot be edited or resumed.

A stale version returns `409 AGENT_VERSION_CONFLICT`. Retrieve the Agent,
review the intervening change, and submit a new operation with its current
version and a new retry key. Runtime activity and changes to `last_active_at`
do not advance the identity version.

Agents connected through MCP cannot be changed through this management API,
including after the MCP connection is disconnected. Those mutations return
`403 AGENT_MCP_MANAGED`. A `metadata.source` value does not change that rule.

## Retry a mutation

Every machine `POST` above requires one nonblank `Idempotency-Key`, at most
255 bytes, and a JSON body no larger than 64 KiB. A larger body returns
`413 REQUEST_TOO_LARGE`.

Keep the same key and identical body bytes when retrying an operation. Even
different whitespace counts as a different body and returns
`422 IDEMPOTENCY_BODY_MISMATCH`. Retry keys are scoped to the owning Account,
credential, operation, and target Agent across both modes. Another credential
cannot replay the result.

Ionic retains successful response snapshots for at least 24 hours. A retry
checks the current Account, credential, permissions, and Program before
returning the saved response. A revoked key or removed permission cannot replay
an earlier success. The saved response is returned before checking the Agent's
current version, so an unchanged retry does not repeat the mutation.

A snapshot describes the original result. For the Agent's current status,
retrieve it again. An earlier `active` response does not establish current
runtime access. After the retention window, retrieve the Agent before deciding
whether to submit another operation.

## Connect an Agent to a merchant

Keep the Agent owned by your platform. Use the connected merchant's Account ID
in an Agent grant request:

1. With a platform secret key that has `platform:act`, call
   `POST /v1/agent_grant_requests` with `agent_id`, the merchant's `account`, and
   the requested `permissions`. Omit `Ionic-Account` from this request.
2. The business must have an active Connection in the key's mode. Each
   permission must be grantable to Agents, allowed by that Connection, and
   within your Program's permission ceiling.
3. Send the returned `url` to the business owner. The owner approves or declines
   in the dashboard within seven days. An admin can view the request but cannot
   decide it.
4. Retrieve `GET /v1/agent_grant_requests/{id}` to read the decision. After
   approval, issue the Agent's platform key in the dashboard. The Agent uses
   that key with `Ionic-Account` set to the merchant's Account ID for supported
   runtime operations.

Platform secret keys include `platform:act`, so the same key can submit a grant
request when the current Connection and Program allow it. The Agent identity
scopes do not grant the business's consent. An approved grant authorizes only
its permissions in its mode. For example, an Agent key with `customers:read`
can call `GET /v1/customers/{id}`.

An approved request remains `approved` if the business later revokes its grant.
Read the nested `agent_grant.status` for the grant's current status. The
`agent_grant_request.updated` event reports approval, decline, or cancellation;
expiry and later grant revocation do not emit that request-update event.


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