# x402 vs API keys: which one your agent should use when

- Author: RomanMotion (https://wurk.fun/user/RomanMotion)
- Published: 2026-10-26
- Canonical (HTML): https://wurk.fun/blog/x402-vs-api-keys-which-one-your-agent-should-use-when
- Cover image: https://ik.imagekit.io/wurk/browser-uploads/f1c626b5c17e7f0a61dfbbe7a20d85ae7b33a20527243aeec2ee1d0a8b87562a/0b226b58-9810-464a-b3a7-2353513b014c/cover-x402.jpg?wurkUpload=v1.tIEwDYrOlo9ocDfBiclbgwcl2t1g5ZIlybYFAY40Mf4

---

You're building an agent that calls paid APIs or sells a service, and every request has a cost. Pick the wrong access model and you can end up managing keys and accounts you barely use, or letting an agent spend without a clear cap. This guide gives you a simple way to choose and a checklist for keeping the payment path in bounds.

The direct answer: x402 is a per-request payment protocol, while an API key is a way to identify and authorize an account or project. They solve different parts of the problem. Use x402 when a service advertises a price for a request and your client can pay it; use key-based access when a provider's account setup, limits, monitoring, or billing arrangements fit your workload better.

## Start with what you're choosing

An API key is a credential, not a billing plan. The provider decides whether access is billed by usage, a subscription, a prepaid balance or something else, and which controls come with the account: rate limits, spend caps, a usage dashboard. Those are features of that provider's setup, not something every key carries, so read the plan before you build around it.

x402 is a protocol for a paid HTTP resource. The server describes accepted payment requirements in a [Payment Required response](https://docs.x402.org/core-concepts/http-402); the client evaluates them and can submit a signed payment payload. The same protocol can be used by an agent acting as the client or by a seller's server protecting a resource ([x402 client/server roles](https://docs.x402.org/core-concepts/client-server)).

For a buyer agent, the practical choice is whether you want to pay each endpoint's stated price or use a provider account with the controls and terms you need. For a seller, it's whether to charge programmatically per request or manage access through customer accounts and keys.

## What an x402 request looks like

The basic flow is: the client requests a resource; the server replies that payment is required and includes its requirements; the client chooses a compatible option and signs a payment payload; then the client retries with the payment header. The server verifies and settles the payment, then returns the resource if successful ([x402 client/server flow](https://docs.x402.org/core-concepts/client-server)).

The exact headers depend on the protocol version. In the current V2 HTTP documentation, the server uses `PAYMENT-REQUIRED`, the client sends `PAYMENT-SIGNATURE`, and the server returns `PAYMENT-RESPONSE` ([HTTP transport headers](https://docs.x402.org/core-concepts/http-402)). Don't copy header names from an older tutorial without checking the version your client and server implement.

The server's requirements can also specify the payment scheme. The x402 docs describe `exact` for a fixed amount and `upto` for a usage-based request where the client authorizes a maximum and the seller charges actual usage ([payment scheme overview](https://docs.x402.org/schemes/overview)). The client still needs to check the amount, asset, destination and network before it signs. A 402 response is a payment request, not a reason to approve every amount automatically.

If a payment header has already been sent and the request times out, don't assume the payment failed. The x402 client/server guidance says the outcome may be unknown; reconcile it before authorizing another payment ([safe retry guidance](https://docs.x402.org/core-concepts/client-server)).

## Where an API key fits

With key-based access, the client sends a credential the provider recognizes, then the provider applies its account and endpoint rules. A key can be convenient when you call the same service regularly, need a provider's account-level monitoring, or have a contract with terms an agent can't get from a request-level payment flow.

But the key also needs protection. OWASP's [Secrets Management Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/Secrets_Management_Cheat_Sheet.html) covers the basics: keep keys out of source code and repos, load them from a secrets manager or the environment, and rotate them. A leaked key keeps working for whoever holds it until you revoke it.

Ask what the provider actually includes: dashboard, support, invoices, predictable quotas. None of that is implied by the word "API key", so check the provider's own plan and billing terms.

## Protect the agent's spending path

An x402 client can authorize payments, so treat its wallet like a spending credential. Use a dedicated wallet for the agent, keep only the amount needed for its work there, and restrict which services it can pay when your client stack supports that.

Coinbase's CDP x402 client, for example, documents spend controls for a maximum per payment, cumulative spending over a time window, and allowed networks ([CDP client configuration](https://docs.cdp.coinbase.com/x402/buyer/client-configuration)). The same page notes those controls exist in its TypeScript SDK but not yet in Python, so don't assume every x402 library has the same guardrails.

Add your own policy checks before signing: allowlist the endpoints the agent may call, reject payment requirements above your per-call limit, and require a person's approval for anything outside the agent's task. For an API-key client, use a dedicated key or project when the provider supports it, set spending and rate limits where available, and keep the key out of prompts, logs and client-side code.

Neither model removes the need to review what the agent is doing. x402 makes the payment request part of the HTTP exchange; an API key authenticates the request. Your application still decides which calls and amounts are allowed.

## The seller's decision

If you sell a service, x402 lets a client request a resource, receive your payment requirements, and retry with the protocol's signed payment payload. That can suit a service you want agents to call without first creating an account or obtaining a long-lived key. The protocol handles the payment handshake; it doesn't decide your price, define your customer support, or write your usage policy ([x402 client/server roles](https://docs.x402.org/core-concepts/client-server)).

An API-key model can make sense when you need to associate usage with customer accounts or apply provider-side access controls. But that means you need to operate the account and key lifecycle: issuing credentials, protecting them, setting limits, and deciding how to handle renewal or revocation.

There isn't one model every seller should choose. Compare the buyer's setup friction, your own operational burden, and whether you need account-level controls. If you need invoices, support commitments, refunds or chargeback handling, verify those terms with the provider or payment setup directly; neither label alone promises them.

## Decision checklist

- Is the service priced per request, or does it require an account?
- Will the agent make occasional calls or steady repeated calls?
- Can the client inspect the price and payment destination before signing?
- Can you enforce a per-call and cumulative spend limit?
- Can the provider's key be scoped, monitored, rotated and revoked?
- Do you need a provider dashboard, account-level rate limits, or documented billing terms?
- Have you tested what happens when a paid request times out after authorization?

Choose the option whose limits you can enforce and whose failure states you can reconcile.

If this helps you avoid an unplanned agent bill, a small tip on this post keeps these guides coming. New to the protocol? Start with [x402 explained for freelancers: how AI agents pay per request](https://wurk.fun/blog/x402-explained-for-freelancers-how-ai-agents-pay-per-request).
