AI agents can browse, reason, and call APIs.
But they can’t pay.
That sounds like a small limitation — but it breaks a surprising number of real-world use cases.
The problem: 402 Payment Required
If you’ve built APIs for agents, you’ve probably run into this:
HTTP/1.1 402 Payment Required
The idea is simple:
- your API charges per request
- the client needs to pay before continuing
This works fine for humans.
It doesn’t work for agents.
When an agent hits a paid endpoint:
- it can’t authorize a payment
- it can’t retry after payment
- the workflow just stops
This makes it hard to build:
- pay-per-use APIs
- premium data access
- agent-driven SaaS workflows
What people try (and why it doesn’t work)
1. Giving agents a credit card
This is the obvious approach — and a bad one.
- no spending limits at the agent level
- hard to scope usage
- risky if the agent misbehaves
2. Prefunded wallets
Another common workaround:
- fund a wallet
- let the agent spend from it
Problems:
- capital inefficiency
- poor UX (top-ups, balances, monitoring)
- no fine-grained control per action
3. Keeping a human in the loop
The safest option — and the least scalable.
- every payment requires approval
- breaks automation
- defeats the purpose of agents
The missing piece: controlled, programmable payments
What’s actually needed is a new primitive:
let agents execute payments — but only within strict constraints
That means:
- predefined spending limits
- allowed merchants or endpoints
- expiration rules
- usage tracking
So the agent can act — but not go rogue.
How we approached it
We built a system that introduces the concept of a payment mandate:
- A user approves a mandate (e.g. $50, API X only, expires in 24h)
- The agent operates within that mandate
- Payments are executed automatically when needed
This allows agents to:
- call paid APIs
- handle 402 responses
- retry requests after payment
- stay within defined limits
Handling 402 automatically
Here’s the key flow:
- Agent calls API
- API returns 402 Payment Required
- Payment is executed
- Request is retried automatically
From the agent’s perspective, it just works.
Example (Node.js)
import { Delegare } from '@delegare/sdk';
// Initialize the client
const delegare = new Delegare({
merchantId: 'm_your_agent_platform_id',
apiKey: process.env.DELEGARE_API_KEY
});
// The user's pre-authorized spending token (SD-JWT-VC)
const intentMandate = "eyJhbGciOiJIUzI1Ni... (truncated)";
// 1. Fetch a resource that might be paywalled
// If the server returns 402, Delegare intercepts it, checks the required price
// against the user's monthly budget, signs the payment, and fetches the data.
const response = await delegare.fetch(
'https://api.premium-data-provider.com/weather',
{ method: 'GET' },
intentMandate // Automatically authorize if x402 paywall is hit
);
const data = await response.json();
console.log(data); // Returns the premium data!
The SDK handles:
- payment challenges
- execution
- retries
Real-world use cases
Once agents can pay, a lot of things unlock:
API monetization
charge per request without breaking agent workflowsData access
agents can pay for premium datasetsAutonomous SaaS usage
agents can subscribe or purchase servicesEven consumer scenarios
e.g. an agent ordering food within a set budget
Early usage
We built this while working on agent-based systems and started using it internally.
Without a formal launch, we saw ~1,000 SDK downloads from developers experimenting with the approach.
Where this is going
If agents are going to:
- run workflows
- interact with services
- operate in real environments
They need a way to transact.
We think payment is a missing layer in the current agent stack — and one that will become increasingly important.
If you're building with agents
We’d love feedback from people working on:
- paid APIs
- agent workflows
- MCP / tool integrations
You can try it here:
https://sandbox.delegare.dev
Top comments (0)