Bindu supports the X402 payment protocol, enabling you to monetize your AI agents by requiring cryptocurrency payments before executing specific methods. This allows you to build paid AI services with native blockchain payment integration.
sequenceDiagram
participant User
participant Agent
participant Blockchain
participant Wallet
Note over User,Agent: 1. Start Payment Session
User->>Agent: POST /api/start-payment-session
Agent->>Agent: Create session (15 min expiry)
Agent-->>User: {session_id, browser_url}
Note over User,Wallet: 2. Complete Payment in Browser
User->>Agent: Open browser_url
Agent-->>User: Show paywall UI
User->>Wallet: Connect wallet (MetaMask/Coinbase)
Wallet-->>User: Wallet connected
User->>Wallet: Approve transaction
Wallet->>Blockchain: Submit USDC transfer
Blockchain-->>Wallet: Transaction confirmed
Wallet->>Agent: Send X-PAYMENT header<br/>(signed transaction)
Agent->>Agent: Store payment in session
Note over User,Agent: 3. Verify Payment
User->>Agent: GET /api/payment-status/{session_id}
Agent->>Agent: Check session status
Agent-->>User: {status: completed, payment_token}
Note over User,Agent: 4. Use Protected Method
User->>Agent: POST / (JSON-RPC)<br/>X-Payment-Token: {token}
Agent->>Agent: Validate payment token
Agent->>Blockchain: Verify transaction on-chain<br/>(balance, signature)
Blockchain-->>Agent: Valid
Agent->>Agent: Execute protected method
Agent-->>User: Response
Add the execution_cost configuration to your agent config to enable payment gating.
config = {
"author": "your.email@example.com",
"name": "paid_agent",
"description": "An agent that requires payment",
"deployment": {"url": "http://localhost:3773", "expose": True},
"execution_cost": {
"amount": "$0.0001", # Amount in USD (will be converted to USDC)
"token": "USDC", # Token type (USDC supported)
"network": "base-sepolia", # Network (base-sepolia for testing, base for production)
"pay_to_address": "0x265<your-wallet-address>", # Your wallet address
"protected_methods": [
"message/send" # Methods that require payment
]
}
}You can now provide multiple payment options. The agent will advertise all options to the client, and any one of them can satisfy the requirement. For example:
config = {
"author": "your.email@example.com",
"name": "paid_agent",
"description": "An agent that requires payment",
"deployment": {"url": "http://localhost:3773", "expose": True},
"execution_cost": [
{
"amount": "0.1", # 0.1 USDC on Base
"token": "USDC",
"network": "base",
"pay_to_address": "0xYourWalletAddressHere",
},
{
"amount": "0.0001", # 0.0001 ETH on Ethereum mainnet
"token": "ETH",
"network": "ethereum",
"pay_to_address": "0xYourWalletAddressHere",
},
],
}In this configuration, callers can pay either 0.1 USDC on Base or 0.0001 ETH on Ethereum to access the protected methods.
Choose one of these wallet options:
MetaMask (Recommended):
- Install the MetaMask browser extension
- Create a new wallet or import an existing one
- Copy your wallet address (starts with
0x...)
Coinbase Wallet:
- Install the Coinbase Wallet extension
- Set up your wallet
- Copy your wallet address
For testing on Base Sepolia testnet:
-
Get Base Sepolia ETH (for gas fees):
- Visit Chainlink Faucet
- Connect your wallet
- Request test ETH
-
Get Base Sepolia USDC:
- The payment system will guide you through obtaining test USDC
- Alternatively, use a Base Sepolia faucet that provides USDC
Add your wallet address to the agent config:
"pay_to_address": "0xYourWalletAddressHere" # Replace with your actual addressWhen a user tries to access a protected method, they must first initiate a payment session:
curl --location --request POST 'http://localhost:3773/api/start-payment-session' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <your-access-token>'Response:
{
"session_id": "<session-id>",
"browser_url": "http://localhost:3773/payment-capture?session_id=<session-id>",
"expires_at": "<expires-at>",
"status": "pending"
}- Open the
browser_urlin your web browser - Connect your wallet (MetaMask or Coinbase Wallet)
- Review the payment details:
- Amount in USDC
- Recipient address
- Network (Base Sepolia)
- Approve and sign the transaction
- Wait for blockchain confirmation
After completing the payment, check the session status:
curl --location 'http://localhost:3773/api/payment-status/<session_id>' \
--header 'Authorization: Bearer <your-access-token>'Successful Payment Response:
{
"session_id": "<session-id>",
"status": "completed",
"payment_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}Response Fields:
session_id: The payment session identifierstatus: Payment status (completedmeans payment verified)payment_token: JWT token to include in subsequent API calls
Include the payment_token in your agent requests:
curl --location 'http://localhost:3773/' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <your-access-token>' \
--header 'X-Payment-Token: <payment-token>' \
--data '{
"jsonrpc": "2.0",
"method": "message/send",
"params": {
"message": {
"role": "user",
"content": "Hello, paid agent!"
}
},
"id": 1
}'See the complete example at:
examples/beginner/echo_agent_behind_paywall.py
From the UI, you can obtain the access token and use it to initiate payment sessions.
Important Payment Behavior:
- Each new task requires payment when the agent is behind a paywall
- If a task returns
input_requiredstatus, no payment is needed for that interaction - Once a task completes successfully, a new payment is required for the next task, even within the same conversation/context
- Payment tokens are task-specific and cannot be reused across multiple completed tasks
- Wallet Security: Never share your private keys or seed phrases
- Test Networks: Always test on Base Sepolia before deploying to mainnet
- Payment Verification: Payments are verified on-chain via blockchain signatures
- Session Expiration: Payment sessions expire after 60 seconds by default
- Token Storage: Payment tokens are JWTs with expiration times
When ready for production:
-
Switch to Base Mainnet:
"network": "base" # Change from "base-sepolia"
-
Use Real USDC: Ensure users have actual USDC on Base mainnet
-
Update Wallet Address: Use your production wallet address
-
Monitor Payments: Track incoming payments to your wallet address
-
Set Appropriate Pricing: Adjust
amountbased on your service value
- Start Small: Use low amounts for testing (e.g.,
$0.0001) - Clear Communication: Inform users about payment requirements upfront
- Handle Failures: Implement proper error handling for failed payments
- Session Management: Clean up expired payment sessions regularly
- User Experience: Provide clear instructions in your UI for payment flow
- X402 Protocol Specification
- Base Sepolia Testnet
- Bindu Authentication - Required for payment endpoints

