# Alice Hub agent quickstart

Alice Hub sells small, read-only web checks (security headers, TLS, privacy, SEO, dependencies, agent-readiness, and a few data snapshots) to software agents, one HTTP call at a time.
You pay each call in USDC on Base with the x402 protocol. You need no account, no API key and no human.
Sign-ups are open and people can buy a first set of services on the site, by card, priced in EUR; the rest is not open yet. Pay-per-call for agents is open.

## 1. Discover (free)
```sh
curl -s https://api.alicehub.app/.well-known/agent-card.json  # A2A agent card (JSON)
curl -s https://api.alicehub.app/.well-known/api-catalog      # RFC 9727 linkset: points to openapi.json, auth.md, this guide, /health
curl -s https://api.alicehub.app/openapi.json                 # OpenAPI 3.1 description of every route
curl -s https://alicehub.app/llms.txt                         # plain-text map for language models
curl -s https://api.alicehub.app/health                       # {"ok": true, ..., "showcase": {...}}: the state of sign-ups and sales today
```
Every response from alicehub.app also carries an HTTP `Link` header pointing to `api-catalog`, `service-desc` and `describedby` (llms.txt).

The card's first skill is `pay-per-call` (USDC on Base, no account). Its two other skills, marketplace browsing and buying, need a credential created from an existing account. The paid routes and their prices are not written here, because they change: read the full list, with the live price of each route, from `/x402/catalog`.

## 2. Read the price list (free)
```sh
curl -s https://api.alicehub.app/x402/catalog
```
- `modules[]` lists each paid route with its `route`, `methods`, `price_usdc`, `params`, `description`, `output_example` and `output_schema`.
- `wire` says how to send the payment: `{"version": 1, "request_header": "X-PAYMENT", ...}`. It carries `also_accepts` (`{"version": 2, "request_header": "PAYMENT-SIGNATURE"}`) only while a version 2 payment header is read; without it, only `X-PAYMENT` pays.
- Always read the price from the catalogue or from the 402 answer, never from this page.

## 3. Get a free sample
Add `?preview=1` to any paid route. No payment is taken, and the sample has the shape of the paid answer.
```sh
curl -s 'https://api.alicehub.app/x402/headers?preview=1'
# {"preview": true, "note": "Free sample, no payment taken. ...", "route": "/x402/headers", "price_usdc": "...", ...}
```

## 4. Make the unpaid call: the payment requirement
```sh
curl -si 'https://api.alicehub.app/x402/headers?url=https://example.com'
```
You get `HTTP 402`. No work has been done and nothing has been charged. The same requirement arrives in two forms:
- **Body (x402 v1):** `{"x402Version": 1, "error": "X-PAYMENT header is required", "accepts": [{"scheme": "exact", "network": "base", "maxAmountRequired": "<atomic units>", "asset": "<USDC on Base>", "payTo": "...", ...}], "price_usdc": "...", "how_to_pay": "..."}`
- **Header (x402 v2):** `PAYMENT-REQUIRED: <base64 JSON>`. It decodes to `{"x402Version": 2, "accepts": [{"scheme": "exact", "network": "eip155:8453", "amount": "<atomic units>", ...}]}`.

A v1 client reads the body and answers with `X-PAYMENT`. A v2 client reads the `PAYMENT-REQUIRED` header and answers with `PAYMENT-SIGNATURE` only while the menu's `wire.also_accepts` names it; otherwise it answers with `X-PAYMENT` too. Both forms state the same amount. `network: "base"` and `eip155:8453` are the same chain.

## 5. Pay and get the answer
1. Sign the authorization named in `accepts[0]`: an EIP-3009 `transferWithAuthorization` for the stated amount of USDC on Base, sent to `payTo`.
2. Base64-encode the x402 payload and resend the **exact same request** with the header:
   - v1: `X-PAYMENT: <payload>`
   - v2: `PAYMENT-SIGNATURE: <payload>`, only while `wire.also_accepts` in the menu names it
3. A successful call returns `200` with the JSON answer. The receipt comes in `X-PAYMENT-RESPONSE`, which is exposed to browsers through `access-control-expose-headers`.

What is never charged (observed tonight):
- `?preview=1` on any route.
- An invalid input: `400 {"error": "bad_input", ...}` comes back before any payment step. Example: `?url=http://example.com` gives « target must be an https:// URL ».
- A call without payment: `402`, no work done.
- `HEAD` on a paid route: it answers `402` and takes no payment.
- The catalogue, every discovery file, `/health` and the MCP tools.

## 6. MCP tools
```sh
curl -s https://api.alicehub.app/mcp -H 'content-type: application/json' \
  -H 'accept: application/json, text/event-stream' \
  -d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18","capabilities":{},"clientInfo":{"name":"my-agent","version":"0"}}}'
curl -s https://api.alicehub.app/mcp -H 'content-type: application/json' \
  -d '{"jsonrpc":"2.0","id":2,"method":"tools/list"}'
```
`tools/list` is the live list. The free tools search the public service catalogue (`catalog_search`), read the service health (`service_status`), browse the agent marketplace listings (`marketplace_listings`) and read the pay-per-call menu (`paid_menu`). Each other tool matches one paid route: it returns that route's payment requirement and the exact HTTP request to pay and retry. The payment itself always goes through the `/x402/*` route.

## 7. Errors and limits
| Status | Meaning | What to do |
|---|---|---|
| 200 | The answer is built and paid for | Keep `X-PAYMENT-RESPONSE` |
| 400 | Wrong input (`bad_input`), nothing charged | Fix the input |
| 402 | Payment required, or the proof was rejected | Sign a new authorization with a new nonce |
| 409 | The same authorization is already in flight | Wait, then resend the same header |
| 429 | Rate limited per payer and route | Wait for `retry-after` |
| 503 | Nothing was settled (also returned if the payment rail is off) | Retry later |

The `url` routes accept public `https://` addresses only. `/x402/deps` takes a public GitHub repository URL.

## 8. Sponsored agents (marketplace)
A person who already has an account can give an agent a scoped credential (`a2a_…`) to browse and buy on the marketplace (the scopes it holds are in `GET /a2a/marketplace/whoami`) (`https://api.alicehub.app/a2a/marketplace`, priced in CDT). Sign-ups for people are open, so a new sponsor can create an account first. Without a credential, the marketplace answers `401 invalid_agent_credential`. Details: https://api.alicehub.app/auth.md

---
Questions: support@alicehub.app
