GuidesAI Agent Payments

AI Agent Payments

Enable AI agents to pay for APIs and services autonomously using T402’s MCP (Model Context Protocol) integration.

Overview

AI agents need to access paid APIs, data sources, and compute resources. T402’s MCP server enables:

  • Autonomous payments: Agents pay for resources without human intervention
  • Budget controls: Set spending limits per session or request
  • Multi-chain support: Pay with USDT on any supported network
  • Seamless integration: Works with Claude, GPT, and other MCP-compatible agents

Architecture

┌─────────────┐     ┌─────────────┐     ┌─────────────┐
│   AI Agent  │────>│  MCP Server │────>│  Paid API   │
│  (Claude)   │     │  (@t402/mcp)│     │  (T402)     │
└─────────────┘     └─────────────┘     └─────────────┘

                           v
                    ┌─────────────┐
                    │   Wallet    │
                    │  (Signer)   │
                    └─────────────┘

Setup MCP Server

1. Install the Package

pnpm add @t402/mcp

2. Configure Claude Desktop

Add to your claude_desktop_config.json:

{
  "mcpServers": {
    "t402": {
      "command": "npx",
      "args": ["@t402/mcp"],
      "env": {
        "T402_PRIVATE_KEY": "0x...",
        "T402_NETWORK": "eip155:8453",
        "T402_MAX_AMOUNT": "1.00"
      }
    }
  }
}

3. Environment Variables

VariableDescriptionExample
T402_PRIVATE_KEYWallet private key for signing payments0x...
T402_NETWORKDefault network for paymentseip155:8453 (Base)
T402_MAX_AMOUNTMaximum payment per request1.00 (USDT)
T402_FACILITATOR_URLCustom facilitator URL (optional)https://facilitator.t402.io

Usage Examples

Basic API Access

When Claude encounters a 402 Payment Required response, it will automatically:

  1. Parse the payment requirements from the response
  2. Sign a payment authorization
  3. Retry the request with the payment header
  4. Return the response to you
User: "Get the latest market data from api.example.com/premium/markets"

Claude: I'll access that API for you. It requires a payment of $0.01 USDT.
[Automatically pays and retrieves data]

Here's the market data...

Budget Management

Set spending limits to control costs:

{
  "env": {
    "T402_MAX_AMOUNT": "0.10",
    "T402_DAILY_LIMIT": "10.00"
  }
}

Building T402-Enabled APIs

Create APIs that AI agents can pay to access:

import express from 'express'
import { paymentMiddleware } from '@t402/express'
 
const app = express()
 
app.use(paymentMiddleware({
  'GET /api/market-data': {
    price: '$0.01',
    network: 'eip155:8453',
    payTo: '0xYourAddress...',
    description: 'Real-time market data'
  },
  'POST /api/analyze': {
    price: '$0.05',
    network: 'eip155:8453',
    payTo: '0xYourAddress...',
    description: 'AI-powered analysis'
  }
}))
 
app.get('/api/market-data', (req, res) => {
  res.json({ btc: 45000, eth: 2500 })
})
 
app.listen(3000)

Security Considerations

⚠️

Private Key Security: Never commit private keys to version control. Use environment variables or secure secret management.

  • Spending Limits: Always set T402_MAX_AMOUNT to prevent unexpected charges
  • Network Selection: Use testnets for development (eip155:84532 for Base Sepolia)
  • Key Rotation: Regularly rotate wallet keys for production deployments

Best Practices

  1. Start with testnets: Use Base Sepolia or other testnets for development
  2. Set conservative limits: Start with low T402_MAX_AMOUNT values
  3. Monitor spending: Track payments in your wallet or via facilitator logs
  4. Use dedicated wallets: Create separate wallets for AI agent payments

Premium Content Access

T402 also enables pay-per-access content gating, letting users and agents pay only for what they consume without subscription fatigue.

Content Monetization Patterns

Traditional content monetization has problems:

  • Subscription fatigue: Users don’t want another monthly fee
  • All-or-nothing: No way to access single articles/videos
  • High friction: Credit card forms, account creation

T402 solves this with pay-per-access:

  • One-click payments: Pay with a connected wallet
  • No accounts needed: Wallet is the identity
  • Flexible pricing: Charge per article, per minute, per page

Content Use Cases

Articles & Blog Posts

app.use(paymentMiddleware({
  'GET /article/:id': {
    price: '$0.10',
    network: 'eip155:8453',
    payTo: process.env.WALLET_ADDRESS,
    description: 'Premium article access'
  }
}))

Video Content

// Price per minute of video
'GET /video/:id': {
  price: (req) => {
    const video = getVideoMetadata(req.params.id)
    const pricePerMinute = 0.01
    return `$${video.duration * pricePerMinute}`
  },
  network: 'eip155:8453',
  payTo: process.env.WALLET_ADDRESS
}

E-books & Documents

// Price per page or chapter
'GET /book/:id/chapter/:chapter': {
  price: '$0.25',
  network: 'eip155:8453',
  payTo: process.env.WALLET_ADDRESS,
  description: 'Book chapter access'
}

React Frontend with Paywall

import { usePayment } from '@t402/react'
 
function PremiumArticle({ articleId }) {
  const { pay, isPaying, hasPaid } = usePayment()
  const [content, setContent] = useState(null)
 
  const accessArticle = async () => {
    const response = await pay(`/api/article/${articleId}`)
    if (response.ok) {
      const data = await response.json()
      setContent(data.content)
    }
  }
 
  if (hasPaid && content) {
    return <article>{content}</article>
  }
 
  return (
    <div className="paywall">
      <h2>Premium Article</h2>
      <p>This article requires a one-time payment of $0.10</p>
      <button onClick={accessArticle} disabled={isPaying}>
        {isPaying ? 'Processing...' : 'Pay $0.10 to Read'}
      </button>
    </div>
  )
}

Server-Side Access Control

import express from 'express'
import { paymentMiddleware, verifyPayment } from '@t402/express'
 
const app = express()
 
// Protect premium routes
app.use('/premium/*', paymentMiddleware({
  'GET /premium/article/:id': {
    price: '$0.10',
    network: 'eip155:8453',
    payTo: process.env.WALLET_ADDRESS
  }
}))
 
// Free preview
app.get('/article/:id/preview', (req, res) => {
  const article = getArticle(req.params.id)
  res.json({
    title: article.title,
    excerpt: article.content.substring(0, 200),
    price: '$0.10',
    requiresPayment: true
  })
})
 
// Full content (protected)
app.get('/premium/article/:id', (req, res) => {
  const article = getArticle(req.params.id)
  res.json({
    title: article.title,
    content: article.content,
    author: article.author
  })
})

Content Pricing Strategies

Per-Item Pricing

Content TypeSuggested Price
Short article$0.05 - $0.10
Long article$0.10 - $0.25
Video (per min)$0.01 - $0.05
E-book chapter$0.25 - $0.50
Full e-book$5.00 - $15.00

Bundle Pricing

'GET /bundle/weekly': {
  price: '$1.00', // 10 articles for price of 5
  network: 'eip155:8453',
  payTo: process.env.WALLET_ADDRESS,
  description: 'Weekly content bundle (10 articles)'
}

Time-Based Access

'GET /access/daily': {
  price: '$0.50',
  network: 'eip155:8453',
  payTo: process.env.WALLET_ADDRESS,
  description: '24-hour unlimited access',
  // Store access grant with expiry
  onPayment: (event) => {
    grantAccess(event.payer, '24h')
  }
}

User Experience Tips

Show Value First: Always show a preview or excerpt before asking for payment.

  1. Clear pricing: Display price prominently before the paywall
  2. Preview content: Show enough to demonstrate value
  3. One-click purchase: Minimize friction with connected wallets
  4. Receipt/proof: Provide transaction confirmation

Multi-Chain Content Access

Accept payments on the user’s preferred network:

'GET /article/:id': {
  price: '$0.10',
  networks: ['eip155:8453', 'ton:-239', 'tron:728126428'],
  payTo: {
    'eip155:8453': '0x...',    // Base
    'ton:-239': 'UQ...',        // TON
    'tron:728126428': 'T...'    // TRON
  }
}

Next Steps