Skip to content

How to Pay for an x402 API with Coinbase AgentKit (2026)

Pay an x402 API with Coinbase CdpX402Client/AgentKit: Node 22+, CDP keys, Base Sepolia faucet, wrapFetchWithPayment; Facilitator 1k free then $0.001.

How to Pay for an x402 API with Coinbase AgentKit

Table of Contents

AI agents can call APIs all day, then stall the moment the server returns HTTP 402 Payment Required. Without a wallet that can sign a USDC payment and retry, the agent never gets the protected resource.

Coinbase's buyer path closes that gap: a CDP-managed wallet via CdpX402Client (or AgentKit x402 actions) pays on Base testnet or mainnet, settles through x402, and returns HTTP 200 with no private key file on disk.

📌
Stablecoin Insider's framing: this is the buyer-side first payment with CdpX402Client / AgentKit. Seller-side Stripe x402, facilitators, Skyfire, and Circle nanopayments are covered in separate Stablecoin Insider guides.

This guide walks prerequisites, a Base Sepolia test payment against Coinbase's demo endpoint, the AgentKit tool path when the model should choose actions, Facilitator pricing and network support as of September 12, 2026, and the guardrails that make this path unsafe for end-user self-custody.

Key Takeaways

  • CdpX402Client plus wrapFetchWithPayment pays an x402 API from a CDP-managed wallet with no local private key file.
  • environment: "development" targets Base testnet; omit it for Base mainnet per Coinbase's buyer quickstart.
  • AgentKit exposes discover_x402_services, make_http_request, retry_http_request_with_x402, and make_http_request_with_x402.
  • CDP Facilitator: first 1,000 onchain txs/month free, then $0.001 each, with OFAC/KYT screening on supported networks.
  • Named downside: server-held CDP secrets need spend limits; KYT can block; testnet is not mainnet; Embedded Wallets fit end-user custody.
⚠️
Named downside: CDP_API_KEY_ID, CDP_API_KEY_SECRET, and CDP_WALLET_SECRET live on your backend. Without spend limits and KYT awareness, a compromised agent can drain the wallet or fail settlement on screened addresses.

What AgentKit, CdpX402Client, and Agentic Wallets are

On February 11, 2026, Coinbase launched Agentic Wallets as wallet infrastructure built for autonomous agents. Coinbase's launch page frames Agentic Wallets as the successor path after AgentKit, which first embedded wallets into agents.

That same launch page claims x402 was already battle-tested with over 50 million transactions (Coinbase Developer Platform, Feb 11, 2026). Treat that as a protocol-scale claim, not your agent's monthly volume.

For a first paid API call without writing a full agent loop, Coinbase's x402 quickstart for buyers centers on CdpX402Client from @coinbase/cdp-sdk/x402 plus wrapFetchWithPayment from @x402/fetch.

Use AgentKit (@coinbase/agentkit) when the agent should discover services and choose payment tools itself. Use Embedded Wallets when humans, not your server, should hold the paying wallet.

Prerequisites (as of Sep 12, 2026)

Coinbase's buyer quickstart requires Node.js 22 or later, a CDP API key pair, and a wallet secret so the SDK can sign payments with a CDP-managed wallet.

Export these before you run anything:

  • CDP_API_KEY_ID
  • CDP_API_KEY_SECRET
  • CDP_WALLET_SECRET

Install the TypeScript stack Coinbase documents for buyers:

npm install @coinbase/cdp-sdk @x402/core @x402/evm @x402/svm @x402/extensions @x402/fetch

Python is also documented (Python 3.10+, cdp-sdk and x402[evm,svm,httpx]), but it has no CdpX402Client helper. You assemble the signer and scheme yourself. This guide stays on the TypeScript path.

Step-by-step: first paid call with CdpX402Client

1. Create the client on Base testnet

Instantiate CdpX402Client({ environment: "development" }). Coinbase's docs state that "development" uses the Base testnet. Omit the environment flag when you are ready for Base mainnet.

Call client.getAddresses() and log evmAddress. That address is the CDP-managed payer you will fund. There is still no private key file for you to store.

2. Fund with Base Sepolia USDC

The first run usually prints the address and then fails, because the wallet holds no USDC yet. Fund that address with test USDC on base-sepolia.

Fastest path in code (same credentials): CdpClient().evm.requestFaucet({ address, network: "base-sepolia", token: "usdc" }). Wait for the faucet transaction to confirm before retrying.

For production funding patterns and treasury ops, see how to fund an AI agent wallet with USDC.

How to Fund an AI Agent Wallet with USDC

3. Wrap fetch and hit the protected demo

Wrap the global fetch: wrapFetchWithPayment(globalThis.fetch, client). Then request Coinbase's demo protected endpoint: https://x402.vercel.app/protected.

On success the console shows HTTP 200. That means payment was verified and settled, and you received the protected resource without an account, invoice, or card.

🔧
Ops check: if you still see a failure after faucet, confirm the faucet tx confirmed on Base Sepolia and that environment is still "development". Mainnet USDC will not fund a development client.

AgentKit path: when the agent should choose tools

CdpX402Client is the explicit buyer client. AgentKit is the skills layer when an LLM agent should discover endpoints and pay without you hard-coding every URL.

As of the @coinbase/agentkit npm package, the x402 actions are:

  • discover_x402_services: list available x402 services, optionally filtered by maximum USDC price.
  • make_http_request: plain HTTP call; on 402 it returns payment details for retry.
  • retry_http_request_with_x402: retry with payment after a 402.
  • make_http_request_with_x402: combine request and payment retry in one step.

Stablecoin Insider's rule of thumb: use make_http_request_with_x402 when the agent already knows the URL. Use discover_x402_services when the agent must find an endpoint under a USDC price cap first.

Pair discovery with spend controls before you let an agent roam a bazaar of paid APIs. See how to set spend limits on an AI agent USDC wallet.

How to Set Spend Limits on an AI Agent USDC Wallet

Buyer path comparison (as of Sep 12, 2026)

PathWho holds the walletBest forNetworks / notesCost / volume context
CdpX402Client + wrapFetchWithPaymentCDP-managed (server)Backend or agent that already knows the paid URLdevelopment = Base testnet; omit env for Base mainnet (buyer quickstart)You pay the resource price in USDC; no local private key file
AgentKit x402 actionsWallet provider wired into AgentKitLLM agents that discover and pay dynamicallydiscover_x402_services + make_http_request_with_x402 (npm @coinbase/agentkit)Same USDC settlement; add tool-level spend caps before open discovery
CDP Facilitator (seller-side)Seller resource server; Facilitator settlesMerchants verifying and settling inbound x402Base, Base Sepolia, Polygon, Arbitrum, World, World Sepolia, Solana, Solana Devnet>100M txs and $28M volume on Base+Solana alone; first 1,000 onchain Facilitator txs/mo free, then $0.001; OFAC/KYT screening (CDP network-support docs)
Embedded Wallets (buyer self-custody)End userBrowser/full-stack flows where users pay themselvesPer Coinbase buyer quickstart: use when users should pay from self-custodial walletsNot the CDP-managed server path in this guide

Facilitator volume and pricing come from Coinbase's CDP Facilitator / network-support docs. Those numbers describe Facilitator onchain activity, not your agent's first demo call.

If you are building the seller instead of the buyer, start with how to accept x402 USDC payments from AI agents and how to choose an x402 facilitator for USDC.

Guardrails and named downsides

Keys stay on the server. CDP_API_KEY_ID, CDP_API_KEY_SECRET, and CDP_WALLET_SECRET authenticate the managed wallet. Rotate them like any production secret, and never ship them to a browser agent.

Spend controls are mandatory. An agent with open discovery and no caps can burn USDC across many 402 endpoints. Wire session and per-tx limits before mainnet. Stablecoin Insider covers that in the spend-limits guide linked above.

Facilitator KYT can block. CDP's Facilitator docs state OFAC and Know Your Transaction checks decline payments involving sanctioned or high-risk addresses. A "works on testnet" flow can still fail settlement on mainnet after screening.

Testnet is not mainnet. environment: "development" is Base Sepolia. Omit it only after faucet testing, fee budgeting, and KYT expectations are written down.

Wrong path for end-user self-custody. Coinbase's buyer quickstart points teams that need users to pay from their own wallets to Embedded Wallets, not CdpX402Client on a shared server wallet.

Seller stacks differ. Stripe x402, Circle agent nanopayments, and Facilitator choice are separate playbooks: accept x402 on Stripe, Circle agent nanopayment in USDC, choose an x402 facilitator.

Stablecoin Insider's take

💡
Stablecoin Insider's take: start with CdpX402Client on Base Sepolia against https://x402.vercel.app/protected until you see HTTP 200, then graduate to AgentKit discovery only behind hard USDC spend limits. Treat Coinbase's Feb 2026 "over 50M" x402 claim and the Facilitator's >100M txs / $28M Base+Solana volume as proof the rails exist, not as a forecast of your agent's burn rate. Skip this path when end users must self-custody; use Embedded Wallets instead.

Seller-side accept from agents: how to accept x402 USDC payments from AI agents.

How to Accept x402 USDC Payments from AI Agents
How to Choose an x402 Facilitator for USDC (2026)
Compare facilitator options for verifying and settling inbound x402 USDC payments.

Stripe seller path: how to accept x402 USDC payments on Stripe.

How to Accept x402 USDC Payments on Stripe

Circle nanopayment buyer alternative: how to make a Circle agent nanopayment in USDC.

How to Make a Circle Agent Nanopayment in USDC

FAQ

How do I pay for an x402 API with Coinbase AgentKit or CdpX402Client?

Create a CdpX402Client (use environment: "development" for Base testnet), fund the printed evmAddress with Base Sepolia USDC, wrap fetch with wrapFetchWithPayment, and call the protected URL until you see HTTP 200.

What packages do I need for the Coinbase x402 buyer quickstart?

Install @coinbase/cdp-sdk, @x402/core, @x402/evm, @x402/svm, @x402/extensions, and @x402/fetch on Node.js 22+, with CDP_API_KEY_ID, CDP_API_KEY_SECRET, and CDP_WALLET_SECRET exported.

When should I use AgentKit x402 actions instead of CdpX402Client?

Use AgentKit when the agent should discover services and choose tools (discover_x402_services, make_http_request_with_x402). Use CdpX402Client when your backend already knows the paid endpoint.

What networks does the CDP Facilitator support for x402?

As of Coinbase's network-support docs: Base, Base Sepolia, Polygon, Arbitrum, World, World Sepolia, Solana, and Solana Devnet, with OFAC/KYT screening on Facilitator settlements.

How much does the CDP Facilitator cost?

The first 1,000 onchain Facilitator transactions each month are free; each additional onchain transaction costs $0.001. Payment verification is free; fees apply to onchain activity.

Should I use CdpX402Client if end users must self-custody?

No. Coinbase's buyer quickstart points those flows to Embedded Wallets. CdpX402Client is for CDP-managed server or agent wallets you operate.


Next step

Export the three CDP secrets, install the six packages on Node 22+, run CdpX402Client on development, faucet Base Sepolia USDC, and do not leave testnet until wrapFetchWithPayment returns HTTP 200 against the demo endpoint and your spend limits are written down.

Building the seller side instead of the buyer?

Accept x402 USDC from AI agents

This content is provided for informational and educational purposes only and does not constitute financial, investment, legal, or tax advice; no material herein should be interpreted as a recommendation, endorsement, or solicitation to buy or sell any financial instrument, and readers should conduct their own independent research or consult a qualified professional.

Latest

Ethena Brings USDe and sUSDe

Ethena Brings USDe and sUSDe to TRON

On September 11, 2026, Ethena Labs and TRON DAO said USDe and sUSDe are live on TRON via Stargate Finance for bridge, hold, and transfer, with JustLend DAO and SUN.io expected in coming weeks against >$94B USDT on TRON.

Members Public
MoneyGram Launches Stablecoin Visa Card in Colombia

MoneyGram Launches Stablecoin Visa Card in Colombia

MoneyGram launched the MoneyGram Card on September 10, 2026: a stablecoin-backed Visa card live first in Colombia on Rain, Crossmint, and Stellar, with USDC at launch, MGUSD planned later, and a physical card targeted for late 2026.

Members Public