<?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: Éric</title>
    <description>The latest articles on DEV Community by Éric (@xynaptic).</description>
    <link>https://dev.to/xynaptic</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4192261%2F22256658-50b4-4728-8caf-ea9a17d2502c.jpg</url>
      <title>DEV Community: Éric</title>
      <link>https://dev.to/xynaptic</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/xynaptic"/>
    <language>en</language>
    <item>
      <title>🤖💸 How an AI Agent Pays for an API Without an API Key (x402 in Practice)</title>
      <dc:creator>Éric</dc:creator>
      <pubDate>Sun, 18 Oct 2026 15:01:27 +0000</pubDate>
      <link>https://dev.to/xynaptic/how-an-ai-agent-pays-for-an-api-without-an-api-key-x402-in-practice-8fl</link>
      <guid>https://dev.to/xynaptic/how-an-ai-agent-pays-for-an-api-without-an-api-key-x402-in-practice-8fl</guid>
      <description>&lt;p&gt;Every API on the internet still works like it's 2010: a human signs up, gets a key, wires a monthly subscription, and pastes the key into a config file. 🔑&lt;/p&gt;

&lt;p&gt;That works when the customer is a developer. It breaks completely when the &lt;strong&gt;customer is an autonomous agent&lt;/strong&gt;. An agent cannot create an account, accept terms of service, or enter a credit card for a $0.02 data call. 🤷&lt;/p&gt;

&lt;p&gt;This post walks through, step by step, how the x402 protocol fixes it — using a live catalog (I run &lt;a href="https://xynaptic.io" rel="noopener noreferrer"&gt;xynaptic.io&lt;/a&gt;, 200+ pay-per-call endpoints) so you can reproduce every command. ✅&lt;/p&gt;

&lt;h2&gt;
  
  
  🚪 Step 1: The request
&lt;/h2&gt;

&lt;p&gt;bash&lt;br&gt;
curl -i &lt;a href="https://api.xynaptic.io/v1/crypto-price" rel="noopener noreferrer"&gt;https://api.xynaptic.io/v1/crypto-price&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;No key, no auth header, no account. What comes back? 👀&lt;/p&gt;

&lt;h2&gt;
  
  
  💰 Step 2: The 402 challenge
&lt;/h2&gt;

&lt;p&gt;http&lt;br&gt;
HTTP/1.1 402 Payment Required&lt;br&gt;
X-PAYMENT: version=2, chain=base, max-total=10000 (0.01 USDC),&lt;br&gt;
  pay-to=0x4ff893...a4D5e9, resource="crypto-price"&lt;/p&gt;

&lt;p&gt;HTTP 402 (Payment Required) has existed since 1998 and nobody used it. 🕰️ x402 turns it into a &lt;strong&gt;machine-readable price tag&lt;/strong&gt;: the price, the receiving address, and the network — all stated &lt;em&gt;before&lt;/em&gt; payment, so an agent can compare providers and budget itself. 🏷️&lt;/p&gt;

&lt;p&gt;No login wall. No "contact sales". Just a price. ⚡&lt;/p&gt;

&lt;h2&gt;
  
  
  🔄 Step 3: The agent pays
&lt;/h2&gt;

&lt;p&gt;The agent's x402 client builds a USDC transfer for the exact amount on the stated chain (Base, Polygon or Solana here), then &lt;strong&gt;retries the same request with the payment proof attached&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;bash&lt;br&gt;
curl &lt;a href="https://api.xynaptic.io/v1/crypto-price" rel="noopener noreferrer"&gt;https://api.xynaptic.io/v1/crypto-price&lt;/a&gt; \&lt;br&gt;
  -H "X-PAYMENT: "&lt;/p&gt;

&lt;p&gt;The server verifies the payment on-chain, settles it, and returns the data. On xynaptic.io every response is also &lt;strong&gt;signed with Ed25519&lt;/strong&gt;, and every proof is auditable at &lt;code&gt;api.xynaptic.io/trust&lt;/code&gt;. 🔏&lt;/p&gt;

&lt;h2&gt;
  
  
  🧭 The full flow
&lt;/h2&gt;

&lt;p&gt;GET request → 402 challenge (price, payTo, network)&lt;br&gt;
           → on-chain USDC transfer&lt;br&gt;
           → retry with proof&lt;br&gt;
           → 200 + your data (signed)&lt;/p&gt;

&lt;p&gt;Three properties worth noting: 👇&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;💸 &lt;strong&gt;Pay per call, not per month.&lt;/strong&gt; An agent that makes one $0.01 call pays one cent. No tiers, no minimums, no end-of-month invoice.&lt;/li&gt;
&lt;li&gt;🔐 &lt;strong&gt;Nothing to leak.&lt;/strong&gt; No API keys to rotate, no secrets to scrape from a &lt;code&gt;.env&lt;/code&gt; file pushed to GitHub.&lt;/li&gt;
&lt;li&gt;🧩 &lt;strong&gt;It composes.&lt;/strong&gt; An agent with a wallet can buy data, storage, watch jobs, even skills — machine-to-machine, no human in the loop.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  🧪 Try it yourself
&lt;/h2&gt;

&lt;p&gt;The cheapest way to see it is one curl:&lt;/p&gt;

&lt;p&gt;bash&lt;br&gt;
curl -i &lt;a href="https://api.xynaptic.io/v1/crypto-price" rel="noopener noreferrer"&gt;https://api.xynaptic.io/v1/crypto-price&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You will get a 402. That's not an error — it's a price tag. 😉&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;📚 Full catalog + docs: &lt;a href="https://xynaptic.io/docs" rel="noopener noreferrer"&gt;xynaptic.io/docs&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;🔌 MCP server: &lt;code&gt;mcp.xynaptic.io/mcp&lt;/code&gt; (npm client: &lt;code&gt;xynaptic-mcp&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;🐙 Open catalog on GitHub: &lt;a href="https://github.com/ericchengech/xynaptic-catalog" rel="noopener noreferrer"&gt;github.com/ericchengech/xynaptic-catalog&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;📖 Protocol reference: &lt;a href="https://x402.org" rel="noopener noreferrer"&gt;x402.org&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;📖 &lt;a href="https://xynaptic.io/blog" rel="noopener noreferrer"&gt;https://xynaptic.io/blog&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you build agents: is the 402 → pay → retry flow understandable enough? What data domains would you want next? I read every comment. 💬👇&lt;/p&gt;

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