This page defines every domain-specific term you will encounter in the Key0 docs. Read it once before diving into protocols or architecture — or use it as a reference when you hit an unfamiliar term.Documentation Index
Fetch the complete documentation index at: https://docs.key0.ai/llms.txt
Use this file to discover all available pages before exploring further.
Roles
Seller
Seller
Buyer (Agent)
Buyer (Agent)
Facilitator
Facilitator
gasWalletPrivateKey. See Settlement Strategies.Payment Concepts
USDC
USDC
Base (L2)
Base (L2)
8453) and Base Sepolia testnet (chain ID 84532). Using L2 keeps per-transaction fees low enough for micropayments.EIP-3009 (transferWithAuthorization)
EIP-3009 (transferWithAuthorization)
Gas Wallet
Gas Wallet
gasWalletPrivateKey to SellerConfig. The gas wallet never holds USDC — it only pays ETH for gas. See Settlement Strategies.Payment Signature (PAYMENT-SIGNATURE header)
Payment Signature (PAYMENT-SIGNATURE header)
Protocol Concepts
x402 Protocol
x402 Protocol
402 with machine-readable PaymentRequirements. The client pays and retries with proof. Key0 implements x402 version 2. See the x402 spec on GitHub.Challenge
Challenge
challengeId, records the expected USDC amount, the destination wallet, and the expiry timestamp. It starts in the PENDING state and moves through the state machine as the payment progresses. See State Machine.AccessGrant
AccessGrant
accessToken— a signed JWT (or other credential) for the protected resourcetokenType— always"Bearer"resourceEndpoint— the URL to call with the tokentxHash— the on-chain transaction hash as proof of paymentexpiresAt— when the token expireschallengeId/requestId— for correlation and idempotency
ResourceResponse (the backend API data) instead of an AccessGrant.ResourceResponse
ResourceResponse
PAID state (awaiting refund) and the ResourceResponse still contains the backend’s error body so the client knows what went wrong.Settlement
Settlement
Transfer event matches the expected amount and destination, then transitions the challenge from PAID to DELIVERED. Settlement can happen via a gas wallet (EIP-3009) or a direct on-chain transfer (txHash proof). See Settlement Strategies.PaymentRequirements
PaymentRequirements
USDC), destination (payTo wallet address), network (eip155:84532), and maximum timeout. Buyers read these values to construct the EIP-3009 authorization.Idempotency
Idempotency
requestId produces the same result without double-charging. If a buyer retries after a network failure, Key0 detects the existing challenge and returns the same AccessGrant rather than creating a second payment. Always pass a stable requestId (e.g., a UUID generated once per purchase intent).Key0 Concepts
Plan
Plan
SellerConfig.plans and exposed via GET /discover and the agent card.Pay-Per-Request (PPR)
Pay-Per-Request (PPR)
SellerConfig.routes.- Embedded — use
key0.payPerRequest(routeId)middleware on individual routes. After on-chain settlement the request is passed to your route handler. The handler receives payment metadata inreq.key0Payment(Express/Fastify) orc.get("key0Payment")(Hono). - Standalone — set
proxyTo.baseUrl(orfetchResource) onSellerConfig. Clients call the paid route directly. After payment Key0 proxies the request to your backend and returns aResourceResponsewith the API data directly.
PENDING → PAID → DELIVERED lifecycle and are eligible for automatic refunds if delivery fails after payment.SellerConfig
SellerConfig
agentName, agentUrl), your wallet address, your plans, your fetchResourceCredentials callback, settlement mode, and optional hooks. It is the single source of truth for your Key0 deployment. See SellerConfig Reference.ChallengeEngine
ChallengeEngine
fetchResourceCredentials, fires onPaymentReceived hooks, and manages idempotency. Both the x402 HTTP middleware and the MCP integration share the same ChallengeEngine instance. See ChallengeEngine Reference.ChallengeRecord
ChallengeRecord
planId, requestId, challengeId, USDC amount, expiry, and current state. The state machine enforces valid transitions on this record atomically. See Data Models.State Machine
State Machine
| State | Meaning |
|---|---|
PENDING | Challenge created, waiting for payment |
PAID | On-chain transfer confirmed, credentials being issued |
DELIVERED | Credentials issued, AccessGrant returned to buyer |
EXPIRED | Challenge TTL passed before payment arrived |
CANCELLED | Manually cancelled |
REFUND_PENDING | Credential issuance failed, refund queued |
REFUNDED | On-chain USDC refund confirmed |
REFUND_FAILED | Refund attempt failed (needs manual review) |
AccessTokenIssuer
AccessTokenIssuer
AccessGrant. It supports HS256 (symmetric secret) and RS256 (RSA key pair) algorithms. The issued token embeds the planId, resourceId, walletAddress, and expiry. Sellers can also use their own fetchResourceCredentials callback to return any credential type. See Token Issuance.fetchResourceCredentials
fetchResourceCredentials
planId, resourceId, and walletAddress of the buyer, and must return the credential (JWT, API key, signed URL, etc.) to include in the AccessGrant. This is the integration point between Key0 and your application’s auth system.Transport Layers
x402 HTTP Transport
x402 HTTP Transport
GET /discover, POST /x402/access, and GET /api/resource. Any HTTP client — curl, fetch, an AI agent — can participate. No special libraries required on the client side. See x402 HTTP Flow.A2A (Agent-to-Agent)
A2A (Agent-to-Agent)
POST /x402/access with an X-A2A-Extensions: x402/v2 header, routing them to the A2A JSON-RPC handler. The payment mechanics are identical to the x402 HTTP flow; only the message envelope differs. See A2A Flow.MCP (Model Context Protocol)
MCP (Model Context Protocol)
POST /mcp (enabled via mcp: true in SellerConfig). Two tools are exposed: discover_plans (free) and request_access (payment-gated). Claude Code, Cursor, and other MCP clients use this to interact with Key0 services. See MCP Integration.Agent Card
Agent Card
GET /.well-known/agent.json that describes the Key0 service: its name, description, URL, available skills (plans), and supported extensions. Agent frameworks use it to auto-discover Key0 services and understand their pricing without any prior configuration. See Agent Card.Infrastructure
Challenge Store (IChallengeStore)
Challenge Store (IChallengeStore)
RedisChallengeStore) and Postgres (PostgresChallengeStore). An in-memory store is available for testing. See Storage.Seen TX Store (ISeenTxStore)
Seen TX Store (ISeenTxStore)
AccessGrant (double-spend protection). See Storage.Audit Store (IAuditStore)
Audit Store (IAuditStore)
Refund Cron
Refund Cron
REFUND_PENDING state and executes on-chain USDC refunds back to the buyer’s wallet. Refunds are triggered when fetchResourceCredentials fails after a confirmed payment. See Refunds.requestId
requestId
requestId always maps to the same challenge and the same AccessGrant. If you omit it, Key0 auto-generates one — but you lose the ability to safely retry on network failure.resourceId
resourceId
fetchResourceCredentials callback so you can issue a credential scoped to a particular resource (e.g., a specific dataset or API endpoint). Defaults to "default" if omitted.
