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

# API introduction

> Base URLs, formats, limits and retry rules of the Anafi API, and a list of all operations.

After you read this page, you can call each route of the Anafi API with the correct host, headers and value formats. You also know which calls are safe to repeat.

The public TypeScript SDK `@anafi-cc/anafi-sdk` calls these routes for you. It also builds the sealed payloads and checks the replies. Use the routes directly when you do not use the SDK, or when you want to know what the SDK sends. See [SDK overview](https://docs.ana.fi/sdk/overview.md).

## Base URLs

Each network has its own host. A host serves only its own network. A request about an account on another network gets an answer about the same address on the network of the host.

| Network token | Base URL | Chain id |
| - | - | - |
| `polygon` | `https://api.polygon.ana.fi` | `137` |
| `xlayer` | `https://api.xlayer.ana.fi` | `196` |
| `polygon-amoy` | `https://api.polygon-amoy.ana.fi` | `80002` |

The bank payout routes (tag "Bank payouts") are served only on `polygon-amoy`. On `polygon` and `xlayer` they answer `404`. All other routes are served on all three networks. See [Networks](https://docs.ana.fi/networks.md).

## Authentication

No API key is necessary today. No route reads a cookie or a header for authority.

Some routes need a proof from the owner instead:

| Proof | Routes |
| - | - |
| EIP-4361 sign-in, inside the sealed payload | `POST /api/wallets/{aa}/recover`, `POST /api/wallets/{aa}/notification_email/request_code` |
| EIP-4361 sign-in, in the JSON body | `POST /api/dsl/generate` |
| Owner signatures inside a Safe transaction | `POST /api/wallets/{aa}/safe/sponsor_exec` |
| Safe owner signature (ERC-1271 or `personal_sign`) | `POST /api/monerium/connect`, `POST /api/monerium/bank-details` |

All read routes answer anyone, about any account. Do not put private data in a route that you read for an account.

## Limits of today

> [!WARNING]
>
> Call the API from a server, from a script, or through your own same-origin proxy if your page is not on `https://app.ana.fi`. The Anafi API hosts answer CORS (`Access-Control-Allow-Origin`) only for `https://app.ana.fi` today. A browser page on another origin cannot call the API directly. Chain reads and owner-sent transactions do not go through the API, so this limit does not apply to them.

> [!WARNING]
>
> Do not plan an integration on another domain that uses `recover` or the notification-email code request. These two sign-in (EIP-4361) flows are accepted only when the sign-in message names the domain of the Anafi dapp, `app.ana.fi`. A sign-in for another domain is refused with `422`. An integration on another domain cannot complete these two flows today.

For the origin `https://app.ana.fi`, a CORS preflight allows the methods `GET` and `POST` and the request header `Content-Type`.

## Requests and responses

* Send a request body as JSON, with the header `Content-Type: application/json`. Without this header, the route answers `415`.
* A success body is JSON, except `GET /api/dsl/docs`, which is `text/markdown; charset=utf-8`.
* An error body is plain text or JSON, as each route defines. See [Errors](https://docs.ana.fi/api-reference/errors.md).
* `POST /api/dsl/generate` and the bank payout routes accept a body of at most 2 MB. All other `POST` routes accept at most 512 KiB. A larger body gets `413`.
* An unknown path answers `404` with an empty body.

## Value formats

| Value | Format | Example |
| - | - | - |
| Address | `0x` and 40 hex digits. Requests accept any letter case. Responses use lowercase. | `"0xf9836de53d455019ed985896fce8af80be66b7f9"` |
| Path segment `aa` | The account address, in the same format. A value that is not an address gets `400`. | `/api/wallets/0xf983.../activity` |
| Hash, 32 bytes | `0x` and 64 lowercase hex digits | `"0x2a4c...1f3a"` |
| Bytes in JSON fields | `0x` and an even count of hex digits | `"0x6a761202..."` |
| Bytes in a sealed envelope | A JSON array of integers from 0 to 255, not hex | `[131, 22, 7]` |
| Token amount | A decimal string of the smallest unit of the token. Parse it as a big integer. | `"200000"` |
| Wei amount | A decimal string | `"350378308000000000"` |
| Time | An integer of Unix seconds | `1796305002` |
| Token | The symbol with its exact letter case | `"USDC.e"` |
| Network | The network token | `"polygon-amoy"` |

Small counts are JSON integers: `bps`, `floorUsdCents`, `dslVersion`, `maxSendBatchRecipients`, `seconds`.

## Field names and enum values

* Most JSON bodies use camelCase keys, for example `accountKind`, `txHash`, `amountRaw`.
* These bodies use snake\_case keys: the sealed envelope (`kem_pk`, `ct`), the sealed reply (`nonce`, `ct`), the staging refusal (`error`, `sealed_error`), the `build` object of `GET /health`, and all plaintext payloads inside a seal. See [Sealed requests](https://docs.ana.fi/api-reference/sealed-requests.md).
* Enum values are lowercase snake\_case strings, for example `safe_module`, `in_progress`, `every_source_consulted`. One exception: the token symbols keep their letter case.
* A union is an object with a tag key. The tag key is `kind` for the outcomes of provisioning, receipts and email codes. It is `state` for the off-ramp handler and policy.
* `null` and absent are different. A field that the reference marks as nullable is always present. A field that the reference marks as optional can be absent, for example `gasCharge` on an activity row and `gas` in the fee terms.

## Retries and idempotency

| Operation | Safe to repeat | Rule |
| - | - | - |
| All `GET` routes | Yes | They change nothing. |
| `POST /api/wallets/provision` | Yes | A repeat returns the same Safe with `kind: "already_deployed"` and sends nothing. |
| `POST /api/wallets/{aa}/safe/sponsor_exec` | No | The Safe nonce stops a second execution. After `502` or `504`, read the Safe nonce before you send again. After `504`, do not send the same bytes again. |
| `POST /api/wallets/{aa}/dsl/commit/stage` | Yes | Each call stages a new attestation. Use the newest one. Too many staged documents give `429`. |
| `POST /api/wallets/{aa}/recover` | No | Each sign-in nonce works once. Sign a new message for each attempt. |
| `POST /api/wallets/{aa}/notification_email/request_code` | No | Each sign-in nonce works once. A new code request can give `retry_after`. |
| `POST /api/wallets/{aa}/notification_email/verify_code` | Limited | A code token allows 3 wrong codes. |
| `POST /api/pay/receipt_email` | Yes | At most one confirmed mail for each transaction hash. A repeat gives `already_requested`. |
| `POST /api/dsl/generate` | Yes | The same sign-in works until its session ends. A call can count against the daily limits. |

A sign-in for `recover` and the email code request is valid for 5 minutes after its `Issued At`. An `Issued At` more than 60 seconds in the future is refused.

## Caching

Only `GET /api/dsl/docs` sets a cache header: `Cache-Control: public, max-age=3600`. Do not cache the other responses. Fee terms, sponsorship and activity can change at each block.

## All operations

| Method and path | Tag | What it does | SDK function |
| - | - | - | - |
| `GET /health` | Status | Shows that the Anafi API answers. | none |
| `GET /api/dsl/docs` | Rule language | Returns the rule language reference as Markdown. | none |
| `POST /api/dsl/generate` | Rule language | Writes a rule document from a description. | `generateDsl` |
| `GET /api/accounts/discover` | Accounts | Lists the accounts that an owner address can use. | `client.discoverAccounts` |
| `POST /api/wallets/provision` | Accounts | Deploys the 1-of-1 Safe of an owner. Anafi pays. | `client.provisionPredictedSafe` |
| `POST /api/wallets/{aa}/safe/sponsor_exec` | Safe relay | Submits an owner-signed Safe transaction. Anafi pays. | Safe write methods, when Anafi pays |
| `POST /api/wallets/{aa}/dsl/commit/stage` | Rules | Stages a sealed rule document and returns the attestation. | `client.stageDsl` |
| `POST /api/wallets/{aa}/recover` | Confidential channel | Returns the rule document and the account state, sealed and signed. | `client.recover` |
| `POST /api/wallets/{aa}/notification_email/request_code` | Notification email | Sends a verification code to an email address. | `client.requestNotificationEmailCode` |
| `POST /api/wallets/{aa}/notification_email/verify_code` | Notification email | Checks the code and verifies the email address. | `client.verifyNotificationEmailCode` |
| `GET /api/wallets/{aa}/activity` | Activity | Lists the payments of an account. | `client.getActivity`, `getActivity` |
| `GET /api/wallets/{aa}/sponsorship` | Fees | Tells whether fees are on and whether the account has a sponsor. | `client.fetchWalletSponsorship` |
| `GET /api/fees` | Fees | Returns the fee terms and gas bounds of the network. | `client.fetchFeeTerms` |
| `POST /api/pay/receipt_email` | Payments | Mails a receipt for one payment of the pay page. | `client.sendPayReceiptEmail` |
| `POST /api/monerium/connect` | Bank payouts | Starts the Monerium connection of a Safe. `polygon-amoy` only. | none |
| `GET /api/monerium/status/{aa}` | Bank payouts | Returns the Monerium connection and the off-ramp setup of a Safe. `polygon-amoy` only. | none |
| `POST /api/monerium/bank-details` | Bank payouts | Returns the IBAN and BIC of a Safe to an owner. `polygon-amoy` only. | none |
| `GET /api/wallets/{aa}/off-ramp/orders` | Bank payouts | Lists the bank payout orders of a Safe. `polygon-amoy` only. | none |

## Related pages

> [card] [Errors](https://docs.ana.fi/api-reference/errors.md)
>
> Error bodies, status codes and SDK error classes.

> [card] [Sealed requests](https://docs.ana.fi/api-reference/sealed-requests.md)
>
> How to seal a request to the engine and open its reply.

> [card] [Flows](https://docs.ana.fi/flows/overview.md)
>
> The order of API calls, signatures and transactions.

> [card] [SDK errors](https://docs.ana.fi/sdk/errors.md)
>
> The error classes of the SDK.


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