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

# Agent quickstart

> Give an AI agent its own key, let it create a checkout session, and complete a test payment.

Give your AI agent a payment tool. In test mode, the agent creates a checkout
session with its own key, a buyer pays on the page Ionic hosts, and the agent
confirms the payment. No real money moves.

You need an Ionic account in **Sandbox**, signed in as an owner. Admins can
create agents, but an owner issues the agent's key.

## 1. Create the agent

1. On the **Agents** page, select **Create agent**. The first time, claim your
   account's agent handle prefix, such as `juniper`. Every agent handle starts
   with it. The prefix is permanent.
2. Enter a name, such as `Checkout assistant`, a handle, such as
   `juniper-checkout`, and a description.
3. Choose **Create checkout sessions** and **View checkout sessions**.
4. Choose when the key expires, then select **Create agent**.
5. Copy the key. It starts with `ak_v1_test_` and is shown once. Set it as
   `AGENT_KEY` where the agent runs.

The agent can act in test mode as soon as it is created. To allow it in live
mode later, switch modes and open its **Access** tab.

## 2. Let the agent create a checkout session

The agent sends its key as a Bearer token. Writes need an `Idempotency-Key`:
use a unique value per checkout and reuse it if the request is retried.

```bash theme={null}
curl https://api.ionicfi.com/v1/checkout/sessions \
  -H "Authorization: Bearer $AGENT_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: order_1001-checkout" \
  -d '{
    "mode": "payment",
    "line_items": [
      {
        "name": "Pro onboarding",
        "amount": 15000,
        "currency": "usd",
        "quantity": 1
      }
    ],
    "customer_email": "buyer@example.com",
    "client_reference_id": "order_1001",
    "success_url": "https://example.com/success?session_id={CHECKOUT_SESSION_ID}",
    "cancel_url": "https://example.com/cart"
  }'
```

`amount` is in cents: `15000` is \$150.00. The response is an open session with
a hosted checkout `url` for the buyer:

```json theme={null}
{
  "id": "cs_000000000000000000001001",
  "object": "checkout_session",
  "mode": "payment",
  "status": "open",
  "payment_status": "unpaid",
  "amount_total": 15000,
  "currency": "USD",
  "url": "https://checkout.ionicfi.com/c/hcs_..."
}
```

An agent hands the `url` to the buyer, for example in a chat reply or an
email.

## 3. Pay as the buyer

Open the `url` and pay with the test card `4111 1111 1111 1111`, any future
expiration date, and any 3-digit CVC. See [test cards](https://docs.ionicfi.com/guides/test-cards.md) for
other outcomes.

## 4. Let the agent confirm the payment

```bash theme={null}
curl https://api.ionicfi.com/v1/checkout/sessions/cs_000000000000000000001001 \
  -H "Authorization: Bearer $AGENT_KEY"
```

The payment is complete when `status` is `complete` and `payment_status` is
`paid`. To fulfill an order, rely on a verified `checkout.session.completed`
[webhook](https://docs.ionicfi.com/webhooks/quickstart.md) on your server.

## 5. Review the agent's activity

Open the agent on the **Agents** page. **Activity** lists the session it
created and the session it retrieved. A call Ionic refuses appears there too,
with the reason.

| Code | Meaning |
| - | - |
| `403` `AGENT_ACCESS_DENIED` | The agent has no current access for this call: it is not allowed in the key's mode, lacks the permission, or is suspended. |
| `403` `AGENT_OPERATION_UNAVAILABLE` | The endpoint is not one agents can call. |
| `400` `IDEMPOTENCY_KEY_REQUIRED` | A write was sent without an `Idempotency-Key`. |

## What's next

> [card] [Give your agent more to do](https://docs.ionicfi.com/api-reference/agent-permissions.md)
>
> Add invoices, payment links, customers, or products and prices.

> [card] [Connect an MCP client](https://docs.ionicfi.com/guides/connect-ai-assistants.md)
>
> Use Claude, ChatGPT, Codex, or another compatible client instead of a
> key.

> [card] [Build for the businesses you serve](https://docs.ionicfi.com/connect/agents.md)
>
> Run your platform's agent for each business that approves it.


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