DEV Community

Making a small API discoverable by AI agents: what worked, what did not

I run ChinaWire, a small paid API for Chinese web content. Getting it technically correct was the easy part; getting agents to find it was the hard part.

Here is what moved the needle, in order.

Make the unpaid call return a real 402

Not a 401, not a 403, not a JSON error. The x402 v2 shape that directories and agents actually parse:

  • HTTP/1.1 402 Payment Required
  • a base64 PAYMENT-REQUIRED header containing accepts[] with scheme: exact, network: eip155:8453, the USDC asset, payTo, and the amount in token atomic units
  • the same challenge in the body for older clients

Probes must reach the 402 before query/body validation rejects the request. If /v1/thing returns 422 without a parameter, a directory will mark it as broken.

Expose discovery surfaces

  • /openapi.json with x-payment-info per operation
  • /.well-known/x402 listing the paid resource URLs
  • /llms.txt - a plain-text map for agents
  • robots.txt that allows agent crawlers, and a sitemap.xml

These are cheap and they gave every crawler something to chew on.

Register where agents look

  • x402scan: registration needs a Sign-In-With-X wallet signature. Any EVM key works and needs no funds. One POST to /api/x402/registry/register-origin with the signed payload registered every route in my OpenAPI.
  • x402-list: a form/API submission; a real domain is free, while free-host and wildcard-DNS hostnames cost $1.
  • Bazaar: the gate is a real on-chain settlement. Conformance alone is not enough - this is the one I am still stuck on with a zero-balance wallet.

What did not work

  • A Cloudflare quick tunnel hostname: valid 402s, zero agent traffic.
  • A raw IP subdomain (sslip.io): directory crawlers treated it as a free host.
  • New-account Hacker News submissions: blocked with "your account isn't able to submit this site".

A normal domain behind Cloudflare, with Full (strict), was the switch that made crawlers start probing.

Small things that matter

  • Give a free sample: a 300-character preview endpoint converted curiosity into a real request in my logs.
  • Put the price in the 402 and on the landing page; agents compare automatically.
  • Log the PAYMENT-SIGNATURE header path separately so you can tell probes from payers.

If you are building an x402 service, the conformance checklist is the easy 20%. The other 80% is being in the places an agent already reads.

Example: https://api.seayeah.top/openapi.json

Discovery: https://api.seayeah.top/.well-known/x402

Source: https://github.com/seayeah12138-bit/wechat2md

Read on DEV Community ↗ ← Back to News

Comments

No comments yet. Start the discussion.