# For agents

> Your agent can sign up, top up, make a payment key and pay any x402 or MPP API with plain HTTP requests. Start from llms.txt.

Your agent can do all of this without you.

Sign up, top up, make a key, find an API, pay it. Every step is one HTTP request. Every page on this site has a Markdown twin. You keep the master key and set the limits.

## Give this to your agent

```
Read https://anyfare.agents.bakingbad.dev/llms.txt and follow it.
Ask me before you sign up, top up, or make a key.
Pay with a payment key, never the master key.
Keep spend under $5 a day and $0.05 a call.
```

Or, if your agent has its own wallet: it needs nothing from us. It pays our 402 in USDC on NEAR, Base or Solana, or over MPP on Tempo.

## What an agent reads

- [/llms.txt](https://anyfare.agents.bakingbad.dev/llms.txt): How it works and how to start. The first thing to read
- [Agent skill](https://anyfare.agents.bakingbad.dev/skills/anyfare-buyer/SKILL.md): /skills/anyfare-buyer/SKILL.md, step by step
- [/openapi.json, API host](https://api.anyfare.agents.bakingbad.dev/openapi.json) and [pay host](https://pay.anyfare.agents.bakingbad.dev/openapi.json): The two APIs, for code generators
- [Any page + .md](https://anyfare.agents.bakingbad.dev/agents.md): Or Accept: text/markdown. Same data, no HTML
- [llms-full.txt](https://anyfare.agents.bakingbad.dev/llms-full.txt): every endpoint, request and answer in one file

## Start in four requests

Each request runs as written. Keys and ids in the answers are placeholders: yours come from the answers.

### 1. Sign up

```sh
curl -X POST https://api.anyfare.agents.bakingbad.dev/v1/accounts
```

Answer: `{ "id": "<account id>", "masterKey": "afm_live_…", "freeCredits": "0.1", … }`

Save the master key where only your user can read it. A new account may get free Credits to try: "freeCredits" says how much.

### 2. Make a payment key with limits

```sh
curl -X POST https://api.anyfare.agents.bakingbad.dev/v1/keys \
  -H "Authorization: Bearer $ANYFARE_MASTER_KEY" \
  -H "Content-Type: application/json" \
  -d '{"label":"research","dailyBudget":"5","maxPrice":"0.05"}'
```

Answer: `{ "id": "<key id>", "dailyBudget": "5", "maxPrice": "0.05", …, "key": "af_live_…" }   shown once`

The agent calls with this key, never with the master key.

### 3. Top up with any token (optional)

```sh
curl -X POST https://api.anyfare.agents.bakingbad.dev/v1/topups \
  -H "Authorization: Bearer $ANYFARE_MASTER_KEY" \
  -H "Content-Type: application/json" \
  -d '{"network":"base","token":"USDC","amount":"20"}'
```

Answer: `{ "id": "<top-up id>", "status": "waiting", "depositAddress": "<deposit address>", "sendAtLeast": "19.9", "payBy": "…", … }`

Send at least "sendAtLeast" to "depositAddress" before "payBy", then read GET https://api.anyfare.agents.bakingbad.dev/v1/topups/<id> until "status" is "credited". The networks and tokens: GET https://api.anyfare.agents.bakingbad.dev/v1/topups/options.

### 4. Call any paid API

```sh
curl -i "https://pay.anyfare.agents.bakingbad.dev/pro-api.coinmarketcap.com/x402/v3/cryptocurrency/quotes/latest?symbol=BTC&convert=USD" \
  -H "Authorization: Bearer $ANYFARE_PAYMENT_KEY"
```

Answer: `200 OK  Anyfare-Receipt: id="pay_…", amount="0.01", currency="USD"`

Check first, free: GET https://pay.anyfare.agents.bakingbad.dev/_/check?url=<link>. Left on the key: GET https://pay.anyfare.agents.bakingbad.dev/_/key.

## The API

Two hosts. The pay host takes payment keys, or an x402 or MPP payment. The API host takes the master key. Public reads need no key.

### The pay host

| Method | Address | What it does | Who may call it | State |
|---|---|---|---|---|
| GET | `https://pay.anyfare.agents.bakingbad.dev/_/check?url=<link>` | Is a link payable, at what price, and what we quote. Free, and pays nothing | No key | Built |
| ANY | `https://pay.anyfare.agents.bakingbad.dev/<host>/<path>` | Pay any x402 or MPP API: put the pay host in front of its link, without `https://` | Payment key, x402 or MPP | Built |
| GET | `https://pay.anyfare.agents.bakingbad.dev/_/key` | The limits of a payment key and what is left of them, and the balance | Payment key | Built |

### Accounts and payment keys

| Method | Address | What it does | Who may call it | State |
|---|---|---|---|---|
| POST | `https://api.anyfare.agents.bakingbad.dev/v1/accounts` | Sign up. Returns the master key, once | No key | Built |
| GET | `https://api.anyfare.agents.bakingbad.dev/v1/account` | The account the master key belongs to | Master key | Built |
| POST | `https://api.anyfare.agents.bakingbad.dev/v1/account/master-key/rotate` | A new master key. The old one stops working at once | Master key | Built |
| POST | `https://api.anyfare.agents.bakingbad.dev/v1/keys` | Make a payment key with limits. The key is shown once | Master key | Built |
| GET | `https://api.anyfare.agents.bakingbad.dev/v1/keys` | Every payment key of the account, with what each spent | Master key | Built |
| PATCH | `https://api.anyfare.agents.bakingbad.dev/v1/keys/:id` | Change the limits of a payment key | Master key | Built |
| DELETE | `https://api.anyfare.agents.bakingbad.dev/v1/keys/:id` | Revoke a payment key. It stops working at once | Master key | Built |
| GET | `https://api.anyfare.agents.bakingbad.dev/v1/balance` | The Credits balance: available, and held for calls in flight | Master key | Built |
| GET | `https://api.anyfare.agents.bakingbad.dev/v1/payments` | Every call the account paid, newest first, in pages | Master key | Built |

### Top-ups

| Method | Address | What it does | Who may call it | State |
|---|---|---|---|---|
| GET | `https://api.anyfare.agents.bakingbad.dev/v1/topups/options` | The networks and tokens a top-up takes, and the least to send on each | No key | Built |
| POST | `https://api.anyfare.agents.bakingbad.dev/v1/topups` | Ask for a deposit address: send a token there and the balance grows | Master key | Built |
| GET | `https://api.anyfare.agents.bakingbad.dev/v1/topups/:id` | Where a top-up is | Master key | Built |

### Public reads

| Method | Address | What it does | Who may call it | State |
|---|---|---|---|---|
| GET | `https://api.anyfare.agents.bakingbad.dev/v1/catalog` | The endpoints Anyfare has routed, with prices and the ways to pay | No key | Built |
| GET | `https://api.anyfare.agents.bakingbad.dev/v1/calls` | Finished calls through Anyfare, newest first, in pages | No key | Built |
| SSE | `https://api.anyfare.agents.bakingbad.dev/v1/calls/stream` | Calls as they finish, as server-sent events. The same filters as the list | No key | Built |
| GET | `https://api.anyfare.agents.bakingbad.dev/v1/calls/:id` | The public receipt of one call | No key | Built |
| GET | `https://api.anyfare.agents.bakingbad.dev/v1/stats` | Platform numbers: calls, volume, buyers, services, how buyers paid, top-ups | No key | Built |
| GET | `https://api.anyfare.agents.bakingbad.dev/v1/stats/live` | Fresh numbers for today and the last 24 hours, and calls per minute | No key | Built |
| GET | `https://api.anyfare.agents.bakingbad.dev/v1/stats/top` | The top services, endpoints, ways to pay and top-up tokens of a period | No key | Built |
| GET | `https://api.anyfare.agents.bakingbad.dev/v1/services` | Services with at least one paid call: price, calls, buyers, volume | No key | Built |
| GET | `https://api.anyfare.agents.bakingbad.dev/v1/services/:host` | One service: its numbers, endpoints, days, ways to pay and top buyers | No key | Built |
| GET | `https://api.anyfare.agents.bakingbad.dev/v1/endpoints/stats` | The numbers of one endpoint: calls, buyers, volume, days, ways to pay | No key | Built |

## llms.txt

The guide an agent reads first. Plain text, with absolute links.

````text
# Anyfare

> Anyfare is a payment router for AI agents. Put the pay host in front of the link of any x402 or MPP API and pay it from the chain you are on, or with a payment key against a balance of Credits. You pay only for calls the API answered with 2xx.

## Hosts

- Pay: https://pay.anyfare.agents.bakingbad.dev. A routed call is https://pay.anyfare.agents.bakingbad.dev/<host>/<path>: the API's link without https://.
- API: https://api.anyfare.agents.bakingbad.dev. Sign up, payment keys, top-ups, and public reads of calls and numbers.
- Website: https://anyfare.agents.bakingbad.dev. Every page has a Markdown twin: add .md to its URL.
- Console: https://console.anyfare.agents.bakingbad.dev. For people.

## Rules

- Ask your user before you sign up, make a key, or top up.
- Keep the master key in a file only the user can read. Never print it, paste it into a chat, or put it in a URL.
- Pay with a payment key, never the master key. The master key works on the API host only.

## Steps

1. Check a link. Free, no key. "payable": true comes with the price and our quote.

```sh
curl "https://pay.anyfare.agents.bakingbad.dev/_/check?url=pro-api.coinmarketcap.com/x402/v3/cryptocurrency/quotes/latest"
```

2. Sign up. A new account may get free Credits: the answer says how much. "masterKey" is shown once: the command saves the answer to anyfare-account.json, which only the user can read.

```sh
umask 077
curl -s -X POST https://api.anyfare.agents.bakingbad.dev/v1/accounts > anyfare-account.json
```

3. Make a payment key with the limits your user sets. "key" is shown once: save it as ANYFARE_PAYMENT_KEY.

```sh
ANYFARE_MASTER_KEY=$(jq -r .masterKey anyfare-account.json)
curl -X POST https://api.anyfare.agents.bakingbad.dev/v1/keys \
  -H "Authorization: Bearer $ANYFARE_MASTER_KEY" \
  -H "Content-Type: application/json" \
  -d '{"label":"research","dailyBudget":"5","maxPrice":"0.05"}'
```

4. Call. Only a 2xx answer is charged, and it carries Anyfare-Receipt: id="pay_...". Read the receipt at https://api.anyfare.agents.bakingbad.dev/v1/calls/<id>.

```sh
curl -i "https://pay.anyfare.agents.bakingbad.dev/pro-api.coinmarketcap.com/x402/v3/cryptocurrency/quotes/latest?symbol=BTC&convert=USD" \
  -H "Authorization: Bearer $ANYFARE_PAYMENT_KEY"
```

5. No account, a wallet instead. A call with no payment answers 402 with every way to pay: the JSON body and the PAYMENT-REQUIRED header list x402 options (USDC on NEAR, Base or Solana), the WWW-Authenticate: Payment header holds the MPP charge (USDC.e on Tempo), and "credits" says how to use a key. Pay one option and send the same call again with PAYMENT-SIGNATURE (x402) or Authorization: Payment (MPP). Your payment settles only after a 2xx answer. Each option, step by step: https://anyfare.agents.bakingbad.dev/llms-full.txt, section "The 402".

6. Top up with any token NEAR Intents takes. GET https://api.anyfare.agents.bakingbad.dev/v1/topups/options lists networks, tokens and minimums. POST https://api.anyfare.agents.bakingbad.dev/v1/topups with network, token and amount (master key) answers a deposit address. Send there, then read GET https://api.anyfare.agents.bakingbad.dev/v1/topups/<id> until status is credited.

7. Before you spend: GET https://pay.anyfare.agents.bakingbad.dev/_/key with the payment key shows its limits and what is left. On 402 insufficient_balance ask your user to top up. On 402 key_budget_exceeded or key_price_limit ask before you raise a limit. On 429 wait Retry-After seconds. On 503 nothing was charged.

## Read more

- [Every endpoint, request and answer](https://anyfare.agents.bakingbad.dev/llms-full.txt): llms-full.txt, with the 402, the errors and the limits
- [Agent skill](https://anyfare.agents.bakingbad.dev/skills/anyfare-buyer/SKILL.md): the steps above as a skill to install
- [OpenAPI, API host](https://api.anyfare.agents.bakingbad.dev/openapi.json)
- [OpenAPI, pay host](https://pay.anyfare.agents.bakingbad.dev/openapi.json)
- [For agents](https://anyfare.agents.bakingbad.dev/agents): the same, with the API as a table. Twin: https://anyfare.agents.bakingbad.dev/agents.md
- [Services](https://anyfare.agents.bakingbad.dev/services.md): the services agents paid, and [calls](https://anyfare.agents.bakingbad.dev/calls.md), newest first
- [Check a link](https://anyfare.agents.bakingbad.dev/check.md?url=<link>): the check, with the numbers of the API behind it
- A call's receipt: https://anyfare.agents.bakingbad.dev/calls/<id>.md or https://api.anyfare.agents.bakingbad.dev/v1/calls/<id>
````
