AI agents can now pay your API autonomously. Here's the infrastructure that makes it possible.
The HTTP 402 status code has existed since 1991. It was reserved for future use. "Payment Required." 35 years later, AI agents finally gave it a purpose. AI agents are already calling external APIs at scale. Claude, GPT, Gemini all have tool calling built in. The problem is there's no standard way to charge them. Until now.
What is x402
Most developers have never seen a 402 response. It was always theoretical. A status code with no real implementation. Coinbase changed that. x402 is an open protocol that turns HTTP 402 into a real payment layer. Here's how it works:
Agent hits your API with no payment
Server returns 402 with payment instructions. How much, which token, which wallet
Agent reads the instructions, signs a USDC transaction on Base, retries the request with payment proof
Server verifies the payment on-chain, returns 200 with the data
The entire loop happens autonomously. No human involved. No accounts, no KYC, no bank. An AI agent consuming your API and paying for it in real time.
$10M+ has already flowed through x402 since launch. The protocol works. The problem is there is not a lot of tooling around it.
The gap I noticed
The x402 spec is solid. But to actually use it you need to:
Provision and manage a crypto wallet to receive payments
Verify on-chain that the payment actually happened before serving the response
Handle the 402 → pay → retry lifecycle correctly
Track every payment somewhere
Eventually get that money out to a real wallet
None of that is trivial. And none of it is what you want to be building when you just want to charge agents for your API. Stripe solved this for card payments 15 years ago. So I built MonkePay to solve this for AI agents.
What I built
MonkePay is payment infrastructure for AI agent APIs. Three lines of middleware on your existing server. That's the entire integration.
const monkePay = MonkePayExpress({
apiKeyId: process.env.MONKEPAY_KEY_ID,
apiKeySecret: process.env.MONKEPAY_KEY_SECRET,
price: '0.001', // $0.001 USDC per request
})
app.get('/api/data', monkePay(), (req, res) => {
res.json({ result: 'paid content' })
})That's it. Your endpoint now charges agents $0.001 per call. No blockchain code. No wallet management. No verification logic. MonkePay handles all of it underneath. It works with Express, Hono, Fastify, and Next.js App Router. Same API across all four.
How it works under the hood
When an agent hits your gated endpoint without payment, MonkePay returns an x402 response with your wallet address, the required USDC amount, and the network. The agent's x402-compatible fetch wrapper reads this, signs a transaction on Base, and retries the request with payment proof in the header.
MonkePay then verifies that transaction on-chain, confirming the USDC actually moved to your wallet before your handler runs. If verification fails, the agent gets another 402. If it passes, your handler runs and the response goes out with a settlement header as cryptographic proof.
For wallet management, MonkePay uses Coinbase Developer Platform wallets. Every account gets a provisioned wallet that receives payments automatically. You set a payout address in the dashboard. Any EVM wallet you control and withdraw USDC to that wallet. The on-chain settlement is real. The money moves. You can verify every transaction on Basescan.
Getting started
Create an account at monkepay.xyz. Get your API keys. Install the SDK:
npm install @monkepay/sdkSet your payout address in Settings. That's the wallet where your USDC lands when you withdraw. For development, use Base Sepolia, the testnet. Get free test USDC from the Circle faucet. Switch to Base mainnet when you're ready for production. One config change.
Two payment modes
Per-request is the default. Agents pay on every call. But there's a second mode worth knowing about: one_time. With one_time, the agent pays once and gets an unlock token. That token grants permanent access to that endpoint. No payment on subsequent calls. The agent just sends the token in a header.
app.get('/api/report', monkePay({ price: '1.00', paymentMode: 'one_time' }), handler)This is useful for reports, exports, or any content that should be pay-once rather than pay-per-use. The token is the key. Whoever holds it gets access.
Who this is for
If you're building an API that AI agents will call. Inference endpoints, data APIs, tool backends, anything agents consume programmatically. MonkePay is the fastest way to monetize it. The agent ecosystem is growing fast. Agents are becoming first-class API consumers. The question is whether your infrastructure is ready to charge them.
x402 is the protocol. MonkePay is what makes it production-ready.
npm: @monkepay/sdk
Docs: docs.monkepay.xyz
Website: monkepay.xyz
Replies