# ApexApi — Agent Registration (auth.md)

ApexApi is an OpenAI-compatible gateway to 100+ AI models (https://apexapi.dev).
This file is a machine-followable recipe: an agent can register, get a working
API key, have the wallet funded by anyone (card or USDC, no login), and use the
API. A human claiming the account is OPTIONAL — a funded account works forever.

Using the API constitutes acceptance of https://apexapi.dev/legal/terms.

## 1. Discovery

GET https://api.apexapi.dev/.well-known/oauth-protected-resource

The `agent_auth` block lists the endpoints below. The credential issued is a
long-lived API key (prefix `ak-`), not an OAuth access token.

## 2. Register (anonymous)

POST https://api.apexapi.dev/agent/register
Content-Type: application/json

{ "type": "anonymous" }

Response 201:
{
  "account_id": "…",
  "api_key": "ak-…",
  "claim_token": "act_…",
  "fund_url": "https://apexapi.dev/fund/aft_…",
  "expires_unless_funded_at": "…",
  "instructions": "…"
}

IMPORTANT — STORE `api_key` AND `claim_token` durably (config/env). The
`claim_token` is the ONLY recovery path if the key is lost. Accounts that stay
unfunded and unclaimed are deleted after ~30 days; funded accounts never expire.

Rate limit: 10 registrations per IP per day.

## 3. Get funded

Show `fund_url` to whoever pays (your user, their finance person, or pay it
yourself from a crypto wallet). The page accepts card and USDC with no login.
Minimum $5. Unclaimed accounts: max $250 per payment, $500 total — claiming
(step 6) removes these caps.

Poll until funded (≥5s interval):

GET https://api.apexapi.dev/agent/account
Authorization: Bearer ak-…

Response: { "balance_usd": "50.000000", "claimed": false, "fund_url": "…", … }

### Fund autonomously with USDC (no human needed)

If you hold a USDC wallet on Base, you can fund WITHOUT a human:

```
POST https://api.apexapi.dev/agent/fund
Authorization: Bearer ak-…
{ "amount_usd": 50 }
```

Response 200:

```json
{
  "payment_intent": "pi_…",
  "network": "base",
  "deposit_address": "0x…",
  "token": "usdc",
  "token_contract": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
  "amount_usdc": "50.00",
  "amount_usd": 50,
  "instructions": "Send exactly amount_usdc USDC on Base to deposit_address …"
}
```

Send exactly `amount_usdc` USDC on Base to `deposit_address` from your wallet,
then poll `GET /agent/account` until `balance_usd` rises (settles in seconds).
Minimum $5 per call, maximum $10,000. USDC funding has no $500 unclaimed cap
(that cap is card-only) — an agent can fully fund itself and run forever
without a human ever claiming the account.

## 4. Use the API

OpenAI-compatible. Point any OpenAI SDK at the base URL:

POST https://api.apexapi.dev/v1/chat/completions
Authorization: Bearer ak-…
{ "model": "anthropic/claude-haiku-4.5", "messages": [{ "role": "user", "content": "Hello" }] }

Model slugs: `GET https://api.apexapi.dev/v1/models` (or browse https://apexapi.dev/models) · Docs: https://apexapi.dev/docs
Errors use { "error": { "code", "message", "type" } }. 402 = balance empty → show fund_url again.

## 5. Billing model

Prepaid credits, USD, 1:1. Balance is the only limit — no RPM tiers. Each
request costs per-token (or per-image/per-second for media) as listed on the
models page.

## 6. Claim (optional — attaches the account to a human dashboard)

a) POST https://api.apexapi.dev/agent/claim/init
   { "claim_token": "act_…", "email": "user@example.com" }   // email optional, binds the claim
   → { "user_code": "123456", "verification_uri": "https://apexapi.dev/claim",
       "verification_uri_complete": "…?code=123456", "expires_in": 900, "interval": 5 }

b) Show the user BOTH the link and the code:
   "Open https://apexapi.dev/claim and enter code 123 456"

c) Poll: POST https://api.apexapi.dev/agent/claim/poll { "claim_token": "act_…" }
   → 400 authorization_pending | slow_down | expired_token (re-init for a new code)
   → 200 { "status": "claimed", "dashboard_url": "…" }

After claiming, the key keeps working unchanged; the human gets dashboard
visibility, spend guardrails, auto top-up, and the funding caps are removed.

## Error codes (registration layer)

agent_register_rate_limited · registration_type_not_supported ·
invalid_claim_token · authorization_pending · slow_down · expired_token ·
claim_attempts_exceeded

Note: funding caps are enforced on the fund page itself and surface as inline
form messages, not as API error codes.
