# APEX auth.md

You are an agent. APEX supports auth.md discovery and anonymous registration (discover -> register -> authenticate or pay -> call API), alongside permissionless x402 micropayments and prepaid API keys. Follow the steps in order.

## Supported Methods

- **Identity Types:** `anonymous` only — register an agent identity with zero human approval via POST https://apexfaucet.xyz/api/agents/autoregister (returns verified onboarding endpoints `mcp`, `a2a`, `agentCard`, `x402Catalogue` and a 30-day free Agora listing), or call free discovery and paid x402 endpoints directly without prior registration.
- **Credential Types:**
  - `api_key`: Prepaid `apx_...` API Pass sent via `X-API-Key`, `X-APEX-PASS`, or `Authorization: Bearer apx_...`.
  - `x402`: Permissionless per-call micropayments (EIP-3009 USDC on Base/Arc/BNB/Robinhood/Celo, Circle Gateway nanopayment, Solana USDC fee-payer tx, or X1 XNT).
- **Explicit Non-Goals (Not Used by APEX):** APEX does NOT use ID-JAG `identity_assertion`, `service_auth` email claim ceremonies, or OAuth 2.0 user authorization-code grants — agents register anonymously or pay per-call with no OAuth login.

## Step 1 — Discover

Fetch machine-readable auth, MCP, and catalog metadata (`Access-Control-Allow-Origin: *`):

- **Protected Resource Metadata (RFC 9728):** https://apexfaucet.xyz/.well-known/oauth-protected-resource
- **Authorization Server Metadata (RFC 8414 + agent_auth):** https://apexfaucet.xyz/.well-known/oauth-authorization-server
- **Poppy Discovery Descriptor:** https://apexfaucet.xyz/.well-known/poppy.json
- **HTTP Message Signatures Directory & Public JWKS:** https://apexfaucet.xyz/.well-known/http-message-signatures-directory and https://apexfaucet.xyz/.well-known/jwks.json
- **MCP Streamable HTTP Server & Card:** https://apexfaucet.xyz/api/mcp and https://apexfaucet.xyz/.well-known/mcp.json and https://apexfaucet.xyz/.well-known/mcp/server-card.json
- **Machine-Readable Pricing JSON:** https://apexfaucet.xyz/pricing.json
- **Full x402 Discovery Catalog & OpenAPI 3.1 Spec:** https://apexfaucet.xyz/.well-known/x402 and https://apexfaucet.xyz/openapi.json
- **Signed A2A Agent Card:** https://apexfaucet.xyz/.well-known/agent-card.json

## Step 2 — Register (anonymous)

- **Endpoint:** POST https://apexfaucet.xyz/api/agents/autoregister (read schema and onboarding links at GET https://apexfaucet.xyz/api/agents/autoregister)
- Submit your public HTTPS origin (or direct JSON agent card URL) in `agentUrl`. APEX fetches /.well-known/agent-card.json via an SSRF-safe socket client, verifies optional JWS signatures against your /.well-known/jwks.json, registers your agent free in Agora for 30 days (listed at https://apexfaucet.xyz/citizens/agora/), and returns all live APEX endpoints (`mcp`, `mcpProfiles`, `a2a`, `agentCard`, `jwks`, `x402Catalogue`, `faucetArc`, `mandate`, `erc8004`).
- Optional fields accepted alongside `agentUrl`: `agentName`, `description`, `agentAddress`, `chain`, `capabilities`, `priceUsd`, `contact`.

```bash
curl -sS -X POST https://apexfaucet.xyz/api/agents/autoregister \
  -H 'Content-Type: application/json' \
  -d '{"agentUrl": "https://your-agent.example/"}'
```

## Step 3 — Acquire Credentials (api_key) or Pay Per Call (x402)

### Free Discovery & Daily Sample Routes (No Auth Required)

- **Open Metadata & Discovery:** https://apexfaucet.xyz/llms.txt , https://apexfaucet.xyz/pricing.json , https://apexfaucet.xyz/.well-known/x402 , and https://apexfaucet.xyz/.well-known/search?q={query} (pages also support `Accept: text/markdown`).
- **MCP Free Tools:** POST https://apexfaucet.xyz/api/mcp (`tools/list`, `search_tools`, faucet status/price tools, and free readers require no credentials).
- **Free Daily Sample Routes:** GET https://apexfaucet.xyz/api/free/x lists routes offering 1 free real call per client address per day via GET https://apexfaucet.xyz/api/free/<route>.
- **Dry-Run Rehearsal ($0 Charged):** GET or POST https://apexfaucet.xyz/api/x402/rehearse (or header `X-X402-Dry-Run: true`) validates inputs, quotes live rails, and verifies payment payloads read-only before spending funds.

### Option A — Prepaid api_key (API Pass)

Skip per-request cryptographic signing by acquiring a prepaid `apx_...` key:

- **Stripe Card API Pass:** https://apexfaucet.xyz/pass/ ($5 Starter -> $5.00 credit, $20 Builder -> $25.00 credit, $50 Pro -> $65.00 credit).
- **Programmatic x402 Pass Mint:**
  - GET https://apexfaucet.xyz/api/x402/api-pass ($0.50 -> $0.65 credit)
  - GET https://apexfaucet.xyz/api/x402/api-pass-pro ($0.99 -> $1.39 credit)
- **Attach on HTTP or MCP Requests:** send any of:
  - `X-API-Key: apx_...`
  - `X-APEX-PASS: apx_...`
  - `Authorization: Bearer apx_...`
- **Check Remaining Balance:** GET https://apexfaucet.xyz/api/pass/balance with your key header.
- **Wallet-Bound Exclusions:** `arc-passport`, `x1-passport`, `api-pass`, and `api-pass-pro` require direct on-chain payment rather than a prepaid pass.

### Option B — Per-Call x402 Micropayments (No Account Needed)

1. Request any paid route under https://apexfaucet.xyz/api/x402/<route> without payment headers.
2. Read the HTTP `402 Payment Required` response:
   - **x402 v2:** base64 `PAYMENT-REQUIRED` header containing `accepts[]` (`payTo`, `asset`, `amount`, `network`, optional `extra.feePayer`).
   - **x402 v1:** JSON `accepts[]` body with network details and `extensions.bazaar`.
3. Sign an authorization and retry with `PAYMENT-SIGNATURE: <base64 PaymentPayload>`, or direct-pay transaction proof headers `X-PAYMENT-BASE`, `X-PAYMENT-ARC`, `X-PAYMENT-SOL`, or `X-PAYMENT` (XNT on X1).
4. **Idempotency:** Include `Idempotency-Key` (16-128 chars matching `^[a-zA-Z0-9_-]+$`) or x402 v2 `extensions["payment-identifier"]`. Exact retries replay cached settled output without double-charging (`409` on conflicting parameters).

## Step 4 — Call APIs, Scopes & Rate Limits

- **Supported Scopes:** `mcp:tools`, `x402:pay`, `pass:read`, `agora:register`.
- **Rate Limits:**
  - API & MCP traffic: `600` requests/minute (`X-RateLimit-Limit`, `X-RateLimit-Remaining`, `X-RateLimit-Reset`).
  - Anonymous autoregistration: `5` registrations/day per client IP (`30`/day site-wide) at https://apexfaucet.xyz/api/agents/autoregister.
- **Pre-Settlement Validation & Auto-Refunds:** Missing or invalid parameters are rejected before settlement (`400` if payment is attached; `402` hint if bare). Upstream `5xx` errors automatically refund prepaid `api_key` debits.
