Welcome to BNBPAYAI

this guide will help you understand BNBPAYAI, the x402 payment standard implementation on BNB Chain, and help you get started building or integrating services with accountless payments.

BNBPAYAI is built on the open x402 payment standard that enables services to charge for access to their APIs and content directly over HTTP. it is built around the HTTP 402 Payment Required status code and allows clients to programmatically pay for resources without accounts, sessions, or credential management.

with BNBPAYAI, any web service can require payment before serving a response, using crypto-native payments on BNB Chain for speed, privacy, and efficiency.

🔗 Built on BNB Chain
BNBPAYAI leverages BNB Smart Chain (BSC) for fast, low-cost transactions. all payments are processed on-chain with USDC on BNB Chain testnet and mainnet.

Why Use BNBPAYAI?

BNBPAYAI addresses key limitations of existing payment systems:

💸

Low Fees

avoid high fees from traditional credit cards and payment processors by using BNB Chain's efficient infrastructure

🤖

Machine-to-Machine

built for AI agents and automated systems that need to pay for services programmatically

Micropayments

support for tiny payments makes it easy to monetize usage-based services down to fractions of a cent

🔐

No Accounts

no registration, no accounts, no credential management - just pay and use

Who is BNBPAYAI for?

🏪 Sellers (Service Providers)

service providers who want to monetize their APIs or content. BNBPAYAI enables direct, programmatic payments from clients with minimal setup. deploy your API, add x402 payment headers, and start earning.

🛒 Buyers (Developers & AI Agents)

human developers and AI agents seeking to access paid services without accounts or manual payment flows. simply send payment headers with your requests and access premium services instantly.

What Can You Build?

BNBPAYAI enables a range of use cases on BNB Chain:

  • API services paid per request - monetize your APIs with per-call pricing
  • AI agents that autonomously pay for API access - enable AI to use premium tools
  • paywalls for digital content - protect premium content behind payments
  • microservices and tooling monetized via microtransactions - charge tiny amounts for specific operations
  • proxy services that aggregate and resell API capabilities - build marketplaces for API access

How Does It Work?

at a high level, the flow is simple:

  1. a buyer requests a resource from a server
  2. if payment is required, the server responds with 402 Payment Required, including payment instructions
  3. the buyer prepares and submits a payment payload with the BNB Chain transaction
  4. the server verifies the payment on BNB Chain
  5. if payment is valid, the server provides the requested resource
// Example: Client making a paid API request
const response = await fetch('https://api.example.com/analyze', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'x402-payment': '0.005' // Payment amount in USDC
  },
  body: JSON.stringify({ data: 'analyze this' })
});

if (response.status === 402) {
  console.log('Payment required');
} else {
  const result = await response.json();
  console.log('Service result:', result);
}

HTTP 402 Payment Required

the HTTP 402 status code was reserved for future payment systems. BNBPAYAI uses this standard to signal that payment is required for a resource.

Response Format

HTTP/1.1 402 Payment Required
Content-Type: application/json

{
  "error": "Payment required",
  "amount": "0.005",
  "currency": "USDC",
  "network": "bsc-testnet",
  "description": "Data analysis service"
}

BNB Chain Integration

BNBPAYAI is built specifically for BNB Chain, offering several advantages:

🚀 Fast & Cheap

BNB Chain offers 3-second block times and transaction fees under $0.10, making it perfect for micropayments and high-frequency API calls.

💰 USDC Support

all payments are processed in USDC on BNB Chain, providing price stability and easy accounting.

🌐 Network Options

test on BNB Chain testnet with free funds, then deploy to mainnet when ready for production.

Network Chain ID Use Case
BSC Testnet 97 Development & Testing
BSC Mainnet 56 Production

Weather API (Free)

a free API to demonstrate the system without requiring payment.

Endpoint

GET /api/weather?city={city}

Example Request

curl "http://localhost:3000/api/weather?city=London"

Example Response

{
  "city": "London",
  "temperature": "15°C",
  "condition": "Partly Cloudy",
  "humidity": "65%",
  "wind": "12 km/h"
}

Data Analysis API

advanced data analysis service requiring payment of 0.005 USDC.

Endpoint

POST /api/analyze

Headers Required

  • x402-payment: 0.005
  • Content-Type: application/json

Example Request

curl -X POST http://localhost:3000/api/analyze \
  -H "x402-payment: 0.005" \
  -H "Content-Type: application/json" \
  -d '{"data": "Sample data", "analysisType": "sentiment"}'

Example Response

{
  "success": true,
  "analysis": {
    "sentiment": "positive",
    "confidence": 0.92,
    "keyPoints": ["Point 1", "Point 2"]
  },
  "transactionId": "0x..."
}

Image Generation API

AI-powered image generation requiring payment of 0.01 USDC.

Endpoint

POST /api/generate-image

Headers Required

  • x402-payment: 0.01
  • Content-Type: application/json

Request Body

{
  "prompt": "A futuristic city at sunset",
  "style": "realistic",
  "size": "1024x1024"
}

AI Agents with x402

BNBPAYAI enables AI agents to autonomously pay for and use premium services. agents can:

  • detect when payment is required (402 status)
  • calculate the cost-benefit of using a paid service
  • authorize and execute payments on BNB Chain
  • utilize the service and continue their task
🤖 Built with Coinbase AgentKit
BNBPAYAI uses Coinbase AgentKit adapted for BNB Chain, enabling AI agents to manage wallets and execute transactions autonomously.

Setup & Configuration

Prerequisites

  • Node.js 18+
  • Coinbase CDP account
  • API keys (optional for AI features)

Installation

# Clone the repository
git clone https://github.com/yourusername/BNBPAYAI
cd BNBPAYAI

# Install dependencies
npm install

# Configure environment
cp env.example .env.local

# Run development server
npm run dev

Environment Variables

# Coinbase CDP Configuration
CDP_API_KEY_ID=your_api_key_id
CDP_API_KEY_SECRET=your_api_key_secret
CDP_WALLET_SECRET=your_wallet_secret

# Network (use bsc-testnet for development)
NETWORK=bsc-testnet

# AI Configuration (Optional)
OPENAI_API_KEY=your_openai_key
ANTHROPIC_API_KEY=your_anthropic_key

Deployment

Deploy to Vercel

  1. push your code to GitHub
  2. connect your repository to Vercel
  3. add environment variables in Vercel dashboard
  4. deploy

Moving to Mainnet

when ready for production:

  1. change NETWORK=bsc in environment variables
  2. fund your wallet with real USDC on BNB Chain
  3. test thoroughly
  4. monitor transactions and costs

Get Started

ready to build with BNBPAYAI on BNB Chain?