x402 AI Starter Kit is a fullstack Next.js template from Vercel Labs that wires the x402 HTTP payment protocol into an AI chat app, an AI agent that pays for tools, a remote MCP server, and Coinbase CDP server-managed wallets.
What is the x402 AI Starter Kit?
The x402 AI Starter Kit is an open-source Next.js template that shows how to use x402, a protocol built on top of HTTP for making accountless payments, inside a modern AI stack. It takes Coinbase Developer Platform credentials (CDP_API_KEY_ID, CDP_API_KEY_SECRET, CDP_WALLET_SECRET) plus either a Vercel OIDC token or an AI Gateway API key as input, and produces a running app with an AI chat interface, an API playground, an agent that can pay for tools, a remote MCP server exposing paid tools, paywalled API routes, and paywalled pages served to bots. Vercel Labs publishes the source at github.com/vercel-labs/x402-ai-starter with a hosted demo.
What makes the x402 AI Starter Kit stand out?
- AI chat plus API playground — a working interface for triggering x402 payments and inspecting the request/response flow in the browser.
- AI agent that can pay for tools — the agent spends from a server-managed wallet when it needs a paid capability.
- Remote MCP server with paid tools — Model Context Protocol tools are exposed behind x402 payment requirements.
- Paywalled APIs — route handlers that return a payment challenge instead of data until payment settles.
- Paywalled pages for bots — content gated for crawler/bot traffic rather than human visitors.
- Secure server-managed wallets — wallet creation and funding are handled through Coinbase CDP, so private keys are not handled in client code.
- Next.js, AI SDK, AI Elements, and AI Gateway — the template is assembled on Next.js with AI Elements for chat UI and Vercel AI Gateway for model access.
- Testnet-first defaults — the app runs on base-sepolia and automatically requests more funds from a faucet when the account balance runs low.
Who should use the x402 AI Starter Kit?
- AI app developers who want a working reference for charging per tool call or per request instead of selling subscriptions.
- MCP server authors who need to expose tools to agents and collect micropayments for each invocation.
- API and content publishers evaluating x402 as a way to paywall endpoints and pages without accounts, logins, or API keys.
- Vercel developers who want a Vercel-deployable starting point and are comfortable providing Coinbase CDP credentials.
Use cases
- Monetizing agent tools: run the included MCP server so an AI agent pays a small amount per paid tool call out of a CDP-managed wallet.
- Pay-per-request APIs: reuse the paywalled route pattern to charge callers for JSON endpoints instead of issuing keys.
- Bot-gated content: apply the paywalled-page pattern so crawlers and bots must pay before receiving the page body.
- Prototyping before mainnet: build and test the full payment loop on base-sepolia with faucet-funded test USDC before switching networks.
How does the x402 AI Starter Kit work?
- Clone the repository and run pnpm install.
- Sign into the Coinbase CDP portal and set the three CDP environment variables in .env.local, following .env.example.
- Supply AI Gateway credentials (obtained with vc link and vc env pull, or from the AI Gateway dashboard) or swap in any AI SDK model provider.
- Run pnpm dev and open localhost:3000. For production, push to GitHub, deploy on Vercel, re-add the environment variables, and set NETWORK to base to move from base-sepolia to mainnet.
FAQ
What is x402?
x402 is a payment protocol built on top of HTTP that enables accountless payments that are fast, cheap, and secure. The starter kit uses it to charge for AI tool calls, API routes, and page content without requiring users to create accounts or manage API keys.
Does the x402 AI Starter Kit run on mainnet?
By default it runs on base-sepolia, a testnet using fake money, and automatically tops up from a faucet when the balance is low. To go to production, set the NETWORK environment variable to base and make sure the purchaser account holds enough USDC.
Do I need Vercel AI Gateway to use this template?
No. AI Gateway is used by default, with credentials supplied either through a Vercel OIDC token or an API key, but the template works with any AI SDK model provider and its associated credentials instead.
What credentials does the x402 AI Starter Kit require?
It requires three Coinbase Developer Platform values, CDP_API_KEY_ID, CDP_API_KEY_SECRET, and CDP_WALLET_SECRET, which let the app create and fund server-side wallets used to pay for tools.
