x402 Payments: How AI Agents Pay for Things on the Internet
AI agents need to pay for things. They subscribe to APIs, purchase supplies, pay for compute, and buy services from other agents. But the internet’s payment infrastructure was built for humans sitting at checkout forms — not for autonomous software. Credit card forms require clicking buttons, filling fields, and solving CAPTCHAs. OAuth-based billing requires human approval flows. Neither works when an agent needs to pay for something autonomously, in real time, without human intervention. The x402 protocol fixes this.HTTP 402: The Status Code Nobody Used
HTTP 402 Payment Required has been in the spec since 1997. For nearly 30 years, it was “reserved for future use.” Every web developer has seen it in the status code list and wondered what it was for. Now we know: it is for agent payments.How x402 Works
The x402 protocol is straightforward. When an agent makes an HTTP request to a paid resource, the server returns a402 Payment Required response with payment terms in the headers:
Setting Up the Agent Wallet
Every Anima agent can have a wallet with configurable budget guards:Budget Guards: The Safety Net
Budget guards are the core safety mechanism. They prevent an agent from spending more than you authorize, even if the agent’s logic has a bug or encounters an unexpectedly expensive API.| Guard | Purpose |
|---|---|
dailyLimitCents | Maximum total spend in a 24-hour rolling window |
monthlyLimitCents | Maximum total spend in a calendar month |
perTransactionLimitCents | Maximum amount for any single payment |
requireApprovalAboveCents | Payments above this amount require human approval via webhook |
Approval Webhooks
For payments that exceedrequireApprovalAboveCents, Anima sends a webhook to your application for human review:
A Complete Payment Flow
Here is a realistic example: a research agent that pays for premium data from multiple sources.Security and Monitoring
Payments are the highest-risk action an agent can take. Anima layers multiple controls:Policy Engine
Every payment passes through the policy engine before execution. Beyond budget guards, you can define rules like:- Block payments to specific vendors
- Require approval for first-time vendors
- Limit payments to specific merchant categories
- Set time-of-day restrictions
Anomaly Detection
Anima’s anomaly detection monitors x402 payment patterns. It flags unusual activity:- Sudden increase in payment frequency
- Payments to new vendors outside the agent’s normal pattern
- Spending rate approaching daily or monthly limits
- Payments that are unusually large relative to the agent’s history
Audit Trail
Every payment — approved, denied, or flagged — is logged with:- Timestamp, amount, currency
- Vendor and payment description
- Which budget guard was checked
- Whether human approval was required
- The agent’s DID for identity verification
Why x402 Matters
The x402 protocol is not just a convenience — it is infrastructure for the agent economy. As agents proliferate, they need a way to pay for services without human intermediation. x402 provides:- Frictionless micropayments: Agents can pay $0.01 for an API call without the overhead of card processing
- Automatic negotiation: Payment terms are in HTTP headers — no integration required
- Composability: Any HTTP service can become a paid service by returning 402
- Budget safety: Wallet guards prevent runaway spending regardless of what the agent’s LLM decides to do
