# Key0 ## Docs - [Agent Card](https://docs.key0.ai/api-reference/agent-card.md): GET /.well-known/agent.json — the A2A discovery endpoint that describes your agent's capabilities and pricing. - [Data Models](https://docs.key0.ai/api-reference/data-models.md): TypeScript type definitions for all protocol messages — AccessRequest, X402Challenge, PaymentProof, AccessGrant, ChallengeRecord, and ChallengeState. - [MCP Tools](https://docs.key0.ai/api-reference/mcp-tools.md): discover_plans and request_access — the two MCP tools exposed by Key0 for plan discovery and payment-gated access. - [Overview](https://docs.key0.ai/api-reference/overview.md): All HTTP endpoints served by Key0 at a glance. - [POST /x402/access](https://docs.key0.ai/api-reference/x402-access.md): The x402 HTTP payment endpoint — handles discovery, challenge issuance, and payment settlement in a single URL. - [Payment Flow](https://docs.key0.ai/architecture/payment-flow.md): The full Key0 payment lifecycle: challenge issuance, on-chain settlement, token delivery, and the two endpoints that feed into the shared ChallengeEngine. - [Project Structure](https://docs.key0.ai/architecture/project-structure.md): Source directory layout, core layers, and entry points for the Key0 SDK. - [Automatic Refunds](https://docs.key0.ai/architecture/refunds.md): When token issuance fails after payment, Key0 automatically refunds USDC to the buyer. Learn how the refund state machine, cron job, and double-refund prevention work. - [Settlement Strategies](https://docs.key0.ai/architecture/settlement-strategies.md): How Key0 settles on-chain payments: facilitator mode vs. gas wallet mode. - [State Machine](https://docs.key0.ai/architecture/state-machine.md): Challenge lifecycle states, allowed transitions, atomic Lua scripts, and Redis schema - [Storage](https://docs.key0.ai/architecture/storage.md): Configure Redis or Postgres backends for challenge state, transaction dedup, and audit trails. Both provide the same atomic guarantees. - [Token Issuance](https://docs.key0.ai/architecture/token-issuance.md): How Key0 issues and validates JWTs after payment. Covers AccessTokenIssuer, HS256/RS256 algorithms, timeout behavior, and the validateAccessToken middleware. - [Docker](https://docs.key0.ai/deployment/docker.md): Run Key0 as a Docker container. Choose from pre-built profiles with managed Redis and Postgres, or bring your own infrastructure. - [Environment Variables](https://docs.key0.ai/deployment/environment-variables.md): Complete reference of all environment variables for standalone Docker and embedded SDK deployments. - [Backend Integration](https://docs.key0.ai/examples/backend-integration.md): How to integrate an existing backend with the Key0 standalone service — token validation, internal endpoints, and resource-scoped access control. - [Express Seller](https://docs.key0.ai/examples/express-seller.md): A Photo Gallery Agent built with Express that sells photo access to AI agents via USDC payments. - [Hono Seller](https://docs.key0.ai/examples/hono-seller.md): A Photo Gallery Agent built with Hono that sells photo access to AI agents via USDC payments. - [Pay-Per-Request: Embedded](https://docs.key0.ai/examples/ppr-embedded.md): Key0 embedded inside your application — weather and joke routes gated behind per-request USDC micro-payments. No JWT issued; payment settles inline. - [Pay-Per-Request: Standalone Gateway](https://docs.key0.ai/examples/ppr-standalone.md): Key0 running as a separate payment gateway — clients call paid routes directly, Key0 settles the payment, proxies to your backend, and returns the response directly. Works for HTTP, A2A, and MCP clients. - [Refund Cron](https://docs.key0.ai/examples/refund-cron.md): Demonstrates automatic on-chain USDC refunds when token delivery fails, using BullMQ for background job processing. - [Standalone Service](https://docs.key0.ai/examples/standalone-service.md): A production-ready Key0 standalone service with configurable storage, auth strategies, token modes, gas wallet support, and automatic refunds. - [Agent CLI](https://docs.key0.ai/guides/agent-cli.md): Generate a branded CLI binary for your Key0 service that agents can install and use autonomously. - [Building a Seller](https://docs.key0.ai/guides/building-a-seller.md): End-to-end guide to building a payment-gated API with Key0. From install to mainnet in 11 steps. - [Claude Code Integration](https://docs.key0.ai/guides/claude-code-integration.md): Connect Claude Code to a Key0-protected API. Discover plans, pay with USDC, and access protected endpoints — all from the CLI. - [Express](https://docs.key0.ai/integrations/express.md): Mount Key0 as Express middleware. Serves agent discovery, payment endpoints, and optional MCP routes — then protect your own routes with a single middleware. - [Fastify](https://docs.key0.ai/integrations/fastify.md): Register Key0 as a Fastify plugin for agent discovery, x402 payments, and access token validation. - [Hono](https://docs.key0.ai/integrations/hono.md): Mount Key0 as a Hono sub-app for agent discovery and x402 payments. - [Core Concepts](https://docs.key0.ai/introduction/core-concepts.md): Plain-English definitions of every Key0 term, from USDC and EIP-3009 to ChallengeEngine and AccessGrant. - [How It Works](https://docs.key0.ai/introduction/how-it-works.md): Key0's two-phase payment flow: challenge, pay, access. - [Sell Anything to AI Agents](https://docs.key0.ai/introduction/overview.md): Key0 is a TypeScript SDK that lets API providers sell APIs, data, goods, or services to AI agents -- with built-in USDC payments, zero proxying, and no architectural changes. - [Two Modes](https://docs.key0.ai/introduction/two-modes.md): Key0 can run as a standalone Docker service or as middleware embedded in your app. Choose the mode that fits your workflow. - [A2A Flow](https://docs.key0.ai/protocol/a2a-flow.md): Agent-to-Agent payment flow using Google's A2A protocol with x402 metadata over the unified /x402/access endpoint. - [MCP](https://docs.key0.ai/protocol/mcp.md): Expose Key0 payment-gated plans as MCP tools. Agents discover plans and purchase access tokens through the x402 protocol over Streamable HTTP. - [x402 HTTP Flow](https://docs.key0.ai/protocol/x402-http-flow.md): The simplest way to interact with Key0 -- a single POST /x402/access endpoint that handles discovery, challenge creation, and payment settlement. - [Quickstart: Embedded](https://docs.key0.ai/quickstart/embedded.md): Add Key0 middleware to an existing Express, Hono, or Fastify server in under 5 minutes. Agents discover your pricing, pay in USDC, and access your protected endpoints. - [Standalone Docker](https://docs.key0.ai/quickstart/standalone.md): Run Key0 as a standalone Docker container alongside your existing API. Two options: a visual Setup UI for zero-config start, or environment variables for automation. - [AccessTokenIssuer](https://docs.key0.ai/sdk-reference/access-token-issuer.md): API reference for AccessTokenIssuer — JWT creation and verification with HS256 or RS256, including zero-downtime secret rotation. - [Auth Helpers](https://docs.key0.ai/sdk-reference/auth-helpers.md): Service-to-service authentication strategies for outbound requests — noAuth, sharedSecretAuth, signedJwtAuth, and oauthClientCredentialsAuth. - [ChallengeEngine](https://docs.key0.ai/sdk-reference/challenge-engine.md): API reference for ChallengeEngine — the core class that manages the challenge lifecycle from access request through payment to credential delivery. - [Error Codes](https://docs.key0.ai/sdk-reference/error-codes.md): Complete reference of Key0ErrorCode values, HTTP status codes, and the Key0Error class. - [createKey0()](https://docs.key0.ai/sdk-reference/factory.md): API reference for the createKey0 factory function — wires together config, adapter, and storage into a complete Key0 instance. - [Middleware](https://docs.key0.ai/sdk-reference/middleware.md): Access token validation middleware for Express, Hono, and Fastify — plus the standalone validateKey0Token for backend services. - [Overview](https://docs.key0.ai/sdk-reference/overview.md): Package exports, subpath imports, and install instructions for @key0ai/key0. - [SellerConfig](https://docs.key0.ai/sdk-reference/seller-config.md): Complete reference for the SellerConfig object — identity, payment, plans, credential issuance, hooks, and settlement options. - [Storage](https://docs.key0.ai/sdk-reference/storage.md): API reference for IChallengeStore, ISeenTxStore, and IAuditStore — the storage interfaces that power atomic state transitions and double-spend prevention. - [X402Adapter](https://docs.key0.ai/sdk-reference/x402-adapter.md): API reference for X402Adapter — the payment adapter that verifies USDC transfers on Base via on-chain ERC-20 Transfer events. ## OpenAPI Specs - [openapi](https://docs.key0.ai/api-reference/openapi.json) ## Optional - [NPM Package](https://www.npmjs.com/package/@key0ai/key0) - [Docker Hub](https://hub.docker.com/r/key0ai/key0)