VercelLogotypeVercelLogotype
LoginSign Up
Back to Templates

x402 AI Starter

A fullstack template for using x402 with MCP and AI SDK.

DeployView Demo
Contentful thumbnail for x402 AI Starter

x402 Next.js + AI Starter Kit

x402 is a new protocol built on top of HTTP for doing fully accountless payments easily, quickly, cheaply and securely.

This template built with Next.js, AI SDK, AI Elements, and AI Gateway and the Coinbase CDP shows off using x402 with a modern AI stack.

Demo: https://x402-ai-starter.vercel.app/

Features

  • AI Chat + API playground to see x402 in action
  • AI agent that can pay for tools
  • Remote MCP server with "paid" tools
  • Paywalled APIs
  • Paywalled pages (for bots)
  • Secure server managed wallets

Tech Stack

  • Next.js
  • AI SDK
  • AI Elements
  • AI Gateway
  • Coinbase CDP
  • x402

Getting Started

git clone https://github.com/vercel-labs/x402-ai-starter
cd x402-ai-starter
pnpm install

Running Locally

  1. Sign into the Coinbase CDP portal

  2. Following .env.example, set the following environment variables in .env.local:

  • CDP_API_KEY_ID
  • CDP_API_KEY_SECRET
  • CDP_WALLET_SECRET

Using AI Gateway requires either a Vercel OIDC token, or an API Key. To get an OIDC token, simply run vc link then vc env pull. An API can be obtained from the AI Gateway dashboard.

Using AI Gateway isn't required, you can use any AI SDK model provider and its associated credentials.

  1. Run pnpm dev

  2. Open http://localhost:3000 in your browser to see the app in action.

Testing Payments

By default, the app uses the base-sepolia network, or "testnet". This is a testing network with fake money. The app is configured to automically request more funds from a faucet (source of testnet money) when your account is running low. You can also do this yourself in the Coinbase CDP dashboard.

Going to Production

When you're ready to deploy your SaaS application to production, follow these steps:

Deploy to Vercel

  1. Push your code to a GitHub repository.
  2. Connect your repository to Vercel and deploy it.
  3. Follow the Vercel deployment process, which will guide you through setting up your project.

Add environment variables

In your Vercel project settings (or during deployment), add all the necessary environment variables. Make sure to update the values for the production environment, including:

  • CDP_API_KEY_ID
  • CDP_API_KEY_SECRET
  • CDP_WALLET_SECRET

Moving to mainnet

To move to mainnet, set the NETWORK environment variable to base.

Make sure that the Purchaser account has enough funds to pay for the tools you're using. To fund the account, you can send USDC to the account's address in the Coinbase CDP dashboard.

GitHub Repovercel-labs/x402-ai-starter
Use Cases
AIWeb3
Stack
Next.jsTailwind

Related Templates

Get Started

  • Templates
  • Supported frameworks
  • Marketplace
  • Domains

Build

  • Next.js on Vercel
  • Turborepo
  • v0

Scale

  • Content delivery network
  • Fluid compute
  • CI/CD
  • Observability
  • AI GatewayNew
  • Vercel AgentNew

Secure

  • Platform security
  • Web Application Firewall
  • Bot management
  • BotID
  • SandboxNew

Resources

  • Pricing
  • Customers
  • Enterprise
  • Articles
  • Startups
  • Solution partners

Learn

  • Docs
  • Blog
  • Changelog
  • Knowledge Base
  • Academy
  • Community

Frameworks

  • Next.js
  • Nuxt
  • Svelte
  • Nitro
  • Turbo

SDKs

  • AI SDK
  • Workflow SDKNew
  • Flags SDK
  • Chat SDK
  • Streamdown AINew

Use Cases

  • Composable commerce
  • Multi-tenant platforms
  • Web apps
  • Marketing sites
  • Platform engineers
  • Design engineers

Company

  • About
  • Careers
  • Help
  • Press
  • Legal
  • Privacy Policy

Community

  • Open source program
  • Events
  • Shipped on Vercel
  • GitHub
  • LinkedIn
  • X
  • YouTube

Loading status…

Select a display theme:
    • AI Cloud
      • v0

        Build applications with AI

      • AI SDK

        The AI Toolkit for TypeScript

      • AI Gateway

        One endpoint, all your models

      • Vercel Agent

        An agent that knows your stack

      • Sandbox

        AI workflows in live environments

    • Core Platform
      • CI/CD

        Helping teams ship 6× faster

      • Content Delivery

        Fast, scalable, and reliable

      • Fluid Compute

        Servers, in serverless form

      • Observability

        Trace every step

    • Security
      • Bot Management

        Scalable bot protection

      • BotID

        Invisible CAPTCHA

      • Platform Security

        DDoS Protection, Firewall

      • Web Application Firewall

        Granular, custom protection

    • Company
      • Customers

        Trusted by the best teams

      • Blog

        The latest posts and changes

      • Changelog

        See what shipped

      • Press

        Read the latest news

      • Events

        Join us at an event

    • Learn
      • Docs

        Vercel documentation

      • Academy

        Linear courses to level up

      • Knowledge Base

        Find help quickly

      • Community

        Join the conversation

    • Open Source
      • Next.js

        The native Next.js platform

      • Nuxt

        The progressive web framework

      • Svelte

        The web’s efficient UI framework

      • Turborepo

        Speed with Enterprise scale

    • Use Cases
      • AI Apps

        Deploy at the speed of AI

      • Composable Commerce

        Power storefronts that convert

      • Marketing Sites

        Launch campaigns fast

      • Multi-tenant Platforms

        Scale apps with one codebase

      • Web Apps

        Ship features, not infrastructure

    • Tools
      • Marketplace

        Extend and automate workflows

      • Templates

        Jumpstart app development

      • Partner Finder

        Get help from solution partners

    • Users
      • Platform Engineers

        Automate away repetition

      • Design Engineers

        Deploy for every idea

  • Enterprise
  • Pricing
Log InContact
Sign Up
Sign Up
Back to Templates
DeployView Demo

MCP with Next.js

Run an Model Context Protocol (MCP) server on Vercel with Next.js.
MCP with Next.js

Vercel AI Gateway Demo

An open-source AI chatbot built with Next.js, the AI SDK, and the AI Gateway.
Vercel AI Gateway Demo

Wallet Manager with Coinbase Developer Platform

Wallet manager dashboard built with Coinbase Developer Platform to create and manage wallets, track balances, and fund wallets.
Wallet Manager with Coinbase Developer Platform
v0

Build applications with AI

AI SDK

The AI Toolkit for TypeScript

AI Gateway

One endpoint, all your models

Vercel Agent

An agent that knows your stack

Sandbox

AI workflows in live environments

CI/CD

Helping teams ship 6× faster

Content Delivery

Fast, scalable, and reliable

Fluid Compute

Servers, in serverless form

Observability

Trace every step

Bot Management

Scalable bot protection

BotID

Invisible CAPTCHA

Platform Security

DDoS Protection, Firewall

Web Application Firewall

Granular, custom protection

Customers

Trusted by the best teams

Blog

The latest posts and changes

Changelog

See what shipped

Press

Read the latest news

Events

Join us at an event

Docs

Vercel documentation

Academy

Linear courses to level up

Knowledge Base

Find help quickly

Community

Join the conversation

Next.js

The native Next.js platform

Nuxt

The progressive web framework

Svelte

The web’s efficient UI framework

Turborepo

Speed with Enterprise scale

AI Apps

Deploy at the speed of AI

Composable Commerce

Power storefronts that convert

Marketing Sites

Launch campaigns fast

Multi-tenant Platforms

Scale apps with one codebase

Web Apps

Ship features, not infrastructure

Marketplace

Extend and automate workflows

Templates

Jumpstart app development

Partner Finder

Get help from solution partners

Platform Engineers

Automate away repetition

Design Engineers

Deploy for every idea