How can an AI agent pay for an API without an API key?

Agents · 7 min read · last reviewed 2026-11-12

The short answer: give the agent its own small wallet holding USDC on Base, and wrap its HTTP client with an x402 library. When a paid API answers 402, the library signs a payment for that exact amount and retries. Nobody has to create an account, store an API key or enter a card.

That solves a real problem. An agent can discover a useful tool in the middle of a task, but a sign-up form with an email check, a card field and a captcha is built to stop software. Paying per request removes those steps. If you want the protocol explained first, read what x402 is.

What you need

  • A new wallet used only by the agent. Do not reuse a personal wallet. If the key leaks or the agent misbehaves, the loss stops at whatever you put in this one.
  • A little USDC on Base. The prices below show how far a small amount goes.
  • The private key in an environment variable such as AGENT_WALLET_KEY. Never put it in code, in a prompt, or anywhere the model can read it.
  • An x402 client library. The examples use the official packages for Node and Python.

Getting USDC onto Base

The usual route is to buy USDC on an exchange that supports withdrawals on the Base network, then withdraw to the agent's wallet address. The one mistake to avoid is choosing the wrong network: USDC sent on another chain will not show up on Base, and the agent's payments will be refused. Send a small test amount first. Exchanges have their own minimums and withdrawal fees, so check those before you start.

You do not need ETH for gas with our shop. The wallet signs an authorisation and the facilitator submits it, so USDC is enough. That is how the common USDC setup works, but it depends on the seller's facilitator, so check the terms if you pay anyone else.

How far a small balance goes

Using our shop's prices, last checked on 12 November 2026:

  • $0.10 covers 48 calls of dns-lookup, can-fetch or page-markdown at $0.0021 each.
  • $1 covers 476 of those, or 200 calls of the site-check bundle at $0.005.

Quick tools in the shop run from $0.0021 to $0.005 per call. The full list is on the quick checks page and in catalog.json. For a whole job costed out with a complete script, see lead-list enrichment at $0.0021 per domain or web pages and PDFs to RAG chunks.

Node example

This is the same call as on the shop's start page, with a per-payment cap added. Use version 2.23.0 or later of these packages.

// npm i @x402/fetch @x402/core @x402/evm viem
import { wrapFetchWithPayment } from '@x402/fetch';
import { x402Client } from '@x402/core/client';
import { ExactEvmScheme } from '@x402/evm/exact/client';
import { privateKeyToAccount } from 'viem/accounts';

const signer = privateKeyToAccount(process.env.AGENT_WALLET_KEY);
const client = x402Client.fromConfig({
  schemes: [{ network: 'eip155:8453', client: new ExactEvmScheme(signer) }],
  spendControls: { maxAmountPerPayment: '$0.005' }, // refuse anything dearer
});
const pay = wrapFetchWithPayment(fetch, client);

const r = await pay('https://shop.lordevo.com/api/quick/dns-lookup?host=example.com&type=MX');
console.log(r.status, await r.json());

The first request gets the 402, the wrapper signs and retries, and you receive the normal JSON. The cap of $0.005 matches the dearest quick tool, so a call asking for more is refused before anything is signed. Change it to suit what you buy.

Python example

# pip install "x402[httpx,evm]"
import asyncio, os
from eth_account import Account
from x402 import x402Client
from x402.http.clients import x402HttpxClient
from x402.mechanisms.evm.exact.register import register_exact_evm_client

client = x402Client()
register_exact_evm_client(client, Account.from_key(os.environ["AGENT_WALLET_KEY"]))

async def main():
    async with x402HttpxClient(client) as http:
        r = await http.get("https://shop.lordevo.com/api/quick/can-fetch?url=https://example.com/blog")
        print(r.status_code, r.json())

asyncio.run(main())

Turning it into a tool the agent can call

The model should never touch the wallet. Put the paying call inside an ordinary function, and give the model that function as a tool. The model chooses the tool and its inputs, while your code holds the key and enforces the limits. The shop has short guides for LangChain, CrewAI, the OpenAI Agents SDK and the Vercel AI SDK. If your agent runs in an MCP client such as Claude or Cursor, read how paying for MCP tools works first, because the wallet step is different there.

If the first paid call fails

Most first-run problems are one of these, and none of them cost you anything:

  • You still get a 402 after paying. The payment was not accepted. The usual cause is no USDC on Base, often because it was sent on another network. Check the balance on a Base block explorer using the wallet address.
  • "All payment requirements were rejected by spendControls". The price is above your cap. This is the cap doing its job, so raise it only if the price is what you expected.
  • A 400 or 422 error. The input is wrong or unusable, for example a host name that does not exist. Payment is not the problem.
  • A 403 with robots_disallowed. The site's robots.txt does not allow our fetch, and we respect that. Try another URL.

The full list is in what happens when a paid call fails.

Before you let it run unattended

Keep the balance small, set a cap and add a total budget. An agent stuck in a loop can make many cheap calls quickly, and a per-payment cap will not stop that. How to limit what an agent can spend has tested code for this.

Try it first with no wallet

Three free calls per IP address per UTC day work on tools up to $0.0022, which is enough to confirm a tool returns what your agent needs:

curl "https://shop.lordevo.com/api/quick/dns-lookup?host=example.com&trial=1"

How this was checked: the Node cap was run on 4 November 2026 with @x402 packages 2.29.0 against a stub seller, with no network and no real money. The Python code is copied from the shop's start page, whose notes say the 402 was parsed and a payment built with x402 2.26.0.

Questions

Does the agent need ETH for gas on Base?

Not with our shop, and not with the common x402 USDC setup. The wallet signs an authorisation and the facilitator submits it on chain and pays the network fee. Direct transfers made outside x402 do need gas.

Where should the agent private key be stored?

In an environment variable or a secrets manager that only your tool code can read. Keep it out of prompts, logs and source control, and keep only a small balance in that wallet.

Can an agent pay with a credit card instead?

Not through x402 as our shop runs it, which takes USDC on Base only. Card fees also make payments of a fraction of a cent impractical. Our website audits for people are paid by card through Stripe, but they are separate products.

Do I have to do KYC to use the shop?

The shop asks for no account or identity details. If you buy USDC on an exchange, that exchange will have its own identity checks.

Try a pay-per-call tool

Web, domain and data checks for agents over x402, in USDC on Base. No account and no API key. Prices and inputs for every tool are in the catalogue.