AgentBank x402 Protocol Documentation

Credit provider for AI agents using x402 protocol on Solana. Provides micro-credit in USDC when agents don't have funds, enabling continuous operations.

x402 Credit Provider

Integrates with x402 protocol - pays services in USDC when agents encounter 402 Payment Required

$1 USDC Initial Credit Limit

Each agent can borrow up to $1 USD total in USDC - trustless instant approval. At 0.005$ USDC/Per Call with x402 Protocol, that Micro-loan can fund 200 Calls until the Agent gets topped up from the user.

Quick Start: 3 Steps to Integrate

Already have an AI agent with x402 protocol? Add AgentBank as your credit fallback in 3 simple steps:

1

Register Your Agent (Optional)

Registration happens automatically on first payment, but you can register manually:

curl -X POST https://agentbank.live/api/agentbank/register \
  -H "Content-Type: application/json" \
  -d '{
    "walletAddress": "YOUR_SOLANA_WALLET_ADDRESS",
    "agentName": "My AI Agent"
  }'
2

Add Fallback Logic to Your Agent

Modify your x402 payment handler to use AgentBank when wallet is empty:

// Your existing x402 payment flow
async function handlePayment(url) {
  const response = await fetch(url)
  
  if (response.status === 402) {
    const paymentHeader = response.headers.get('x-payment-required')
    const paymentReq = JSON.parse(paymentHeader)
    
    // Check USDC balance
    const usdcBalance = await checkUSDCBalance(myWallet)
    
    if (usdcBalance >= paymentReq.amount) {
      // Have funds - pay directly
      return await payWithX402(paymentReq)
    } else {
      // No funds - use AgentBank fallback
      return await payWithAgentBank(paymentReq)
    }
  }
  return response
}

// Add AgentBank fallback function
async function payWithAgentBank(paymentReq) {
  const result = await fetch(
    'https://agentbank.live/api/agentbank/x402/credit-payment',
    {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify({
        agentWalletAddress: 'YOUR_WALLET_ADDRESS',
        paymentRequirements: {
          amount: paymentReq.amount,
          recipient: paymentReq.recipient,
          scheme: 'usdc-solana',
          network: 'solana-mainnet'
        },
        agentMetadata: {
          agentName: 'My AI Agent',
          service: url
        }
      })
    }
  )
  
  const data = await result.json()
  
  if (data.success) {
    console.log('✅ AgentBank paid on my behalf')
    console.log('💳 Current debt:', data.agentStatus.currentUsdcDebt, 'USDC')
    console.log('💰 Remaining credit:', data.agentStatus.remainingCreditUsd, 'USD')
    return data
  } else {
    throw new Error('Credit limit exceeded: ' + data.error)
  }
}
3

Test It Works

Make a request to an x402 service with an empty wallet - AgentBank will pay automatically:

// Test with empty wallet
const response = await handlePayment('https://api.example.com/data')

// AgentBank pays the service
// You get the resource
// Debt is tracked automatically

// Check your status anytime
const status = await fetch(
  'https://agentbank.live/api/agentbank/agent/YOUR_WALLET_ADDRESS'
)
const { agent } = await status.json()
console.log('Total USDC debt:', agent.usdc_debt)
console.log('Available credit:', agent.usdc_credit_limit - agent.usdc_debt)

🎉 That's it!

Your agent now has AgentBank as a credit fallback. When you don't have USDC, AgentBank pays services on your behalf. When you earn USDC, debt is automatically repaid. Never blocked by lack of funds again.

Overview

AgentBank is a credit provider for AI agents using the x402 payment protocol on Solana. When agents encounter a 402 Payment Required response and don't have USDC, AgentBank pays the service on their behalf using USDC from the treasury wallet. The agent receives debt which is automatically repaid when they earn USDC.

How It Works

  1. 1. Agent requests resource → Service responds 402 Payment Required (needs $0.01 USDC)
  2. 2. Agent checks wallet → No USDC available
  3. 3. Agent calls AgentBank → POST /api/agentbank/x402/credit-payment
  4. 4. AgentBank validates → Checks agent has credit available (under $1 USD total)
  5. 5. AgentBank pays service → Sends USDC SPL tokens directly to service
  6. 6. Service grants access → Agent receives resource, debt recorded
  7. 7. Auto-repayment → When agent earns USDC, debt is automatically repaid

Integration Guide

Method 1: Direct API Calls (Recommended)

Call AgentBank's credit provider API directly when you encounter a 402 Payment Required response:

// When you receive 402 Payment Required
const response = await fetch('https://api.example.com/data')

if (response.status === 402) {
  const paymentRequirements = JSON.parse(
    response.headers.get('x-payment-required')
  )
  
  // Call AgentBank credit provider
  const creditResult = await fetch(
    'https://agentbank.live/api/agentbank/x402/credit-payment',
    {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify({
        agentWalletAddress: 'YOUR_SOLANA_WALLET_ADDRESS',
        paymentRequirements: {
          amount: paymentRequirements.amount,
          recipient: paymentRequirements.recipient,
          scheme: 'usdc-solana',
          network: 'solana-mainnet'
        },
        agentMetadata: {
          agentName: 'My AI Agent',
          service: 'api.example.com'
        }
      })
    }
  )
  
  const result = await creditResult.json()
  
  if (result.success) {
    console.log('Payment successful via AgentBank credit')
    console.log('Transaction:', result.transactionSignature)
    console.log('Current USDC debt:', result.agentStatus.currentUsdcDebt)
    console.log('Remaining credit:', result.agentStatus.remainingCreditUsd)
    
    // Now retry the original request
    const retryResponse = await fetch('https://api.example.com/data')
    const data = await retryResponse.json()
  } else {
    console.error('Payment failed:', result.error)
  }
}

Method 2: Check Credit Before Payment

Check if your agent has sufficient credit before attempting a payment:

// Updated domain from agentbank.xyz to agentbank.live
// Check credit availability first
const checkResult = await fetch(
  'https://agentbank.live/api/agentbank/x402/credit-payment?' +
  'agentWalletAddress=YOUR_WALLET&amount=0.01'
)

const { canPay, agentStatus } = await checkResult.json()

if (canPay) {
  console.log('Agent has sufficient credit')
  console.log('Available credit:', agentStatus.remainingCreditUsd)
  // Proceed with payment request
} else {
  console.log('Insufficient credit')
  console.log('Current debt:', agentStatus.currentUsdcDebt)
  console.log('Credit limit:', agentStatus.usdcCreditLimit)
}

API Reference

POST /api/agentbank/x402/credit-payment

Request credit payment for x402 service

Request Body:
{
  "agentWalletAddress": "7xKXtg2CW87d97TXJSDpbD5jBkheTqA83TZRuJosgAsU",
  "paymentRequirements": {
    "amount": "0.01",
    "recipient": "9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin",
    "scheme": "usdc-solana",
    "network": "solana-mainnet"
  },
  "agentMetadata": {
    "agentName": "My AI Agent",
    "service": "api.example.com",
    "requestId": "req_123"
  }
}
Response (Success):
{
  "success": true,
  "paymentMethod": "credit",
  "transactionSignature": "5j7s8K9mN2pQ3rT4vW5xY6zA7bC8dE9fG0hI1jK2lM3nO4pQ5rS6tU7vW8xY9z",
  "creditTransactionId": "550e8400-e29b-41d4-a716-446655440000",
  "amountPaid": 0.01,
  "currency": "USDC",
  "network": "solana",
  "agentStatus": {
    "currentUsdcDebt": 0.01,
    "usdcCreditLimit": 1.0,
    "remainingCreditUsd": 0.99,
    "credibilityScore": 50
  }
}

GET /api/agentbank/x402/credit-payment

Check if agent has sufficient credit available

Query Parameters:
GET /api/agentbank/x402/credit-payment?agentWalletAddress=7xKXtg...&amount=0.01
Response:
{
  "canPay": true,
  "reason": "Sufficient credit available",
  "agentStatus": {
    "currentUsdcDebt": 0.0,
    "usdcCreditLimit": 1.0,
    "remainingCreditUsd": 1.0,
    "credibilityScore": 50,
    "status": "active"
  }
}

POST /api/agentbank/register

Register a new agent (automatically called on first credit payment, but can be called manually)

Request Body:
{
  "walletAddress": "7xKXtg2CW87d97TXJSDpbD5jBkheTqA83TZRuJosgAsU",
  "agentName": "My AI Agent"
}
Response:
{
  "success": true,
  "agentId": "550e8400-e29b-41d4-a716-446655440000",
  "agent": {
    "id": "550e8400-e29b-41d4-a716-446655440000",
    "wallet_address": "7xKXtg2CW87d97TXJSDpbD5jBkheTqA83TZRuJosgAsU",
    "agent_name": "My AI Agent",
    "credit_limit": 1.0,
    "current_debt": 0,
    "credibility_score": 50,
    "status": "active"
  }
}

Credit System

  • Credit Limit: $1 USD maximum total debt in USDC per agent
  • Currency: USDC SPL tokens on Solana (1:1 with USD)
  • Instant Approval: Trustless credit decisions - no human gatekeepers
  • Auto-Repayment: When agent wallet receives USDC, debt is automatically repaid
  • Credibility Score: Starts at 50, increases +5 per repayment (max 100)
  • Fallback Mechanism: AgentBank only pays when agent has no USDC - it's a safety net, not primary payment

Error Handling

// Updated domain from agentbank.xyz to agentbank.live
// Handle insufficient credit
const result = await fetch(
  'https://agentbank.live/api/agentbank/x402/credit-payment',
  { 
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify(requestData)
  }
)

const data = await result.json()

if (!data.success) {
  if (data.error.includes('credit limit')) {
    console.log('Credit limit reached')
    console.log('Current USDC debt:', data.agentStatus.currentUsdcDebt)
    console.log('Remaining credit:', data.agentStatus.remainingCreditUsd)
    // Agent needs to repay debt before more credit
  } else if (data.error.includes('suspended')) {
    console.log('Agent account suspended')
    // Contact AgentBank support
  } else if (data.error.includes('Payment failed')) {
    console.log('USDC payment to service failed')
    // Retry or check treasury liquidity
  } else {
    console.log('Payment failed:', data.error)
  }
}

Ready to integrate?

Start using AgentBank as your x402 credit provider. No API keys required - just your Solana wallet address.

POST https://agentbank.live/api/agentbank/x402/credit-payment