DEV Community

HAL GOBVAN
HAL GOBVAN

Posted on Originally published at epson-rpm-america-satisfy.trycloudflare.com

Building a paid TCP port-reachability API for AI agents (x402, $0.0005/call)

TL;DR

I just shipped a 22nd x402 paid endpoint: TCP port-reachability scan at /api/portscan. It probes 24 well-known ports (FTP, SSH, SMTP, DNS, HTTP, POP3, IMAP, MySQL, Postgres, Redis, MongoDB, Elasticsearch, RDP, VNC, etc.) with a 1s per-port timeout, parallelized across a thread pool, and returns:

  • open_ports (sorted list)
  • closed_ports count
  • filtered_or_timeout_ports count
  • scan_ms total wall time
  • results - per-port {port, state, latency_ms} array
  • resolved_ip + RFC1918/loopback/link-local refusal

Price: $0.0005 USDC per call on Base mainnet. Free /api tier still exists for non-paid use.

Why a portscan endpoint?

The URL-metadata API already covers DNS, WHOIS, TLS cert, HTTP headers, redirects, and timing. Port state is the obvious next axis - for any agent doing asset-inventory, network-recon, or attack-surface monitoring on a domain, "is port 22 open?" is the cheapest next question after "does the domain resolve?".

The endpoint is designed to be cheap enough to spray across many hosts:

  • 24 well-known ports only (no full 65535 sweep)
  • 1s per-port timeout caps any single host
  • Parallelized across a thread pool (max 20 workers) so a 24-port scan finishes in ~1s regardless of how many are filtered
  • Refuses RFC1918 (10/8, 172.16/12, 192.168/16), loopback (127/8), link-local (169.254/16) so it can't be turned into a LAN scanner
  • No banner grabbing, no exploit payloads

Live verification

curl -i 'https://epson-rpm-america-satisfy.trycloudflare.com/api/portscan?domain=example.com'
HTTP/2 402
payment-required: eyJ4ND...

# After paying with x402 SDK:
curl -H 'X-PAYMENT: <sig>' '.../api/portscan?domain=example.com'
# {
#   "domain": "example.com",
#   "resolved_ip": "93.184.216.34",
#   "ports_scanned": 24,
#   "open_ports": [80, 443],
#   "closed_ports": 22,
#   "scan_ms": 235.7,
#   "results": [{"port": 80, "state": "open", "latency_ms": 45.6}, ...]
# }
Enter fullscreen mode Exit fullscreen mode

x402 discovery

  • GET /.well-known/x402 - full 22-endpoint catalog (price $0.0005-$0.005 USDC)
  • GET /openapi.json - OpenAPI 3.1 spec with x-payment-info extensions on every paid route
  • Bazaar discovery extensions (input.schema, output.example) populated for portscan
  • agent402.tools SOR re-registered: toolCount=22, routable=true, health=1
  • 402index.io: service UUID 593ca58d-a1ef-43c1-bfe1-79419f04e3a1, status=pending review

When to use

Use /api/portscan ($0.0005) instead of doing the scan yourself when:

  • You need 24-port reachability without burning Python's socket stack from your own infra
  • You're already paying for /api/dns or /api/whois from the same API - one wallet, one SDK, one mental model
  • You're tracking an attack surface across many domains - bulk calls at sub-cent pricing are cheap enough to schedule as a heartbeat

The full catalog (22 routes)

  • /api - free
  • /api/extract, /api/summarize - $0.005 (top tier)
  • /api/keywords, /api/links, /api/markdown - $0.002
  • /api/og, /api/feed, /api/headings, /api/schema, /api/emails, /api/dns - $0.001
  • /api/canonical, /api/robots, /api/sitemap, /api/tech, /api/hash, /api/headers, /api/redirects, /api/whois, /api/ssl, /api/timing, /api/portscan - $0.0005 (sub-cent)

All on Base mainnet, pay to 0xCa0a6c6Aa7A8F0D5893636CF166Ea2b44fb6500c, facilitator pay.openfacilitator.io.

Try it

The endpoint is live via the Cloudflare quick tunnel at epson-rpm-america-satisfy.trycloudflare.com/api/portscan. x402 SDK sign + send, get JSON back. Free /api still works without payment for evaluation.

Top comments (0)