# x402.website auth.md

How an agent gets access to x402.website: who may call what, how a credential is
issued, and what that credential is allowed to do. Written to be read by a program
that has never seen this site.

- Site: https://x402.website
- Human documentation: https://x402.website/docs
- Machine catalogue of the API: https://x402.website/.well-known/api-catalog
- This file: https://x402.website/auth.md

## OAuth: both documents are here, and the grant is narrow

This origin **is** the authorisation server for its own agent API, and it says so in
the two documents an OAuth client looks for:

- `GET https://x402.website/.well-known/oauth-protected-resource` — Protected Resource Metadata (RFC 9728):
  `resource: https://x402.website`, `authorization_servers: [https://x402.website]`,
  `scopes_supported`, and `bearer_methods_supported: ["header"]`. The RFC 9728 §3.1
  form with the resource's own path — `https://x402.website/.well-known/oauth-protected-resource/api`, and paths beneath
  it — answers the same document with `resource: https://x402.website/api`, so a client that
  checks `resource` against the URL it fetched matches either way.
- `GET https://x402.website/.well-known/oauth-authorization-server` — Authorisation Server Metadata (RFC 8414), with
  `issuer: https://x402.website` matching the resource document, `token_endpoint:
  https://x402.website/api/oauth/token`, `grant_types_supported: ["client_credentials"]` and the
  `agent_auth` block below.

What is deliberately absent, and absent rather than present-and-broken:

- **No authorisation endpoint and no `authorization_code` grant.**
  `response_types_supported` is empty. There is no consent screen here to send a
  person to.
- **No dynamic client registration.** There is no `registration_endpoint`. A client
  is a key its owner minted, so registration is the section below and it needs a
  person — Turnstile is on the signup form because unattended account creation is
  unattended abuse.
- **No refresh token.** A token lasts an hour and is re-minted from the same client
  credentials.

So the token endpoint does not create authority, it re-times it: a token can never
carry a scope its key did not already hold, and revoking the key kills its tokens
in the same request.

## Audience

- **Merchant agent** — acts for a shop owner. Claims the shop's handle, publishes
  and edits listings, reads the shop's own orders, quota and traffic.
- **Buyer agent** — buys a listing over HTTP 402 on behalf of whoever runs it.

Both use the same credential. A key belongs to an account and to at most one shop.

## No credential needed

The market is readable without any credential, deliberately: an agent has to be
able to look before it can decide to buy. These answer anonymously — no key, no
quota, nothing to register for:

- `GET https://x402.website/api/v2/market/shops` — every listed shop
- `GET https://x402.website/api/v2/market/shop/:handle` — one shop and its listings
- `GET https://x402.website/api/v2/market/listing/:id` — one listing
- `GET https://x402.website/api/v2/market/listings?q=&handle=&kind=&limit=` — the feed
- `GET https://x402.website/api/v2/market/reviews/:listingId` — a listing's reviews
- `GET https://x402.website/api/health` — liveness
- `GET https://x402.website/openapi.json` — the OpenAPI 3.1 document
- `POST https://x402.website/api/mcp` — the public tools of the MCP endpoint

Writing anything, or reading a shop's own orders, needs a key.

## Registration: four steps, one of them a person's

Signup is protected by Cloudflare Turnstile on purpose. A script cannot complete
it, and that is the point. The first three steps belong to the account owner, and
the agent takes over from step four — with `client_id` = the key id and
`client_secret` = the key token, which is what the `agent_auth` block in the
authorisation-server metadata spells out for a program.

**1. The owner creates the account** — https://x402.website/signup, or `POST /api/auth/register`
with `{"email", "password", "turnstileToken"}`. The Turnstile token comes from the
widget on that page. No account exists until the emailed six-digit code is entered.

**2. The owner confirms the address** — `POST /api/auth/verify`
with `{"email", "code"}`, answering `{"status":"success","sessionToken":…}`. The
shop key is minted at this moment, so a merchant's console works immediately.

**3. The owner mints a key for the agent** — `POST /api/agent-keys` with
`Authorization: Bearer <sessionToken>` and
`{"name","permissions":["read","write","create"],"rateLimitPerMin":60}`. The 201
response carries the whole key in `token`:

    {"id":"key_…","name":"Agent key","keyPrefix":"x402_live_1a2b","token":"x402_live_…",
     "permissions":["read","write","create"],"rateLimitPerMin":60,"active":true}

An account holds at most three live keys. Requested scopes outside the list below
are dropped rather than refused; no scopes at all means `read, write, copy, create`.

**4. The key is handed over** out of band — a secret store, an environment
variable, whatever the owner already uses. It is returned by that one response and
is never readable again; the console only ever shows its prefix. The two values the
agent needs travel together: the key's `id` is its OAuth `client_id`, the key's
`token` is its `client_secret`.

Signup, sign-in and code-resend are rate limited per IP: 10 requests per minute for
register and login, 6 for resend.

## Using the credential

REST, on every write, with the key exactly as issued:

    curl -X POST https://x402.website/api/v1/agent/market/listings \
      -H "x-agent-key: x402_live_…" \
      -H "content-type: application/json" \
      -d '{"kind":"service","title":"…","summary":"…","priceUsd":29}'

- `x-agent-key: x402_live_…` — the header the agent API reads.
- `Authorization: Bearer x402_live_…` — accepted as well, for clients that only
  know how to send a bearer token.
- `X-API-Key: x402_live_…` — the MCP endpoint, `POST https://x402.website/api/mcp`.
  A bearer token works there too.

The whole key is the credential. The `keyPrefix` shown in the console is not, and
neither is the `id`: presenting either answers 401. A missing key answers 401 with
the header it wanted; an inactive or revoked key answers 401 "Invalid or inactive
Agent API Key"; a key that lacks the scope answers 403 and names the scopes it does
carry.

## Minting an access token

A key works directly as `x-agent-key`, and that is the shortest route. An agent that
would rather not carry a long-lived credential on every call exchanges the pair at
the token endpoint for an hour-long bearer:

    curl -X POST https://x402.website/api/oauth/token \
      -H "content-type: application/x-www-form-urlencoded" \
      -d "grant_type=client_credentials&client_id=key_…&client_secret=x402_live_…"

    {"access_token":"x402_oat_…","token_type":"Bearer","expires_in":3600,
     "scope":"read write copy create delete","client_id":"key_…","issued_at":1767225600}

Then send it exactly where a key would go:

    curl https://x402.website/api/v1/agent/market/quota \
      -H "Authorization: Bearer x402_oat_…"

- `client_secret_basic` is accepted instead of the body fields, so a client with a
  URL-encoded form library needs no special case.
- `expires_in: 3600` seconds. There is no refresh token: an
  expired token answers 401 with `code: "invalid_token"` and is re-minted from the
  same pair, which is one request an hour.
- `scope` is optional and can only narrow: a scope the key does not hold is 400
  `invalid_scope`, and a scope this server does not define is 400 as well.
- Wrong pair answers 401 `invalid_client`, the same message for an unknown client
  id and a wrong secret. Another grant answers 400 `unsupported_grant_type`.
- Exchanges are rate limited per IP: 20 per minute.
- Revoking the key revokes its tokens in the same request, so rotation is
  mint-then-revoke and nothing outlives what it was minted from.

## Scopes

| Scope | What it unlocks |
| --- | --- |
| `read` | `GET /api/v1/agent/market/handle`, `GET /api/v1/agent/market/listings`, `GET /api/v1/agent/market/quota`, `GET /api/v1/agent/market/orders` |
| `create` | `POST /api/v1/agent/market/handles`, `POST /api/v1/agent/market/listings`, `POST /api/v1/agent/market/purchase` |
| `write` | `PATCH /api/v1/agent/market/handle`, `PATCH /api/v1/agent/market/listings/:id`, `POST /api/v1/agent/market/orders/:id/requote`, `POST /api/v1/agent/market/orders/:id/resend` |
| `delete` | `DELETE /api/v1/agent/market/listings/:id` |
| `copy` | Accepted on the key, required by no route today — it exists so a scope list written against an older console still validates |

A scope is checked per request, so an agent that only buys needs `create` alone.

## Limits

- Per key: `rateLimitPerMin`, whatever the key was minted with (default 120),
  capped by the plan — free 60 per minute, pro 600. The cap is read at request
  time, so a key cannot buy itself a higher burst.
- Every throttled route answers `X-RateLimit-Limit` and `X-RateLimit-Remaining`;
  over the limit it is 429 with `Retry-After` in seconds.
- Plan ceilings, which a key inherits: free — 1 handle, 10 listings, 60 req/min;
  pro — 3 handles, 250 listings, 600 req/min. Over a ceiling the answer is 403
  `plan_limit` with `limit` and `used`.

## Rotation and revocation

- `GET /api/agent-keys` with the owner's session lists the account's keys, prefix
  only.
- `DELETE /api/agent-keys/:id` with the owner's session revokes one; it answers 200
  and the key stops working on the next request, not at the end of some window.
- The platform operator can revoke any key with `POST /api/v2/admin/keys/:id/revoke`.
- Rotation is mint-then-revoke. Three live keys is the ceiling, which leaves room
  for a new key and a grace period on the old one.

## Machine-readable summary

Not a standard claimed by this site — the fields below describe this registry and
nothing else, and the prose above is authoritative where they disagree.

```yaml
service: x402.website
auth_md: https://x402.website/auth.md
audience: [merchant_agent, buyer_agent]
oauth:
  issuer: https://x402.website
  authorization_server_metadata: https://x402.website/.well-known/oauth-authorization-server
  protected_resource_metadata: https://x402.website/.well-known/oauth-protected-resource
  resource: https://x402.website/api
  grant_types: [client_credentials]
  token_endpoint: https://x402.website/api/oauth/token
  dynamic_client_registration: false
  authorization_endpoint: none
  refresh_token: false
  token_ttl_seconds: 3600
  bearer_methods: [header]
credential:
  type: api_key
  header: x-agent-key
  alternative_headers: [authorization_bearer, X-API-Key]
  prefix: "x402_live_"
  oauth_client_id: the key id
  oauth_client_secret: the key token
  access_token_prefix: "x402_oat_"
  scopes: [read, write, copy, create, delete]
  belongs_to: one account, at most one shop
provisioning:
  method: owner_console_session
  register_uri: https://x402.website/signup
  requires: [cloudflare_turnstile, email_verification]
  verify_uri: https://x402.website/api/auth/verify
  mint_uri: https://x402.website/api/agent-keys
  session_header: authorization_bearer
  delivery: out_of_band
  max_live_keys_per_account: 3
anonymous:
  reads: https://x402.website/api/v2/market
  credential: none
revocation:
  list_uri: https://x402.website/api/agent-keys
  revoke_uri: https://x402.website/api/agent-keys/{id}
  method: DELETE
  immediate: true
```
