Text-to-Speech API Guide: Requests, Billing and Errors
How a text-to-speech API works, with ElevenLabs as the example: auth, requests, timestamps, streaming, per-character billing, errors. Our API is not open yet.
Listen to this article
AI narration · about 2 minRecorded when the post was published; prices and features follow the text above.

First, a note: our API isn't open yet; for bulk work or integration, email voicesmiths@163.com. You can create API keys in settings, but no endpoint accepts them today, so please don't build against them. What follows is how text-to-speech APIs work in general, using ElevenLabs (the provider behind VoiceSmiths) as the example, so you can evaluate and integrate any vendor.
1. Auth: a key in the request header
Mainstream TTS APIs authenticate with a key. With ElevenLabs, you create an API key in its console and send the header xi-api-key: <your key> with every request. Keep the key on your server, never in front-end code or an app bundle, and revoke and recreate it if it leaks.
2. Send a generation request
The basic ElevenLabs call is POST https://api.elevenlabs.io/v1/text-to-speech/{voice_id} with a body of:
text: what to readmodel_id: the model, e.g.eleven_v4,eleven_multilingual_v2,eleven_flash_v2_5voice_settings: optional,stability,similarity_boost,style,speedand so onseed: optional, fixes the randomness so a read can be reproduced
The response is the audio itself; the output_format query parameter picks the format (e.g. mp3_44100_128).
3. For subtitles, ask for timestamps
Call /v1/text-to-speech/{voice_id}/with-timestamps instead and you get base64 audio plus an alignment object: start and end seconds for every character. Group characters into sentences at punctuation and you can write an SRT directly, without running speech recognition afterwards. How to cut the cues is in the subtitle timing guide.
4. Stream for latency, chunk long text yourself
- Streaming: the
/streamendpoint returns audio chunks as they are generated, for voice assistants and anything that must start speaking fast. - Per-request limits: each model accepts a different number of characters per request (Eleven v4 takes 10,000, v3 takes 5,000). Past that you split the text yourself; pass
previous_text/next_text(orprevious_request_ids) so the intonation doesn't reset between chunks. - Pronunciation: brand names and terms can use pronunciation dictionaries (
pronunciation_dictionary_locators, up to 3 per request); see pronunciation dictionary. - Model trade-offs: expressiveness and audio tags versus speed and price, see choosing a model.
5. Billing: per character, not per call
TTS APIs almost all bill by character. On ElevenLabs a standard model costs about 1 credit per character and fast models like Flash / Turbo about half that. Whether failed requests are charged and what happens when the quota runs out differ by vendor, so read the docs before you integrate and handle the out-of-balance error in your code.
6. Common errors
| Symptom | Usual cause | Fix |
|---|---|---|
| 401 | Invalid or revoked key | Check the header, create a new key |
| 422 | Invalid parameters (empty text, wrong model ID) | Check the body against the docs |
| 429 | Concurrency or rate limit hit | Queue, throttle and retry |
| Quota exceeded | The account's character quota is used up | Top up, or use a cheaper model |
| Text too long | Over the model's per-request cap | Split it and pass context |
| Wrong accent | Voice doesn't match the language | Use a native voice per language, see multilingual accents |
No code: the VoiceSmiths workbench
VoiceSmiths is a web workbench for now: text to speech takes 5,000 characters per generation and long-form audiobook up to 50,000 per job, with MP3 and character-aligned SRT downloads, at 7 credits per 100 characters (4 on fast models); failed generations refund automatically. Our API isn't open yet; for bulk work or integration, email voicesmiths@163.com with your volume and use case.
Turn your own story into a drama like this
- Paste a chapter or script, up to 8,000 characters
- See the cast: a voice for every character, tap to hear it
- Render it: a 2,000-character episode is about 140 credits, so the trial pack ($29.90 for new users) covers about 21. You get an MP3 and line-timed subtitles