// April 7, 2026 · Max

How AI Agents Discover and Pay for APIs with x402

I've been building a discovery API for AI agents that need to find and pay for services on their own. Here's what I've learned about x402 and why I think discovery is the missing piece.

x402ai-agentsapi-discovery

I’ve been thinking a lot about what happens when AI agents need to do things on their own. Not just generate text, but actually call APIs, pay for services, and get real data back. The “autonomous agent” pitch sounds great until you realise that right now, a developer has to manually find every API, sign up for accounts, manage keys, set up billing, and hardcode URLs. If something goes down, the developer has to step in.

That’s what got me started on EntRoute. It’s a side project, a discovery API that helps agents find and pay for the APIs they need without a human in the loop.

The problem I kept running into

I kept hitting the same wall. Say an agent needs to get the current price of ETH. Sounds simple, right? But the agent needs to:

  1. Know that a “token price” API exists somewhere
  2. Find one that’s actually working right now
  3. Figure out how much it costs
  4. Pay for the call
  5. Parse the response

Steps 2-4 are where everything falls apart. There’s no standardised way for an agent to discover what’s out there, check if it’s working, compare prices, or make a payment. All at runtime, without bothering a human.

x402 solves payments, but not discovery

The x402 protocol is genuinely clever. It uses the HTTP 402 status code that’s been reserved since the 90s but never really used. The flow is dead simple:

# Agent calls an API endpoint
curl https://api.example.com/v1/token-price?symbol=ETH

# Server responds with 402 Payment Required
# Headers tell you exactly what to pay:
#   X-Payment-Network: base
#   X-Payment-Asset: USDC
#   X-Payment-Amount: 0.001
#   X-Payment-Address: 0x...

The agent sees the 402, sends a payment (USDC on Base), and retries with proof. No API keys. No accounts. No billing dashboards. Just HTTP the way it was meant to work.

x402 solves the payment side beautifully. What it doesn’t solve is discovery. An agent still has no idea which endpoints exist or where to find them.

So I built a discovery layer

That’s what EntRoute does. It’s basically DNS for paid APIs. You tell it what you need, either with a capability ID or plain English, and it gives you back a ranked list of verified endpoints.

# Ask EntRoute: "I need a token price API"
curl -X POST https://api.entroute.com/discover 
  -H "Content-Type: application/json" 
  -d '{"intent": "get the current price of ETH"}'
{
  "resolved": {
    "capability_id": "defi.token_price",
    "confidence": 0.95
  },
  "ranked_endpoints": [
    {
      "provider_name": "TokenAPI",
      "url": "https://api.tokenapi.com/v1/price",
      "method": "GET",
      "score": 0.87,
      "payment": {
        "type": "x402",
        "price_per_call": 0.001,
        "network": "base",
        "accepted_assets": ["USDC"]
      },
      "observed": {
        "success_rate_7d": 0.98,
        "p95_latency_ms": 150
      }
    }
  ]
}

Every endpoint in that list has been probed. I run automated checks every 10 minutes to make sure they actually return a proper 402 response and accept payments. If something goes down or starts misbehaving, it drops in the rankings or gets pulled entirely.

What the full flow looks like

Here’s the bit I find satisfying. The complete loop from “I need data” to “I have data” with no human intervention:

import { EntRouteClient } from '@entroute/sdk-agent-ts';

const client = new EntRouteClient({
  baseUrl: 'https://api.entroute.com'
});

// 1. Discover: find the best endpoint for what you need
const result = await client.discover({
  intent: 'get ETH token price',
  constraints: { max_price: 0.01 }
});

const endpoint = result.ranked_endpoints[0];
console.log(`Using ${endpoint.provider_name} at ${endpoint.url}`);
console.log(`Price: $${endpoint.payment.price_per_call} per call`);

// 2. Call the endpoint (agent handles 402 → pay → retry)
const response = await fetch(endpoint.url);
// ... handle x402 payment flow

Or if you’re using Claude, it’s even simpler. I built an MCP server so you can just add it and start asking questions:

claude mcp add entroute -- npx @entroute/mcp-server

Then you just ask Claude something like “Find me an API that returns the current ETH price” and it does the discovery, shows you the pricing, and gives you working code. That moment when it actually works end-to-end is pretty satisfying.

Why I bothered with ranking

Early on I realised that just returning a list of endpoints isn’t enough. Some are slow, some are overpriced, some go down every other day. So I built a ranking system that scores every endpoint across four dimensions:

Factor Weight (default) What it measures
Success rate 45% Does it actually return valid responses?
Latency 25% How fast is it? (p95)
Price 20% How much per call?
Stability 10% Is it consistent over time?

You can adjust these weights depending on what matters. A trading bot probably cares about speed. A research agent probably cares about cost. I’ve set up presets like reliability, speed, and budget so you don’t have to think about it.

Where things stand

Right now EntRoute indexes 362 endpoints across 110 capabilities from 166 providers. Most of those come from the Coinbase Bazaar. I wrote an automated sync that pulls new endpoints, maps them to capabilities, and queues them for verification. It runs every night.

It’s still early days and there’s a lot to figure out. The payment bridge needs work, the verification could be smarter, and I’m sure the ranking weights will need tuning as real usage data comes in. But the core loop works: discover, rank, verify, serve.

If you’re building something with AI agents and you’re tired of hardcoding API URLs, I’d genuinely like to know if this is useful to you. Give it a try and let me know what breaks.

Get started: Quick Start Guide | Browse Capabilities | SDK Reference

// about the author
M

Building EntRoute, a side project exploring how AI agents will discover and pay for APIs in the x402 economy. Indie dev, building in public.

// try it yourself

Add EntRoute to Claude in one command:

$ claude mcp add entroute -- npx @entroute/mcp-server