# AIPAY — operating notes for an AI agent

You are reading the short version. The long ones are `llms.txt` (what this is and
what is enabled) and `llms-full.txt` (every doc in one file). If you only have one
request, read this file and then `https://api.aipay.im/v1`.

## What AIPAY is

A non-custodial, multi-chain crypto wallet and merchant payment gateway.
Payments move from a payer's wallet to a merchant's address; AIPAY never holds
keys or funds. There is no account and no signup for a payer.

Two surfaces, and mixing them up is the usual mistake:

| Surface | Transport | Use it for |
| --- | --- | --- |
| Merchant order API | HTTPS at `https://api.aipay.im/v1`, `Authorization: Bearer aipay_sk_…` | creating orders, reading receipts and status, signed webhooks, CSV export |
| Agent surface | local Node.js process (`agent/mcp-server.mjs`, `agent/cli.mjs`) | an agent paying with **its own** key under a local spending policy |

There is **no hosted agent endpoint and no npm package**; the runtime is at
<https://github.com/aipayim/aipay-agent>. The merchant API is not exposed through
the agent tools.

## How to do the common thing

```bash
# 1. merchant (returns the API key once — store it in a secret manager)
curl -s -X POST https://api.aipay.im/v1/merchants -H 'Content-Type: application/json' \
  -d '{"shopName":"My Shop","recipientAddress":"0xYourAddress","chainKey":"bsc"}'

# 2. order (checkoutUrl + reference; merchantOrderId makes it idempotent)
curl -s -X POST https://api.aipay.im/v1/orders \
  -H "Authorization: Bearer $AIPAY_API_KEY" -H 'Content-Type: application/json' \
  -d '{"amount":"12.50","asset":"USDT","merchantOrderId":"INV-1042"}'

# 3. poll (no key needed)
curl -s https://api.aipay.im/v1/orders/<reference>/status
```

Push beats polling: configure `webhookUrl` and verify
`X-AIPAY-Signature: sha256=<hex HMAC-SHA256(secret, "<timestamp>.<raw body>")>`,
rejecting timestamps older than five minutes. Events: `order.confirmed`,
`order.expired`, `order.cancelled`. Retries 1 m / 5 m / 30 m / 2 h / 6 h. One
recorded delivery can be re-sent on demand with
`POST /v1/orders/:reference/notifications/:deliveryId/replay` (merchant key, same
delivery id, fresh retry budget, written to the order timeline); there is still
no event stream and no bulk replay, so bulk recovery is pulling
`GET /v1/orders` or `GET /v1/orders/export.csv`.

## Rules that are not negotiable (and not our opinion)

- **Mainnet only.** There is no sandbox and no testnet behind `api.aipay.im`; a
  test order is a real order for a small amount. To rehearse without money, run
  the Worker yourself (`wrangler dev` with `RPC_OVERRIDES`, see
  `/docs/merchant-order-service.md` §11) or use the repository at
  <https://github.com/aipayim/aipay>.
- **We are not a PSP and never touch the money.** Consequently there are **no
  refunds, reversals, chargebacks or dispute handling** in the API: the merchant
  refunds from their own wallet. Do not promise a payer a refund through AIPAY.
- **Confirmed means "we re-read the transaction and it is deep enough"** — not
  "the goods shipped" and not "the payment is final forever". EVM orders are
  re-read once (30 min – 6 h later) and a vanished or shallow transaction is
  recorded as `confirmation_regressed` (event + `last_error`); the status never
  changes and no webhook fires. Reconcile on it, do not reverse on it.
- **One recipient per merchant, no on-chain memo.** Two pending orders with the
  same amount and recipient are ambiguous — use distinct amounts.
- **Native coins (ETH/BNB/POL/…) need `POST /confirm` with the tx hash**; only
  token transfers are discovered by the sweep.
- **An off-chain confirmation is the merchant's own receipt**, not chain
  evidence, and `channel` says which it is.
- **MSG / MSGChain is disabled.** Do not offer it.
- **Paid plans are not on sale.** `GET /v1` reports `billing.status: "free"` with
  no plans; there is no price list to quote.

## What you may not do

Do not invent endpoints, statuses or webhook fields; do not claim an order is
paid without a `confirmed` state from the API; do not treat a 202
(`insufficient_confirmations`) as success; do not mint spendable value from a
webhook without verifying its signature and timestamp; do not describe AIPAY as
custodial, as a licensed payment institution, or as covering fiat collection (the
off-chain layer only orchestrates *the merchant's own* channels).

## Where the rest is

- `llms.txt` — capabilities and fail-closed features
- `llms-full.txt` — all docs concatenated
- `agent.json` — machine-readable capability surface
- `openapi.json` — merchant HTTP API description
- `.well-known/mcp.json` — says out loud that our MCP runtime is local (stdio)
  and that there is **no hosted MCP endpoint**
- `/docs/provider-assessment-answers.md` — point-by-point answers to a third-party
  capability assessment, including the gaps above
