Best x402 and AP2 Tools for AI Agent Payments: x402 SDK Picks for 2026
The x402 SDKs and AP2 projects worth building on in 2026, with stars, licences and setup from each README, plus x402 vs AP2 in one table.
If you want to charge per API call or let an AI agent pay for one, start with the official x402 SDK from the x402 Foundation (TypeScript, Python and Go). Add x402-rs if you work in Rust, Solana Foundation's pay if you want an agent to pay from a local wallet, and Google's A2A x402 extension if agents are paying other agents. If your agent buys things with a card on a person's behalf, the official AP2 repository is the reference, with AP2 Conformance to check your mandate code against it and Lucid Agents if you want a runtime that does both.
The two protocols answer different questions. x402 moves the money inside an HTTP request. AP2 proves what a person allowed the agent to buy. Here is the split, then the picks.
Protocol facts below were checked on 12 November 2026 against x402.org, the x402 repository, ap2-protocol.org and the AP2 repository. Nothing here is financial advice, and this post does not recommend buying any token or cryptocurrency.
x402 vs AP2 at a glance
| x402 protocol | AP2 (Agent Payments Protocol) | |
|---|---|---|
| What it is | An open standard that puts payment inside HTTP. A server answers 402 Payment Required, the client pays and retries | An open protocol for agent commerce built on signed mandates that record what a user authorised |
| Who runs it | The x402 Foundation, hosted by the Linux Foundation. Coinbase contributed the protocol; the operational launch was announced on 14 July 2026 | Created by Google, which is donating it to the FIDO Alliance (announced 28 April 2026). Standards work continues in FIDO working groups |
| Payment rails | Stablecoins are the primary use case. The FAQ on x402.org lists all EVM-compatible chains and Solana, and says it is extensible to traditional payment methods | The current version supports "pull" methods such as credit and debit cards. E-wallets, real-time bank transfers (UPI, PIX) and digital currencies are on the roadmap, per ap2-protocol.org |
| Fees | x402.org says zero protocol fees; payment network fees still apply | Not defined by the protocol; set by the card networks and processors involved |
| Status | x402.org's FAQ describes it as production-ready (the project's own claim) | v0.2 released, still evolving |
| Fits on top of | Any HTTP server or client, plus an MCP package and an A2A extension | An extension for A2A and MCP, and usable with the Universal Commerce Protocol |
| Pick it when | You sell an API, data or inference per request | An agent shops for a person and the merchant needs proof of consent |
You will see both in the same system. Google's own A2A x402 extension links to AP2 from its README, and the AP2 site lists samples "using the x402 protocol for payments". Several comparison pages call them complementary, and that matches the primary sources: AP2 handles authorisation, x402 handles settlement over HTTP.
How AI agents pay with x402, step by step
This is the core flow from the x402 README, shortened:
- The client requests a resource.
- The server replies
402 Payment Requiredwith aPAYMENT-REQUIREDheader listing what it accepts. - The client picks one option, builds a payment payload and retries with a
PAYMENT-SIGNATUREheader. - The server checks the payload, itself or through a facilitator's
/verifyendpoint. - The server does the work, settles (directly or through the facilitator's
/settle), and returns200 OKwith aPAYMENT-RESPONSEheader.
There is no account, no API key and no stored card on the client side. The README lists three payment schemes: exact (a fixed price), upto (a cap, with the seller charging actual usage) and batch-settlement (many small charges settled together on EVM chains).
The picks, compared
Stars were read from the GitHub REST API as of 12 November 2026. AgenticMart lists these from public GitHub data and has not scanned them.
| Project | Protocol | Language | Official or community | Stars (12 Nov 2026) | Licence | AgenticMart page |
|---|---|---|---|---|---|---|
| x402 | x402 | TypeScript, Python, Go | Official (x402 Foundation) | 6,797 | Apache-2.0 | x402 |
| AP2 | AP2 | Python (samples also in Go, Android) | Official (Google) | 3,269 | Apache-2.0 | AP2 |
| pay | x402 (and MPP) | Rust | Solana Foundation | 1,804 | MIT | pay |
| A2A x402 Extension | x402 over A2A | Python | Google, community extension | 572 | Apache-2.0 | a2a-x402 |
| x402-rs | x402 | Rust | Community | 293 | Apache-2.0 | x402-rs |
| Lucid Agents | x402 and AP2 metadata | TypeScript | Community (Daydreams) | 202 | MIT | Lucid Agents |
| AP2 Conformance | AP2 | Python | Community | 2 | Apache-2.0 | AP2 Conformance |
Stars show attention, not quality. The small conformance suite is on the list because nothing else on it does that job.
1. x402 (official SDK): the default x402 SDK
Best for: turning any HTTP endpoint into a pay per request API, or giving a client the ability to pay one.
This is the reference specification and SDK. One thing many guides still get wrong: the repository moved. coinbase/x402 now says it is a development fork, and the main repository is x402-foundation/x402. Install from the packages that repository points to.
The TypeScript side is split into small packages: core, chain support (@x402/evm, @x402/svm and others), server middleware (@x402/express, @x402/hono, @x402/next, @x402/fastify), client wrappers (@x402/fetch, @x402/axios) and @x402/mcp for MCP servers. Python and Go have their own packages.
Quoted from the docs, not run for this post:
# Minimal express server
npm install @x402/core @x402/evm @x402/svm @x402/express
# Python
pip install x402
# Go
go get github.com/x402-foundation/x402/go/v2
The @x402/express README shows a full route. This excerpt is quoted from it, not run for this post:
app.use(
paymentMiddleware(
{
"GET /protected-route": {
accepts: [
{ scheme: "exact", price: "$0.10", network: "eip155:84532", payTo: "0xYourEvmAddress" },
],
description: "Access to premium content",
},
},
resourceServer,
),
);
eip155:84532 in that example is a test network. The README is direct about production: do not assume the public x402.org facilitator is your mainnet path. Pick a production facilitator for your network, run your own, or settle inside your server.
2. AP2 (official): the reference for agent payments protocol mandates
Best for: agents that buy from merchants on a user's behalf, where card networks and merchants need a signed record of consent.
AP2's core objects are mandates, which are verifiable digital credentials. In v0.2 the two named on ap2-protocol.org are the Checkout Mandate (the negotiated items, shared with the merchant) and the Payment Mandate (authorisation against a specific payment instrument, shared with the credential provider, networks and processor). Each can be open or closed. If a guide still lists Intent, Cart and Payment mandates, it describes v0.1, which v0.2 replaced. Google's announcement says v0.2 added "Human Not Present" payments, where an agent pays later based on instructions the user approved earlier.
The repository holds the spec, a Python SDK, and scenarios in Python, Go and Android. Its samples use Google's ADK and Gemini, though the README says AP2 requires neither. As of 12 November 2026 the GitHub API shows its last push on 17 June 2026.
Quoted from the docs, not run for this post. The README says a PyPI package will come later, so install from Git:
uv pip install git+https://github.com/google-agentic-commerce/AP2.git@main
To run the human-present card sample (needs a Google API key or Vertex AI, set as the README describes):
bash code/samples/python/scenarios/a2a/human-present/cards/run.sh
3. pay (Solana Foundation): let an agent pay without handing it a key
Best for: developers who want Claude Code, Codex or a script to call paid APIs from a local wallet, with spending limits.
pay wraps a command. When the API returns 402, it detects the protocol (x402 or MPP), prepares the stablecoin transaction, asks your wallet to sign, and retries. It also ships an MCP server, a local payment debugger, and a gateway mode for charging for your own endpoints. The pay mcp permissions (allowed origins, networks, a maximum payment) are what make it worth a look for unattended agents.
Quoted from the docs, not run for this post:
npm install -g @solana/pay
pay setup
pay --sandbox curl https://debugger.pay.sh/mpp/quote/AAPL
pay mcp --allow-origin https://api.example.com --allow-network mainnet --max-payment '$1.00'
4. A2A x402 Extension: agents charging other agents
Best for: A2A agents that sell a service to other agents.
The A2A x402 extension maps the 402 idea onto A2A messages: payment-required, payment-submitted, payment-completed. The Python library lets a merchant agent raise an exception or use a decorator when a request needs payment. This excerpt is quoted from its Python README, not run for this post:
@require_payment(price="$2.00", pay_to_address="0x456...", resource="/ai-service")
async def generate_content(prompt):
return ai_service.generate(prompt)
The spec in the repository is v0.1. If your agents speak A2A, read our A2A protocol page for the base protocol.
5. x402-rs: x402 in Rust, including your own facilitator
Best for: Rust services, and teams that want to run their own facilitator.
x402-rs splits the work into crates: x402-axum to protect routes, x402-reqwest for paying clients, chain crates for EVM and Solana (Aptos from Git), and a facilitator server shipped as a Docker image. It supports x402 V1 and V2. Server excerpt, quoted from the docs, not run for this post:
let x402 = X402Middleware::new("http://facilitator.example.com");
let app = Router::new().route(
"/paid-content",
get(handler).layer(
x402.with_price_tag(V2Eip155Exact::price_tag(
address!("0xYourAddress"),
USDC::base_sepolia().amount(10u64),
))
),
);
6. Lucid Agents: one runtime for paid agent services
Best for: a TypeScript service with several typed, paid capabilities rather than one paid route.
Lucid Agents turns typed functions into services agents can discover, call and pay for. Its feature table lists an x402 payments package (EVM and Solana seller checks, EVM buying) and an ap2 package for AP2 role metadata in discovery. Note the README says AP2 v0.1 metadata, while AP2 itself is now at v0.2. The README is honest about scope: for a single paid route, the upstream x402 middleware may be the smaller dependency.
Quoted from the docs, not run for this post:
bunx @lucid-agents/cli@2.5.0 my-agent --adapter=hono --template=blank
cd my-agent
bun install
bun run dev
7. AP2 Conformance: check your mandate code against the reference
Best for: anyone writing their own AP2 verifier in any language.
AP2 Conformance is a set of test vectors for v0.2 mandates, generated from AP2's own reference SDK at a pinned commit, plus a runner. It separates "core" cases (where you must match the reference) from optional "hardening" cases. Its README states plainly that it is not an official AP2 or FIDO certification. Quoted from the docs, not run for this post:
npm run conformance
How we picked
- Source list. We started from AgenticMart's x402 and AP2 lists, built from public GitHub data and last checked on 8 November 2026, then refreshed stars and licences from the GitHub API on 12 November 2026.
- One job each. Each pick covers a different job: charge for an endpoint, pay from an agent, agent-to-agent payment, a non-JavaScript stack, a full runtime, or conformance testing.
- Official first. Both official repositories are on the list.
- Clear licence, not a fork, still pushed in 2026. We skipped repositories whose GitHub licence field shows no recognised licence, forks such as
coinbase/x402, and starter kits. - Payments as the main job. Some popular repositories use x402 as one feature inside a larger tool, such as an LLM router. They are on the x402 page but not here.
What we did not do: we did not run, scan or audit any of these projects for this post. Read each one's code and permissions before connecting it to a wallet or a card. On AgenticMart listing pages, the "What it can touch" label is a good place to start.
Before you take money with x402 or AP2
- Price it first. Per-request pricing changes how people use an API. Our guide to pricing AI agents and MCP servers covers per-call, subscription and usage models.
- Decide your facilitator for x402. The test facilitator is for test networks. Production needs a facilitator that supports your network, or your own.
- Know who holds the risk. x402 settles on-chain, and x402.org lists chargebacks as a problem of the old way, so plan refunds yourself. AP2 uses card rails, where networks and processors handle disputes.
- Check the rules where you operate. Taking stablecoin or card payments can carry tax and licensing duties. Ask someone qualified.
FAQ
What is the x402 protocol?
x402 is an open standard for payments over HTTP using the 402 Payment Required status code. A server states its price in a 402 response, the client pays and retries, and the server returns the resource. It is now run by the x402 Foundation at the Linux Foundation.
x402 vs AP2: which should I use?
Use x402 if you are selling an API, data or inference per request and are happy to accept stablecoins. Use AP2 if an agent buys from merchants on a person's behalf and you need a signed record of what the person approved, today mainly with cards. Some systems use both: AP2 for consent, x402 for settlement.
How do AI agents pay for APIs?
With x402, the agent's HTTP client sees a 402 response, signs a payment from a wallet it is allowed to use, and retries the request with a payment header. Tools such as pay add limits on origins, networks and amounts so the agent cannot overspend. With AP2, the agent presents mandates the user signed, and payment runs through existing card networks.
How do I build a pay per request API?
Add x402 middleware to your server, list the routes and prices, and point it at a facilitator. The official SDK has middleware for Express, Hono, Next.js and Fastify, Python and Go packages, and an MCP package. Test on a test network before you switch to a production facilitator.
Is there an official x402 SDK for Python or Go?
Yes. The official repository lists pip install x402 for Python and go get github.com/x402-foundation/x402/go/v2 for Go, alongside the TypeScript packages. Community SDKs exist for Rust and other languages.
Does AgenticMart process x402 or AP2 payments?
No. AgenticMart does not process payments today. It lists open-source agent payment projects so you can compare them, and paid selling on the marketplace has not opened yet.
Built an x402 or AP2 tool?
If you maintain a payments SDK, facilitator, paid MCP server or agent that pays its way, developers comparing options should be able to find it. On AgenticMart you can list free now, paid selling opens soon. Submit your project, browse every protocol on the protocols page, or read how selling on AgenticMart will work.
Browse agents, MCP servers and skills on AgenticMart, see what each can touch, and explore the newest standards on our agent protocol map. List yours free now, paid selling opens soon.