Blog
March 23, 2026 7 min read

How to monetize your API for AI agents (with one line of code)

You built an API. It's good. Developers use it. But there's a new type of customer knocking on your door — and they can't sign up.

AI agents are the fastest-growing consumer of APIs right now. They browse documentation, discover endpoints, and try to call them. But when they hit your signup page — account creation, email verification, credit card form — they can't continue. They leave. You never know they were there.

This isn't a future problem. It's happening today, on your API, right now.

The opportunity you're missing

AI agents already spend millions on API calls every month. Coinbase's x402 protocol has settled over 75 million transactions. The agent economy isn't theoretical — it's real, and it's growing fast.

Here's some quick math.

10,000 agents call your API once a day at $0.01 each. That's $100/day. Or $36,500/year. From traffic you're currently losing because agents can't get past your paywall.

The agents are already there. The only question is whether you're collecting the revenue.

The solution: HTTP 402

HTTP 402 is a standard status code that's been in the HTTP spec since 1997. It means "Payment Required." For decades, nobody used it. Now it's the foundation of agent-to-API payments.

Here's how it works in plain English:

1

An agent sends a normal HTTP request to your API.

2

Your server responds with HTTP 402 Payment Required. The response includes: how much it costs, which token (USDC), and which wallet to pay.

3

The agent reads this, signs a USDC payment, and retries the request with a payment header.

4

The x402 facilitator verifies the payment, settles it on-chain, and your API responds with HTTP 200 and the data.

No accounts. No API keys. No invoices. No signup forms. Just HTTP.

The agent doesn't need to know anything about you. Your API doesn't need to know anything about the agent. The payment is embedded in the protocol itself.

How to add it to your API

Install the SDK:

npm install @monapi/sdk @x402/express

Add the middleware to your Express app:

import express from "express";
import { monapi } from "@monapi/sdk";

const app = express();

app.use(monapi({
  wallet: process.env.WALLET,
  price:  0.01,
}));

app.get("/api/weather", (req, res) => {
  res.json({ temp: 22, city: "Berlin" });
});

app.listen(3000);

That's it. Every route now requires payment. When an agent hits your API without paying, here's what it sees:

$ curl -i localhost:3000/api/weather

HTTP/1.1 402 Payment Required
X-Payment-Price:    0.01
X-Payment-Token:    USDC
X-Payment-Network:  base
X-Payment-Wallet:   0x83...913

Any x402-compatible agent reads this response, pays automatically, and retries. Your API responds normally.

Per-route pricing

Not every endpoint is worth the same. Charge differently based on what you're serving:

app.use(monapi({
  wallet: process.env.WALLET,
  routes: {
    "/api/weather":  0.01,   // simple lookup
    "/api/forecast": 0.05,   // more compute
    "/api/search":   0.10,   // expensive query
  },
}));

monapi also supports Next.js and MCP (Model Context Protocol). Same SDK, different entry points. Check the docs for framework-specific examples.

What happens under the hood

When an agent pays your API, here's the full sequence:

1

Request. The agent calls your endpoint. No payment header attached.

2

402. monapi intercepts, returns payment terms: price, wallet, token, network.

3

Payment. The agent signs a USDC transfer using EIP-3009 and retries with the payment in the header.

4

200. The x402 facilitator verifies and settles the payment on-chain. Your API responds with the data.

A few things worth knowing:

Who's already paying?

The x402 ecosystem is live and growing. Agents built with Coinbase AgentKit, Cloudflare Workers, and the Vercel AI SDK already support x402 payments out of the box.

This isn't a whitepaper promise. The infrastructure exists today. Agents are making payments today. The question is whether your API is set up to receive them.

Get started in 5 minutes

You have three options:

  1. Interactive CLI. Run npx monapi init — it detects your framework, configures your wallet, and generates starter code.
  2. Copy the code above. Install the two packages, add the middleware, deploy.
  3. Read the full docs. Every config option, every framework, every edge case — it's all in the documentation.

The SDK is free, open source, and MIT licensed. No monapi account needed. No fees from us.

Your API is already getting traffic from agents.

The only question is whether you're getting paid for it.


Sources

  1. x402 Protocol — Open payment standard by Coinbase for HTTP-native payments
  2. x402 Network Support — Coinbase Developer Platform documentation
  3. USDC Contract Addresses — Circle official documentation
  4. Coinbase AgentKit — AI agent wallet infrastructure
  5. EIP-3009 — Transfer With Authorization (gas-free USDC transfers)
  6. monapi SDK — Source code and documentation on GitHub
  7. @monapi/sdk — npm package