Dev.to AI 🤖 Ai 👁 0 📖 2 min read

Pay-per-call web tools for AI agents with x402 (USDC on Solana, no API key)

I put two small web utilities behind x402 — the HTTP 402 Payment Required protocol — so an AI agent can call them without an account or API key and pay a fraction of a cent per call in USDC on Solana. Base URL: https://

I put two small web utilities behind x402 — the HTTP 402 Payment Required protocol — so an AI agent can call them without an account or API key and pay a fraction of a cent per call in USDC on Solana.

Base URL: https://agent-tools.faling-bot.workers.dev

Endpoint Price What it does
POST /api/markdown $0.002 Fetch a public web page, return clean Markdown (title, main text, links)
POST /api/summarize $0.003 Bullet-point summary of {text} or a {url} (Llama 3.1 8B on Workers AI)

It runs on a Cloudflare Worker. Payments are verified and settled by the PayAI facilitator, which sponsors Solana gas, so the paying agent only needs USDC.

The flow

  1. Call the endpoint with no payment. You get 402 with a JSON body and a PAYMENT-REQUIRED header (base64 JSON, x402 v2) listing what's accepted: scheme: exact, network: solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp, the USDC mint, and the amount in atomic units (2000 = $0.002).
  2. Your x402 client signs a USDC transfer and retries with a PAYMENT-SIGNATURE header (v1 X-PAYMENT is accepted too).
  3. The server verifies the payment, does the work, settles, and returns 200 with the result. The settlement receipt is in PAYMENT-RESPONSE. If the input is invalid or the upstream page fails, the payment is not settled.
curl -i -X POST https://agent-tools.faling-bot.workers.dev/api/markdown \
  -H 'content-type: application/json' -d '{"url":"https://example.com"}'
# HTTP/2 402 + payment requirements

Paying from TypeScript

import { wrapFetchWithPaymentFromConfig } from "@x402/fetch";
import { ExactSvmScheme } from "@x402/svm/exact/client";
import { toClientSvmSigner } from "@x402/svm";
import { createKeyPairSignerFromBytes } from "@solana/kit";

const signer = await createKeyPairSignerFromBytes(secretKeyBytes); // a wallet holding a little USDC
const pay = wrapFetchWithPaymentFromConfig(fetch, {
  schemes: [{ network: "solana:*", client: new ExactSvmScheme(toClientSvmSigner(signer)) }],
});

const res = await pay("https://agent-tools.faling-bot.workers.dev/api/markdown", {
  method: "POST",
  headers: { "content-type": "application/json" },
  body: JSON.stringify({ url: "https://example.com" }),
});
console.log(await res.json()); // { url, title, markdown, chars, truncated }

As an MCP server

There's also a stateless streamable-HTTP MCP endpoint at https://agent-tools.faling-bot.workers.dev/mcp with tools url_to_markdown and summarize. It's listed in the official MCP Registry as dev.workers.faling-bot.agent-tools/x402-web-tools. A tool call without payment returns isError with the x402 requirements. To pay, pass the base64 payment payload as arguments.x402_payment, or as _meta["x402/payment"]. Not every MCP client can do this yet, so the plain HTTP endpoints are the more reliable option.

Machine-readable discovery

  • /llms.txt: a short guide for agents
  • /openapi.json: OpenAPI 3.1 with x-payment-info (it's indexed on x402scan)
  • /.well-known/x402: x402 resource list
  • /.well-known/agent.json: an A2A agent card

Limits and caveats

  • Rate limit: 30 requests/min per IP. The summarizer has a daily cap because it runs on a free-tier model.
  • The Markdown extractor is heuristic (main/article detection plus tag stripping). It doesn't execute JavaScript, so SPAs and pages behind logins return little.
  • This is a small, new, experimental service. Expect rough edges, and send feedback in the comments.

Written with AI assistance.

📰 Read the original article on Dev.to AI

Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.