Skip to main content

AI Agent Payments (x402)

Enable automated payments for AI agents using the x402 protocol.

Overview​

The x402 protocol allows AI agents to make autonomous payments within predefined limits, enabling machine-to-machine commerce.

How It Works​

Registering an AI Agent​

const agent = await pelago.agents.create({
name: 'Research Assistant',
operatorPID: 'did:pelago:stellar:GOPERATOR...',
capabilities: ['micropayments', 'api_access'],
spendingLimits: {
perTransaction: 5.00, // Max $5 per payment
hourly: 20.00, // Max $20/hour
daily: 100.00, // Max $100/day
monthly: 1000.00 // Max $1000/month
},
allowedRecipients: [
'did:pelago:stellar:GSERVICE...'
]
});

console.log('Agent PID:', agent.pid);

Making Agent Payments​

// Agent-initiated payment
const payment = await pelago.agentPayments.create({
agentPID: 'did:pelago:stellar:GAGENT...',
recipientPID: 'did:pelago:stellar:GSERVICE...',
amount: 0.01,
currency: 'USD',
purpose: 'API call - /v1/search',
signature: agentSignature // Agent's cryptographic signature
});

x402 Protocol Headers​

# Service responds with payment requirement
HTTP/1.1 402 Payment Required
X-Payment-Required: pelago
X-Payment-Amount: 0.01
X-Payment-Currency: USD
X-Payment-Recipient: did:pelago:stellar:GSERVICE...
X-Payment-Endpoint: https://pay.pelago.tech/agent

# Agent includes payment proof
GET /api/resource
X-Payment-Token: pay_token_xxx

Spending Controls​

Operators can monitor and control agent spending:

// Get agent spending summary
const spending = await pelago.agents.getSpending('agent_abc123');
console.log('Today:', spending.daily);
console.log('This month:', spending.monthly);

// Pause agent
await pelago.agents.pause('agent_abc123');

// Update limits
await pelago.agents.updateLimits('agent_abc123', {
daily: 200.00
});

Use Cases​

  • API Monetization: Charge per API call
  • Content Access: Pay-per-article/document
  • Compute Resources: Pay for AI/ML inference
  • Data Services: Pay for data queries