<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Jia Jian Goi</title>
    <description>The latest articles on DEV Community by Jia Jian Goi (@gjj).</description>
    <link>https://dev.to/gjj</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F415197%2Fdbbe2aaf-3b6c-4f1a-86db-8eab6863c0ea.jpeg</url>
      <title>DEV Community: Jia Jian Goi</title>
      <link>https://dev.to/gjj</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/gjj"/>
    <language>en</language>
    <item>
      <title>Building payment-native AI agents with aixyz and x402</title>
      <dc:creator>Jia Jian Goi</dc:creator>
      <pubDate>Wed, 04 Mar 2026 06:06:28 +0000</pubDate>
      <link>https://dev.to/gjj/building-payment-native-ai-agents-with-aixyz-and-x402-44jm</link>
      <guid>https://dev.to/gjj/building-payment-native-ai-agents-with-aixyz-and-x402-44jm</guid>
      <description>&lt;p&gt;Everyone's building AI agents. But almost nobody's figured out how agents get paid.&lt;/p&gt;

&lt;p&gt;Think about it: you build a weather agent, a flight search agent, a code review agent. You want to expose it to other developers or other AI systems. What's the business model? API keys with monthly caps? Stripe subscriptions? Bearer tokens?&lt;/p&gt;

&lt;p&gt;These all require accounts, signups, billing infrastructure. They work fine for humans. They're terrible for agent-to-agent communication.&lt;/p&gt;

&lt;h2&gt;
  
  
  The problem with paying for AI services today
&lt;/h2&gt;

&lt;p&gt;When an AI agent needs to call another service, it typically:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Needs a pre-registered API key&lt;/li&gt;
&lt;li&gt;Pays in bulk (subscription or credits)&lt;/li&gt;
&lt;li&gt;Can't dynamically discover new services&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This works when a human sets everything up in advance. It breaks down when agents need to autonomously discover and pay for services on the fly. Imagine your orchestrator agent finds a better translation service mid-task — it can't just &lt;em&gt;use&lt;/em&gt; it. Someone has to sign up, add a credit card, generate a key, and redeploy. That's a human bottleneck in what's supposed to be an autonomous system.&lt;/p&gt;

&lt;h2&gt;
  
  
  HTTP 402 — the forgotten status code
&lt;/h2&gt;

&lt;p&gt;There's a status code that's been "reserved for future use" since 1991: &lt;strong&gt;402 Payment Required&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;For 30+ years, nobody agreed on what it should actually do. The &lt;a href="https://www.x402.org/" rel="noopener noreferrer"&gt;x402 protocol&lt;/a&gt; is one attempt to finally define it. The idea: a server returns a 402 with payment details (amount, token, chain), the client pays with a cryptographic header, and retries the original request. No accounts. No subscriptions. Pay per request, verified on-chain.&lt;/p&gt;

&lt;p&gt;The flow looks like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Agent A → GET /api/translate → 402 {price: $0.005, payTo: 0x...}
Agent A → signs USDC payment → retries with X-PAYMENT header
Server  → verifies on-chain → 200 {translation: "..."}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It's stateless and composable. Exactly the properties that made HTTP itself successful.&lt;/p&gt;

&lt;h2&gt;
  
  
  The emerging stack
&lt;/h2&gt;

&lt;p&gt;x402 creates a viable payment rail for AI agents, but agents also need identity and discovery. A few complementary protocols are converging:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://eips.ethereum.org/EIPS/eip-8004" rel="noopener noreferrer"&gt;ERC-8004&lt;/a&gt;&lt;/strong&gt; — a proposed standard for on-chain agent identity. Think of it as ENS for agents: a way to verify &lt;em&gt;who&lt;/em&gt; you're paying and &lt;em&gt;who&lt;/em&gt; is calling you, without a centralized registry.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://google.github.io/A2A/" rel="noopener noreferrer"&gt;A2A&lt;/a&gt;&lt;/strong&gt; — Google's Agent-to-Agent protocol. Agents publish a card at &lt;code&gt;/.well-known/agent-card.json&lt;/code&gt; describing their capabilities, and communicate via JSON-RPC. It's basically a service mesh for AI.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://modelcontextprotocol.io/" rel="noopener noreferrer"&gt;MCP&lt;/a&gt;&lt;/strong&gt; — Anthropic's Model Context Protocol. While A2A handles agent-to-agent, MCP handles tool sharing with AI clients like Claude Desktop and Cursor.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;None of these require each other, but they compose well. An agent can be discoverable via A2A, expose tools via MCP, and gate access via x402, all at once.&lt;/p&gt;

&lt;h2&gt;
  
  
  What the developer experience looks like
&lt;/h2&gt;

&lt;p&gt;To make this concrete, here's roughly what a payment-gated agent looks like using &lt;a href="https://github.com/AgentlyHQ/aixyz" rel="noopener noreferrer"&gt;&lt;code&gt;aixyz&lt;/code&gt;&lt;/a&gt;, an open-source framework that wires these protocols together:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;bunx create-aixyz-app my-agent
&lt;span class="nb"&gt;cd &lt;/span&gt;my-agent
bun &lt;span class="nb"&gt;install
&lt;/span&gt;bun run dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Your agent is already running with three endpoints:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;/.well-known/agent-card.json&lt;/code&gt; — A2A discovery&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;/agent&lt;/code&gt; — JSON-RPC with x402 payment gate&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;/mcp&lt;/code&gt; — MCP tool sharing (works with Claude Desktop, Cursor, etc.)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now define your agent and set a price in &lt;code&gt;app/agent.ts&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Define your agent's pricing&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;accepts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;scheme&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;exact&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;price&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;$0.005&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="c1"&gt;// per request, settled in USDC on Base&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="c1"&gt;// Define your agent&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ToolLoopAgent&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;model&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;openai&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;gpt-4o-mini&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
  &lt;span class="na"&gt;instructions&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;You are a helpful weather assistant.&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;tools&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;weather&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This gives you three endpoints out of the box: an A2A agent card for discovery, a JSON-RPC endpoint with x402 gating, and an MCP endpoint for tool sharing.&lt;/p&gt;

&lt;p&gt;On the caller side, any agent (or human with a CLI) that speaks x402 can call this without prior registration. The payment handshake is just part of the HTTP exchange.&lt;/p&gt;

&lt;h2&gt;
  
  
  The honest tradeoffs
&lt;/h2&gt;

&lt;p&gt;This approach isn't without friction, and it's worth being upfront about the downsides:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;On-chain settlement adds latency.&lt;/strong&gt; Even on L2s like Base, you're adding a verification step that a simple API key check doesn't need. For latency-sensitive pipelines, this matters. Optimistic verification and payment channels can help, but they add complexity.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Crypto is a hard sell for many developers.&lt;/strong&gt; Plenty of teams building agents have zero interest in wallets, USDC, or anything blockchain-adjacent. Stripe is &lt;a href="https://docs.stripe.com/agents" rel="noopener noreferrer"&gt;actively exploring agent billing&lt;/a&gt; with a more traditional model — OAuth-based, fiat-native, and already integrated with their existing merchant base. For teams already in the Stripe ecosystem, that path has much lower friction.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Micropayment economics are tricky.&lt;/strong&gt; At $0.005 per request, gas fees need to be negligible or batched. Base and other L2s help here, but "negligible" is relative — if your agent makes thousands of calls per minute, even small per-transaction overhead compounds.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Discovery is still early.&lt;/strong&gt; The A2A ecosystem is small. There's no mature marketplace where you can browse hundreds of agents with reputation scores and usage metrics. We're closer to "here are some repos on GitHub" than "here's an app store."&lt;/p&gt;

&lt;h2&gt;
  
  
  Where this is heading
&lt;/h2&gt;

&lt;p&gt;The interesting thing isn't any one protocol. It's that the &lt;em&gt;shape&lt;/em&gt; of the stack is becoming clear. Agents need:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Identity&lt;/strong&gt; — verifiable, not just an API key&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Discovery&lt;/strong&gt; — dynamic, not hardcoded URLs&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Payment&lt;/strong&gt; — per-request, not pre-negotiated&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Communication&lt;/strong&gt; — structured, not bespoke REST endpoints&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Whether the winning stack is x402 + ERC-8004 + A2A, or Stripe + OAuth + some future discovery protocol, or something else entirely — the problem is real and the design space is narrowing.&lt;/p&gt;

&lt;p&gt;If you're building agents today and thinking about how they'll eventually pay and get paid, these are the protocols worth tracking:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.x402.org/" rel="noopener noreferrer"&gt;x402 spec&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://eips.ethereum.org/EIPS/eip-8004" rel="noopener noreferrer"&gt;ERC-8004 proposal&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://google.github.io/A2A/" rel="noopener noreferrer"&gt;Google A2A&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/AgentlyHQ/aixyz" rel="noopener noreferrer"&gt;aixyz&lt;/a&gt; (open-source framework implementing this stack)&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://docs.stripe.com/agents" rel="noopener noreferrer"&gt;Stripe Agent Toolkit&lt;/a&gt; (the fiat-native alternative)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Disclaimer: I'm a contributor to &lt;a href="https://github.com/AgentlyHQ/aixyz" rel="noopener noreferrer"&gt;aixyz&lt;/a&gt; and &lt;a href="https://use-agently.com" rel="noopener noreferrer"&gt;use-agently&lt;/a&gt;. I've tried to present the landscape fairly, including alternatives like Stripe's agent toolkit, but you should know where I sit.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>agents</category>
    </item>
  </channel>
</rss>
