laso

← All agent guides

How can an AI agent pay for an API call with USDC?

Last reviewed: August 2026

The short answer

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

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

Which option to pick

Own wallet vs. managed wallet for paying x402 APIs.
What mattersOwn wallet + x402 clientLaso managed wallet
Private key in the agent’s environmentYesNo
NetworksWhatever your wallet and the API sharePays from USDC on Solana
Price cap enforced outside your codeNoYes, per call and per account
Spending visible to a humanOnly if you build itActivity feed on the dashboard
CustodySelf-custodyLaso 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

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.