AI API for agents — pay per call with x402
No account, no API key, no subscription. Call an endpoint, receive an HTTP 402 with the price, sign a USDC payment on Base with any x402 client and retry. You get the result; the money goes straight to one wallet. Built for autonomous agents and for developers who want to try pay-per-request AI.
Endpoints
| Method | Endpoint | Price (USDC) | What you get |
|---|---|---|---|
| POST | /v1/image | $0.02 | Text-to-image (SDXL-Lightning). JSON: prompt, orientation (square | phone | desktop). Returns a base64 image (JPEG or PNG, see mimeType). |
| POST | /v1/translate | $0.003 | Neural machine translation (M2M100), 15+ languages. JSON: text (≤ 2000 chars), to (pt, en, es, fr, de…), optional from. |
| POST | /v1/prompt | $0.005 | Turns an idea into 5 optimized text-to-image prompts. JSON: idea, optional style. |
| POST | /v1/tts | $0.01 | Text-to-speech (MeloTTS) in English, Spanish, French, Chinese, Japanese or Korean. JSON: text (≤ 600 chars), lang (en, es, fr, zh, jp, kr). Returns a base64 WAV (16-bit PCM, 44.1 kHz). |
| POST | /v1/embed | $0.001 | Multilingual embeddings (BGE-M3, 1024 dimensions). JSON: texts (up to 16 strings). |
| POST | /v1/summarize | $0.004 | Summary of a text (80–12000 chars) as bullets, a paragraph or a TL;DR. JSON: text, format, max_words. |
| POST | /v1/transcribe | $0.01 | Speech-to-text (Whisper large-v3-turbo) for short clips. JSON: audio (base64 WAV/MP3/FLAC, ≤ ~1.5 MB; a 30 s WAV at 16 kHz is ~1 MB), optional language. |
| GET | /v1/pack/latest | $0.99 | PromptVault Pro Pack: pro prompts with variations and example outputs (JSON, or ?format=md for Markdown). |
Quickstart (JavaScript)
npm i @x402/fetch @x402/evm viem
import { x402Client, wrapFetchWithPayment } from "@x402/fetch";
import { ExactEvmScheme } from "@x402/evm/exact/client";
import { privateKeyToAccount } from "viem/accounts";
const signer = privateKeyToAccount(process.env.PRIVATE_KEY); // a wallet holding a little USDC on Base
const client = new x402Client().register("eip155:*", new ExactEvmScheme(signer));
const pay = wrapFetchWithPayment(fetch, client); // handles the 402 → sign → retry for you
const res = await pay("https://autopilot-studio.kariguetoazul.workers.dev/v1/translate", {
method: "POST", headers: { "content-type": "application/json" },
body: JSON.stringify({ text: "Good morning, how can I help you?", to: "pt" }),
});
console.log(await res.json()); // { translated_text: "...", from: "en", to: "pt" }
What the 402 looks like
curl -i -X POST https://autopilot-studio.kariguetoazul.workers.dev/v1/translate -H 'content-type: application/json' -d '{"text":"Good morning","to":"pt"}'
# HTTP/2 402
# PAYMENT-REQUIRED: <base64 JSON> → x402 v2 · scheme "exact" · network eip155:8453 (Base) · asset USDC · amount "3000" · payTo 0x13dd72Fa0E7504790585D92bD98c720f6fD2aBa6
Guides for builders
- How an AI Agent Pays an x402 API: a 20-Line Client in JS
- How to Add x402 Payments to a Cloudflare Worker with Hono
- How to List Your x402 API on 402 Index, x402scan and Bazaar
- Workers AI Free Tier: What Each API Call Really Costs in Neurons
- All the guides as an open dataset (CC BY 4.0): Hugging Face
Good to know
- Cap your agent's spending:
client.setSpendControls({ maxAmountPerPayment: "$0.05" }). The default cap in@x402/fetchis $1 per payment. - Network and asset: Base (
eip155:8453), USDC (6 decimals). Payments use EIP-3009 signatures, so the payer needs no ETH for gas: the facilitator (PayAI) submits the transfer. - You are charged only for a successful response. Invalid requests (bad JSON, unsupported language…) return 400 before anything is settled.
- Machine-readable docs: /openapi.json · /.well-known/x402 · /v1/pricing · /llms.txt.
- Receiving wallet:
0x13dd72Fa0E7504790585D92bD98c720f6fD2aBa6(check it on Basescan). - Humans: you can also buy the Pro Pack with a normal USDC transfer, no code needed.