Letting an agent pay

How to charge AI agents for your API

Three ways to get paid by AI agents: x402 middleware with a facilitator, Stripe machine payments over MPP or x402, or API keys with prepaid credits.

Either return HTTP 402 with a price and let agents pay per request, using x402 middleware with a facilitator or Stripe's machine payments over MPP or x402, or keep API keys and sell prepaid credits that the agent's owner buys. Many APIs do both: credits for regular customers, per-request payment for agents that arrive without an account.

Why is this harder than it sounds?

Stripe's own docs put the problem plainly: monetising an API usually needs account creation, a subscription and payment entry, all of which need a person, and an agent mid-task can't do them. Pay-per-request protocols remove the sign-up, but they move work onto your server: stating a price in a machine-readable way, verifying a payment before doing the work, settling it, recording it and handling refunds. The route you pick decides whether you receive stablecoins at your own address, fiat in a Stripe balance, or a top-up you reconcile yourself.

How do you do it?

  1. Decide what one unit costs. Price per request or per unit of work, so a payment maps to a response. Keep the paid endpoint idempotent so a retried request doesn't charge twice.
  2. x402: add the middleware. The x402 seller quickstart has middleware for Express, Next.js, Hono and Fastify, Go's Gin and Echo, and Python's FastAPI and Flask. For each paid route you set a scheme (exact by default), a price, a network in CAIP-2 format and the payTo address that receives funds. Unpaid requests get a 402 Payment Required response with the terms.
  3. x402: choose a facilitator. The facilitator verifies and settles payments for your server. The x402.org facilitator is for testnet only (Base Sepolia and Solana devnet); for mainnet the docs point to production facilitators such as Coinbase's and switch the network to Base mainnet, eip155:8453.
  4. Or use Stripe machine payments. Stripe documents MPP, an open protocol co-authored by Stripe and Tempo, which takes cards through Shared Payment Tokens and stablecoins, and also supports x402 for USDC on Base using a Stripe deposit address as payTo. Payments are recorded as PaymentIntents, land in your Stripe balance and settle in fiat. Stablecoin acceptance is limited by country and US state, so check availability first.
  5. Or keep API keys and prepaid credits. A person signs up, buys credits and gives the agent a key. Every agent framework can use a key today, and the balance caps what the agent can spend, but it can't serve an agent that turns up without an account.
  6. If you accept direct transfers, verify them. Some payers send USDC to an address you publish and give you the transaction hash. Base's docs say to confirm the receipt succeeded and that the Transfer event matches the expected sender, recipient and amount before crediting, and warn there is no escrow or protocol refund flow.
  7. Test before mainnet. Run the full flow on a testnet with a test facilitator or Stripe test mode, then start mainnet with small amounts.

What it does not mean

  • Supporting x402 doesn't make you a custodian of payers' funds. Payments go to your payTo address or, with Stripe, to your Stripe balance.
  • A 402 response isn't a paywall page. Agents read the payment terms from it; people never see it unless they call the API directly.
  • Pay-per-request isn't the only agent-friendly option. An API key with prepaid credits works with every agent, as long as a person sets it up.
  • Accepting stablecoins doesn't mean you must hold them. Stripe settles machine payments in fiat to your balance.

Common questions

How does an agent find out my price?

With x402 and MPP, from the 402 response, which carries the payment requirements. With direct transfers or credits, from your docs, so state prices and the receiving address there.

Can agents pay me by card?

Through MPP on Stripe, using Shared Payment Tokens. x402 itself is for stablecoin payments.

Can I refund an agent?

Stripe says machine payments can be refunded through its Refunds API and Dashboard. For direct on-chain transfers, a refund is a new transfer you send back.

Is this financial or legal advice?

No. It describes how the payment routes work. Tax, licensing and which provider to use are your decisions.

Where does Veyra fit?

Veyra is on the payer side and doesn't take payments for sellers: it has no checkout, middleware or merchant account, and it doesn't implement x402 or MPP, so it can't answer a 402 challenge. What it does is let an agent pay USDC on Base to an address its owner has allowed; Veyra requires a recipient allowlist for unattended auto-pay, and without one the owner signs each payment. Once a payment confirms, get_payment returns the transaction reference and an explorer link the agent can pass to you. So if you accept USDC on Base at a published address and credit the account once you have verified the transfer, Veyra-connected agents can pay you, after their owners add your address to their allowlists.

Veyra's spend policy for one agent endpoint: per-transaction limit, daily limit, auto-approve limit, ask-up-to limit and recipient allowlist
What this looks like in Veyra: one spend policy per agent endpoint, with a per-payment cap, a daily cap, an auto-approve band, an ask band and a recipient allowlist, all checked on the server. Try the free policy generator →

Sources

Terms on this page

This page explains how agent payments and the related technology work. It is not financial, investment, legal or tax advice. Protocols and provider features change; check the linked official sources before relying on a detail.