Text-to-speech
POST /api/ttsConvert text to speech with the eleven-v4-turbo model, priced per request from the length of the text. Send POST /api/tts with the required field text and pay quoted per request from $0.005 over x402 or MPP (there is no free tier). It returns a JSON object with model, provider, voice, format, audio and 1 more.
The quote is $0.005 plus $0.0575 per 1,000 characters of text, rounded up to the next $0.001 (2,000 characters: $0.120). Returns audio (the base64-encoded file in the format asked for: mp3, opus, aac, flac, wav or pcm) with model, voice, format and chars (the characters spoken). The ten standard voice names each map to their own voice, or name one of 21 named voices directly; the answer names the voice that spoke. 90+ languages. If the primary speech model is busy, throttling or down, a backup speech model with fewer voices and languages serves the call and the answer's model field names it. No API key needed; pay per call over x402 or MPP. Text capped at 2000 chars. Model-backed. For high-volume speech where timbre matters less, /api/tts-lite is the same interface on Kokoro-82M at $0.005.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
text | string | yes | Text to convert to speech (max 2000 chars) Also accepted as content, str, string, input, body, data. |
voice | string | no | Voice: alloy, ash, ballad, coral, echo, fable, nova, onyx, sage, shimmer (default: alloy), each mapped to its own voice, or a named voice (george, sarah, adam, alice, bella, bill, brian, callum, charlie, chris, daniel, eric, harry, jessica, laura, liam, lily, matilda, river, roger, will) |
format | string | no | Audio format: mp3, opus, aac, flac, wav, pcm (default: mp3) |
Example request
curl -i -X POST https://agent402.tools/api/tts \
-H "Content-Type: application/json" \
-d '{"text":"Hello from Agent402!","voice":"alloy","format":"mp3"}'
Without payment this returns HTTP 402 Payment Required with the exact price for tts; any x402 v2 or MPP client pays it and retries.
Example response
{
"model": "elevenlabs/eleven-v4-turbo",
"provider": "openrouter",
"voice": "river",
"format": "mp3",
"audio": "<base64-encoded audio>",
"chars": 20
}
| Field | Type | Always present | In the example |
|---|---|---|---|
model | string | yes | elevenlabs/eleven-v4-turbo |
provider | string | yes | openrouter |
voice | string | yes | river |
format | string | yes | mp3 |
audio | string | yes | <base64-encoded audio> |
chars | number | yes | 20 |
From an MCP client
catalog.call {
"slug": "tts",
"params": {
"text": "Hello from Agent402!",
"voice": "alloy",
"format": "mp3"
}
}
The hosted connector at https://agent402.tools/mcp needs a payment for tts; the stdio package pays it from a wallet or from an AGENT402_CREDITS_KEY issued earlier. Local install: npx -y [email protected].
Errors and behavior
textis required. An input the tool rejects returns an HTTP 4xx whose body carrieserror,tool,expected,requiredandexample, so the caller can correct it.- A paid call that ends in any status of 400 or above is not charged over x402, MPP or a prepaid credits key: settlement runs after the tool and only on a successful response. The exception is a Tempo push credential, a transfer the buyer sent before the call: it settles before the tool runs, so if the tool then fails the payment is recorded as a refund owed to the paying wallet.
- Wallet-only: this tool runs a model, so it has no proof-of-work tier. A prepaid card-credits key issued earlier (
Authorization: Bearer a402_...) also pays it. - Model-backed: the answer is generated by a model, so the same input can produce a different result.
- Sales tax: the price includes North Carolina sales tax for a buyer billed to a North Carolina address by card (a prepaid credits key or a card payment per call).
- Priced per request: the 402 quotes this body, between $0.005 and $0.12. The quote is $0.005 plus $0.0575 per 1,000 characters of text, rounded up to the next $0.001 (2,000 characters: $0.120).
- A
GETorHEADto /api/tts returns the same 402 quote, so the price can be read without a body. - An
Idempotency-Keyheader makes a retried paid call replay the first 200 instead of charging again (an answer larger than 1 MB is not replayed).
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.12" }); // refuse any quote above this tool's price
registerExactEvmScheme(client, { signer: privateKeyToAccount(KEY) });
const payFetch = wrapFetchWithPayment(fetch, client);
const res = await payFetch("https://agent402.tools/api/tts", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
"text": "Hello from Agent402!",
"voice": "alloy",
"format": "mp3"
}),
});
Related tools
Dub: translate and speak
POST /api/dubTranslate a text into a target language and speak the translation, in one paid call.
Text-to-speech (HD)
POST /api/tts-hdConvert text to speech with the eleven-v4 model, priced per request from the length of the text.
Text-to-speech (lite)
POST /api/tts-liteConvert text to speech with Kokoro-82M, a fraction of the price of /api/tts.
Text-to-speech (OpenAI-compatible)
POST /v1/audio/speechOpenAI-compatible text-to-speech over x402 - point any OpenAI SDK's audio.speech.create() at base_url.
Speech-to-text (Pro)
POST /api/transcribe-proTranscribe audio to text with the gpt-transcribe model - the same model as /api/transcribe with a longer cap.