Text-to-speech (OpenAI-compatible)
POST /v1/audio/speechAI-generated voice: tell listeners so.
Details
OpenAI-compatible text-to-speech over x402 - point any OpenAI SDK's audio.speech.create() at base_url https://agent402.tools/v1 and pay $0.06 per call in USDC, no API key, no signup. Served by Voxtral Mini TTS behind a five-model failover chain (xAI Grok Voice, Kokoro, MAI-Voice-2.1 Flash, MAI-Voice-2.1), every link proven by a real paid canary - a provider outage never becomes your failure. Up to 2,000 chars in, raw mp3 (default) or pcm bytes out - the same wire shape as OpenAI's endpoint. OpenAI voice names (alloy, nova, …) map per-model; native voice ids (e.g. en_paul_cheerful) work too. zdr:true routes only to zero-data-retention providers.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
input | string | yes | Text to speak (up to 2,000 chars) Also accepted as text, data, str, string, body, content. Up to 2000 characters. The example sends Agent402 serves 500+ tools, paid per call.. |
voice | string | no | OpenAI voice name - alloy (default), ash, ballad, coral, echo, fable, onyx, nova, sage, shimmer, verse - or a native voice id from GET /v1/models (e.g. en_paul_cheerful) The example sends alloy. |
response_format | string | no | "mp3" (default) or "pcm" |
model | string | no | Optional - pin a chain model (e.g. mistralai/voxtral-mini-tts-2603); the rest stay as fallbacks |
speed | number | no | Optional 0.25–4 playback speed (providers that don't support it ignore it) |
zdr | boolean | no | Optional - true routes only to zero-data-retention providers |
Example request
curl -i -X POST https://agent402.tools/v1/audio/speech \
-H "Content-Type: application/json" \
-d '{"input":"Agent402 serves 500+ tools, paid per call.","voice":"alloy"}'Watch a call get paid
POST /v1/audio/speech$0.06 USDCPAYMENT-SIGNATUREon 14 chains200 OKAgent402-ReceiptEd25519Example response
A 200 carries raw bytes, not JSON, with Content-Type audio/mpeg or audio/pcm: the file itself.
From an MCP client
catalog.call {
"slug": "v1-audio-speech",
"params": {
"input": "Agent402 serves 500+ tools, paid per call.",
"voice": "alloy"
}
}Hosted connector (https://agent402.tools/mcp): paid in the call. Stdio package (npx -y agent402-mcp@0.17.2): pays from a wallet or an AGENT402_CREDITS_KEY issued earlier.
Errors and behavior
- Pay $0.06 per call over x402 or MPP. Wallet-only, model-backed: no proof-of-work tier; the same input can give a different result. A card-credits key issued earlier (
Authorization: Bearer a402_...) also pays it. - Required:
input; a rejected input answers 4xx witherror,tool,expected,requiredandexample. - On this route, a call ending in any status of 400 or above is not charged over x402, MPP or a credits key. Some calls are paid before they run; a failed one can be retried free with the same payment, or is refunded. A Tempo push credential pays before the call; a failure is a refund owed.
- Sales tax: the price includes North Carolina sales tax for a card buyer billed to a North Carolina address.
- A bodyless
GETorHEADreturns the same 402 quote. - An
Idempotency-Keydoes not replay bytes: a retried paid call runs and is charged again.
Paid call (JavaScript agent)
import { wrapFetchWithPayment } from "@x402/fetch";
import { x402Client } from "@x402/core/client";
import { registerExactEvmScheme } from "@x402/evm/exact/client";
import { privateKeyToAccount } from "viem/accounts";
const client = new x402Client();
client.setSpendControls?.({ maxAmountPerPayment: "$0.06" }); // refuse any quote above this tool's price
registerExactEvmScheme(client, { signer: privateKeyToAccount(process.env.AGENT_KEY) });
const payFetch = wrapFetchWithPayment(fetch, client);
const res = await payFetch("https://agent402.tools/v1/audio/speech", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
"input": "Agent402 serves 500+ tools, paid per call.",
"voice": "alloy"
}),
});Get a wallet or run npx -y agent402-mcp@0.17.2 wallet new.
The quote (Python)
import base64, json, urllib.error, urllib.request
req = urllib.request.Request("https://agent402.tools/v1/audio/speech", method="POST", data="{\"input\":\"Agent402 serves 500+ tools, paid per call.\",\"voice\":\"alloy\"}".encode(), headers={"Content-Type": "application/json"})
try:
urllib.request.urlopen(req)
except urllib.error.HTTPError as e:
quote = json.loads(base64.b64decode(e.headers["PAYMENT-REQUIRED"]))
print(e.code, [(a["network"], a["amount"]) for a in quote["accepts"]]) # the price, per chain, in base units