Estimate Cost
Get the price of a voice-over before you generate it, free of charge
curl -X POST https://api.voice213.com/api/v1/tts/estimate \
-H "Authorization: Bearer $VOICE213_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"text": "(نبرة تساؤل وتشويق) ملّيتو من الساعات اللي تتبدل بعد شهر؟ (نبرة واثقة وهادئة) الساعة الكلاسيكية تاعنا مقاومة للماء وبسوار جلدي أصلي. (نبرة عاجلة وحاسمة) كومونديو دركا، العرض ما يدومش!",
"model": "voice213-pro-2"
}'import os
import requests
API = "https://api.voice213.com/api/v1"
HEADERS = {"Authorization": f"Bearer {os.environ['VOICE213_API_KEY']}"}
script = (
"(نبرة تساؤل وتشويق) ملّيتو من الساعات اللي تتبدل بعد شهر؟ "
"(نبرة واثقة وهادئة) الساعة الكلاسيكية تاعنا مقاومة للماء وبسوار جلدي أصلي. "
"(نبرة عاجلة وحاسمة) كومونديو دركا، العرض ما يدومش!"
)
# The same script, priced on three models
for model in ["voice213-lite", "voice213-pro", "voice213-pro-2"]:
quote = requests.post(
f"{API}/tts/estimate",
headers=HEADERS,
json={"text": script, "model": model},
timeout=30,
).json()
print(model, quote["billableChars"], quote["cost"], quote["enough"])const response = await fetch("https://api.voice213.com/api/v1/tts/estimate", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.VOICE213_API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
text: "(نبرة تساؤل وتشويق) ملّيتو من الساعات اللي تتبدل بعد شهر؟ (نبرة واثقة وهادئة) الساعة الكلاسيكية تاعنا مقاومة للماء وبسوار جلدي أصلي. (نبرة عاجلة وحاسمة) كومونديو دركا، العرض ما يدومش!",
model: "voice213-pro-2",
}),
});
const quote = await response.json();
if (!quote.enough) console.log(`Top up first: this voice-over costs ${quote.cost} DA`);{
"success": true,
"model": "voice213-pro-2",
"chars": 123,
"billableChars": 123,
"pricePer1MChars": 12000,
"cost": 1.476,
"currency": "DZD",
"balance": 5000,
"enough": true
}{
"success": true,
"model": "voice213-lite",
"chars": 22,
"billableChars": 100,
"pricePer1MChars": 9000,
"cost": 0.9,
"currency": "DZD",
"balance": 0.35,
"enough": false
}{
"error": "Max 5000 words exceeded",
"words": 5214,
"maxWords": 5000
}{
"error": "TEXT_TOO_LONG",
"message": "Too much of the text isn't spoken: tone directions, punctuation and invisible characters can't be more than about the spoken text itself. Remove them or split the text.",
"chars": 1842,
"maxChars": 1300
}{
"error": "UNKNOWN_MODEL",
"message": "Unknown model 'voice213-ultra'. Use one of: voice213-lite, voice213-lite-2, voice213-pro, voice213-pro-1.5, voice213-pro-2 (see GET /v1/models).",
"models": ["voice213-lite", "voice213-lite-2", "voice213-pro", "voice213-pro-1.5", "voice213-pro-2"]
}Returns what a voice-over would cost, without generating it: the characters Voice213 would bill, the model's price and the total in dinars, with your API credit and whether it's enough. It's free, and it doesn't count toward your rate limits.
Send the same text and model you would send to Text to Speech. The estimate counts characters exactly as the voice-over does, so the cost it returns is the cost you'll be charged at the same price. It also refuses the texts a voice-over would refuse, with the same 400: a text over 5,000 words, one with nothing to speak, or one where too much isn't spoken (TEXT_TOO_LONG).
Use it to:
- Show a price to your own users before they confirm a voice-over.
- Check a long script against your balance before you send it.
- Compare models on your real script: send the same text with each
model(the Python example does this).
Authorizations
Your API key as a Bearer token: Bearer sk_live_.... You can send it in an x-api-key header instead. See Authentication.
Body
application/jsonThe script you want to price, up to 5,000 words, tone directions included, as for a voice-over. A tone direction in parentheses isn't billed when it's at most 100 characters long, parentheses included, so it doesn't count; a longer one is priced like the rest of the text. A text longer than twice its billable characters plus 1,000, every character counted, is refused with 400 TEXT_TOO_LONG, as a voice-over would be.
voice213-liteThe model to price it with: voice213-lite, voice213-lite-2, voice213-pro, voice213-pro-1.5 or voice213-pro-2, as in Text to Speech. An unknown model is refused with 400 UNKNOWN_MODEL. The older quality values work too. A model paused for the API is still priced, although a voice-over with it gets 503 MODEL_DISABLED for now.
Response
application/jsontrue.
The model the price is for, such as voice213-pro-2.
The characters of text, without its free tone directions (those of up to 100 characters) and with runs of spaces counted once.
The characters that would be billed: chars, or 100 when chars is lower.
The model's price today, in dinars per million characters.
What the voice-over would cost, in dinars: billableChars × pricePer1MChars ÷ 1,000,000, rounded to four decimals.
DZD.
Your API credit right now, in dinars, rounded to the centime.
true when your API credit covers cost, by the same rule a voice-over uses. When it's false, the voice-over would fail with 402: top up first. It doesn't subtract what your running voice-overs have set aside: with others running, a voice-over can still get 402 when this says true. enough compares your exact balance, so rely on it rather than comparing balance with cost.
Errors
| Status | Error | When |
|---|---|---|
400 | text is required | The body has no text, or only spaces. |
400 | EMPTY_TEXT | text has nothing to speak, such as a text made only of tone directions. |
400 | Max 5000 words exceeded | text is over 5,000 words, tone directions included. The body has words and maxWords. |
400 | TEXT_TOO_LONG | text is longer than twice its billable characters plus 1,000: too much of it is tone directions, spaces or invisible characters. The body has chars and maxChars. |
400 | UNKNOWN_MODEL | model isn't one of the five models. The body lists the models you can use. |
401 | Missing API key. Pass it as 'Authorization: Bearer sk_live_...' | The request has no key. |
401 | Invalid or inactive API key | The key is wrong, switched off or deleted. |
403 | Account deactivated | The account that owns the key is deactivated or suspended. |
403 | API_ACCESS_BLOCKED (in code) | API access is switched off for the account. |
503 | MAINTENANCE (in code) | The API is down for maintenance. Retry later. |
An estimate never returns 402: when your credit is short, it says so with enough: false.
Was this page helpful?