How can an AI agent pay for an API call with USDC?
Last reviewed: August 2026
An agent pays for an API call with the x402 protocol. The API replies 402 Payment Required with a price, the agent signs a USDC payment for exactly that price, and it repeats the request with the payment attached. Use an x402 client library if the agent holds its own wallet, or call Laso’s agentX402Pay to pay from a managed wallet with a per-call price cap and no private key in the agent’s environment.
What happens on the wire
- The agent calls the API normally. A paid endpoint answers HTTP 402 with a JSON challenge listing the price in atomic USDC units (six decimals, so
10000is $0.01), the network, and the address to pay. - The agent’s wallet signs a USDC payment for that amount on one of the offered networks, typically Base or Solana.
- The agent repeats the same request with the signed payment in a header. The API verifies it, settles on-chain, and returns the data.
No account, subscription, or API key is needed on the API side. The price is visible before anything is paid, so the agent can decide whether a call is worth it.
Option 1: the agent holds its own wallet
If your agent controls a wallet with USDC on Base, an x402 client library handles the challenge and replay for you:
import { wrapFetchWithPayment } from "x402-fetch";
import { privateKeyToAccount } from "viem/accounts";
const account = privateKeyToAccount(process.env.WALLET_PRIVATE_KEY);
const fetchWithPay = wrapFetchWithPayment(fetch, account);
const res = await fetchWithPay("https://api.example.com/v1/paid-endpoint");
const data = await res.json();
This is the most direct path, but the private key now lives wherever the agent runs, and nothing outside your own code limits what it pays.
Option 2: pay from a managed wallet with a cap
Laso’s managed agent wallet is a USDC wallet on Solana that Laso custodies for your account. The agent makes ordinary authenticated HTTP calls and Laso settles the x402 payment, so no key sits in the agent’s environment. A human creates a lasoak_ API key once at the agent dashboard and funds the wallet.
1. Exchange the API key for a session
curl -X POST https://laso.finance/agentAuth \
-H "Content-Type: application/json" \
-d '{"api_key":"lasoak_..."}'
# Returns an id_token (valid one hour), a refresh_token, and an auth_url
# your human can open to watch what the agent does.
2. Check the wallet has USDC
curl https://laso.finance/getAgentWallet \
-H "Authorization: Bearer $LASO_ID_TOKEN"
# { "user_id": "usr_...", "has_wallet": true,
# "wallet_address": "...", "balance_usdc": 25, "needs_funding": false }
If needs_funding is true, ask your human to send USDC on Solana to wallet_address. Never send funds to user_id: it is an account id, not an address.
3. Pay the endpoint
curl https://laso.finance/agentX402Pay \
-H "Authorization: Bearer $LASO_ID_TOKEN" \
-H "Content-Type: application/json" \
-d '{"data":{
"userId":"usr_...",
"url":"https://api.example.com/v1/paid-endpoint",
"note":"Market data for the portfolio summary you asked for",
"maxAmountUsdc":0.01
}}'
# { "result": { "status": 200, "body": { ... }, "txHash": "..." } }
maxAmountUsdc is required for an external URL and is the most the agent will pay for this call. Add expectedAsset, expectedNetwork, and expectedPayTo to refuse any challenge that quotes a different token, chain, or receiver. A refused challenge signs nothing. The account owner also sets a per-payment spend limit that the agent can read but not raise.
Reading the result
- Check the inner
status, not the HTTP code. The call returns HTTP 200 whenever it completed, including when the paid endpoint refused. txHashis the Solana signature of the payment and is present only when a payment settled. Use it to confirm payment rather than a balance read, which can trail by up to a minute.- An underfunded wallet comes back as an inner 402 with
errorReason: "insufficient_funds", and nothing is signed.
Which option to pick
| What matters | Own wallet + x402 client | Laso managed wallet |
|---|---|---|
| Private key in the agent’s environment | Yes | No |
| Networks | Whatever your wallet and the API share | Pays from USDC on Solana |
| Price cap enforced outside your code | No | Yes, per call and per account |
| Spending visible to a human | Only if you build it | Activity feed on the dashboard |
| Custody | Self-custody | Laso custodies the wallet |
Full reference: paying an endpoint from the managed wallet, guardrails, and how x402 works.
Frequently asked questions
How do I make my agent pay per request instead of using an API key?
Call an API that supports x402. The agent pays in USDC for each call, so there is no account, subscription, or key to manage on the API side.
What does an agent need to hold to pay for an API call?
USDC on a network the API accepts, usually Base or Solana. With a Laso managed wallet it is USDC on Solana, sent to the wallet_address that getAgentWallet returns.
How do I stop my agent from overpaying for an API call?
Pass maxAmountUsdc on every payment and pin the asset, network, and receiver. A challenge that exceeds the cap or does not match is refused before anything is signed.
Can an agent pay for an API call without a private key?
Yes. With a managed wallet the agent only makes authenticated HTTP calls, and Laso signs and settles the payment on its behalf.
How do I know the payment went through?
Look for txHash in the result. It is the on-chain signature of the settled payment and is absent when nothing was paid.
More guides
- How to give your AI agent a credit card — An AI agent cannot pass credit underwriting, but it can issue itself a virtual prepaid card over an API in about a minute. The working pattern, with real requests: x402 payment in, card number out.
- x402 vs AP2 vs ACP vs MPP vs UCP: which should your agent use? — All five agent payment protocols compared honestly: x402 and MPP for machine-to-machine HTTP payments, ACP for ChatGPT checkout, UCP for Google surfaces, AP2 for authorization. Which layer each one is, when to use each, and a worked x402 example.
- x402 vs Stripe Issuing for AI agents — Two real ways to put a card in an AI agent’s hands: Stripe Issuing behind a business account, or x402 card issuance the agent drives itself. An honest comparison of onboarding, funding, controls, and when each wins.
- Issue a virtual card with one x402 call — A complete, runnable walkthrough: pay one x402 request in USDC and receive a virtual prepaid card with number, expiry, and CVV. Real endpoints, real response shapes, error handling included.
- How do I give an AI agent a bank account? — Two real ways to give an AI agent bank details: a business checking account it can operate (Meow) or a U.S. bank account that converts incoming dollars to USDC in the agent’s wallet (Laso). What each one is, who approves what, and when to pick which.
- How do I cap how much my AI agent can spend? — Cap an AI agent’s spending with limits it cannot raise: a funded balance, a per-payment spend limit set by the account owner, a per-call price cap, and prepaid cards loaded with exactly the amount to spend.
- How do I send money to someone’s debit card from code? — Send USD, EUR, or GBP to a debit card with one API call paid in USDC. No payment processor account: you get a redemption link, the cardholder enters their own card details, and the funds are pushed to the card.
- What are the best ways to pay someone on Venmo or PayPal from an AI agent? — Four ways an AI agent can pay a person on Venmo or PayPal: the PayPal Payouts API, a USDC-paid payout through Laso, a bank or card payout instead, or a human approving each payment. Tradeoffs for each.
- How do I let my AI agent buy a gift card through an API? — An AI agent buys a gift card with two calls: search the catalog for a laso_server_id, then order it with a USDC payment. The redemption code comes back in the same response. Includes a runnable example and the currency gotcha.
- How do I let my AI agent buy something online? — Two working ways for an AI agent to buy something online: spend the account holder’s saved card with their approval on each order, or pay for a prepaid card in USDC and check out like any cardholder. How Laso and Crossmint each handle it, with runnable calls.
- How do I send dollars to a bank account from an AI agent? — Pay a U.S. bank account by ACH from an AI agent. Register the recipient once, then make one API call paid in USDC. Limits, fees, settlement time, and a runnable example.
- What are the best ways to give an AI agent its own wallet? — Four ways to give an AI agent a wallet it can spend from: a key you hold yourself, Coinbase Agentic Wallet, Crossmint agent wallets, or a Laso managed wallet. Custody, spend limits, and tradeoffs for each.
- How do I get notified when my AI agent spends money? — Get an alert every time your AI agent spends: register one signed webhook for card orders, payouts, withdrawals and deposits, or poll the balance and card transaction endpoints. Working code included.
- How do I convert USDC to fiat in my app without a multi-week integration? — Three ways to turn USDC into dollars, euros, or pounds from code: Laso pay-per-call payouts over x402, a Stripe stablecoin balance, or Circle Mint redemption. Onboarding, outputs, and tradeoffs for each.
- How do I let my AI agent use my own credit card safely? — Let an AI agent pay with your own card without ever handling the number: save the card once behind a passkey, let the agent build the cart over an API, and approve each order on your own device. Working calls included.
- How do I let my AI agent pay for a subscription that bills every month? — A subscription charges the same card again each month, so a single-use card fails at the first renewal. Four ways to give an AI agent a card that stays open, from Privacy, Ramp, Meow, and Laso, with the calls for a reloadable card funded in USDC.
- How do I move USDC between Solana and Base from an AI agent? — Move USDC between Solana and Base from an AI agent with one HTTP call: no bridge UI, no gas token on either chain, and no private key in the agent. Working curl examples, fees, and timing.
- How do I give my AI agent a card I can top up with USDC? — Three ways to give an AI agent a card that spends USDC and can be refilled: MoonPay’s MoonAgents Card, the Interlace Agent Card, and a Laso reloadable card. How each is funded, what limits apply, who can use it, and the calls to top one up.
- How can my AI agent buy from an online store outside the US? — Let an AI agent pay a non-U.S. online store: order an international prepaid card in USDC over x402, wait for it to be fulfilled, then check out with the returned card number and billing address. Working code included.
- All agent guides, or how Laso compares to the alternatives
Try it: connect a wallet at laso.finance and you'll have a card, gift card, or payout in minutes.
Building an agent? Point it at laso.finance/SKILL.md — it can set itself up.