Use case

Python text-to-speech API

Call POST https://api.sayitapi.com/v1/tts with the requests library, read audio_url from the JSON response, and download the MP3. No SDK is required.

Quick start with requests

Install requests, export your API key as SAYIT_API_KEY, and send it in the SAYIT-API-KEY header. Keys issued by SayIt start with sk_live_. There is no separate sandbox key.

bash
pip install requests
export SAYIT_API_KEY="YOUR_API_KEY"

POST to https://api.sayitapi.com/v1/tts with text, voice_id, and language. The character balance is reduced by text.length.

python
import os
import requests

res = requests.post(
    "https://api.sayitapi.com/v1/tts",
    headers={"SAYIT-API-KEY": os.environ["SAYIT_API_KEY"]},
    json={
        "text": "Hello from Python.",
        "voice_id": "eve",
        "language": "en",
        "output_format": "mp3",
        "speed": 1,
    },
)
res.raise_for_status()
data = res.json()

with requests.get(data["audio_url"]) as audio:
    audio.raise_for_status()
    with open("hello.mp3", "wb") as f:
        f.write(audio.content)

print(data["characters_used"], data["duration_seconds"])

A completed response includes id, audio_url, characters_used, duration_seconds, voice_id, and created_at. When text is translated, translated and source_language are added. The signed audio_url expires after 24 hours, so download the MP3 as shown above if you need to keep it.

Besides those fields, the body accepts output_format (mp3 or wav), speed (0.5 to 2.0; the engine applies 0.7 to 1.5 and clamps values outside that range), sample_rate (8000, 16000, 22050, or 44100; default 22050), and speech_tags (boolean, with tags written inline in the text).

Choosing a voice and language

Set voice_id to eve, ara, rex, sal, or leo; the default is eve. See the voices page for samples.

language defaults to auto, which speaks the text as written, and also accepts one of 57 language codes. SayIt translates into 57 languages with native voice support for 20+, and the request body is unchanged. Plain es, pt, and ar map to es-ES, pt-BR, and ar-SA after translation; any other accepted code is sent to the speech engine as auto.

python
import os
import requests

res = requests.post(
    "https://api.sayitapi.com/v1/tts",
    headers={"SAYIT-API-KEY": os.environ["SAYIT_API_KEY"]},
    json={"text": "Your order has shipped.", "voice_id": "rex", "language": "es"},
)
res.raise_for_status()
data = res.json()
print(data.get("translated"), data.get("source_language"))

Chunking long text in Python

The documented per-request text limit is 250 characters on demo keys, 1,000 on free keys, and 10,000 on paid keys. GET /v1/account returns the limit as max_text_length, so read it at runtime instead of hardcoding it. This simple whitespace splitter keeps each request at or below that limit:

python
import os
import requests

API_KEY = os.environ["SAYIT_API_KEY"]

account = requests.get(
    "https://api.sayitapi.com/v1/account",
    headers={"SAYIT-API-KEY": API_KEY},
)
account.raise_for_status()
limit = account.json()["max_text_length"]


def split_text(text, limit):
    chunk = ""
    for word in text.split():
        while len(word) > limit:
            if chunk:
                yield chunk
                chunk = ""
            yield word[:limit]
            word = word[limit:]
        candidate = (chunk + " " + word).strip()
        if len(candidate) > limit:
            yield chunk
            chunk = word
        else:
            chunk = candidate
    if chunk:
        yield chunk


long_text = "Paste a long article here."
for piece in split_text(long_text, limit):
    res = requests.post(
        "https://api.sayitapi.com/v1/tts",
        headers={"SAYIT-API-KEY": API_KEY},
        json={"text": piece, "voice_id": "eve", "language": "en"},
    )
    res.raise_for_status()
    print(res.json()["audio_url"])

Each piece is a separate synthesis request and is billed by its own text.length. Text longer than the plan allows is rejected with text_too_long.

Batch requests

POST /v1/tts/batch is for paid keys only. The batch size is 50, and the body is { "requests": [ { "text": "..." } ] }. The balance is reserved up front and failed items are refunded. The response is { "results": [...], "total": n }. Free and demo keys receive plan_required.

python
import os
import requests

res = requests.post(
    "https://api.sayitapi.com/v1/tts/batch",
    headers={"SAYIT-API-KEY": os.environ["SAYIT_API_KEY"]},
    json={"requests": [{"text": "First clip."}, {"text": "Second clip."}]},
)
res.raise_for_status()
batch = res.json()
print(batch["total"])
print(batch["results"])

tts.complete webhooks fire for POST /v1/tts only, not for batch items. Paid keys can register HTTPS webhook URLs; private and loopback hosts are rejected, and events include tts.complete, usage.alert_80, and usage.alert_100.

Errors, quota, and retries

Errors use { "error": { "code", "message" } }; param is not returned. Retry only 429 and 5xx responses. A 429 includes a Retry-After header and retry_after in the body. Do not retry 400, 401, 402, or 403; fix the request, key, balance, or plan instead.

CodeHTTPWhen
invalid_request400Missing fields, bad pack, bad URL, speed, or format.
invalid_voice400voice_id is not eve, ara, rex, sal, or leo.
invalid_language400language is not in the supported set.
text_too_long400text is longer than the plan allows.
invalid_api_key401Missing or unknown key, or a revoked / expired rotated key.
quota_exceeded402Character balance is too low for this request.
plan_required403Batch, webhooks, or CSV export need a paid key.
not_found404Unknown webhook, payment, or route.
rate_limit_exceeded429Per-key or auth rate limit. See Retry-After.
server_error500Synthesis, storage, or email send failed. Retry.

quota_exceeded (402) means the character balance is too low for the request, and the balance does not reset monthly. Read chars_balance and chars_used from GET /v1/account before large jobs. Per-key rate limits are counted in a rolling one-minute window.

python
import os
import time
import requests

API_KEY = os.environ["SAYIT_API_KEY"]


def post_tts(payload, attempts=5):
    for attempt in range(attempts):
        res = requests.post(
            "https://api.sayitapi.com/v1/tts",
            headers={"SAYIT-API-KEY": API_KEY},
            json=payload,
        )

        # Retry only 429 and 5xx responses.
        if res.status_code == 429 or res.status_code >= 500:
            if attempt == attempts - 1:
                res.raise_for_status()
            retry_after = res.headers.get("Retry-After")
            try:
                wait = float(retry_after) if retry_after else 2 ** attempt
            except ValueError:
                wait = 2 ** attempt
            time.sleep(wait)
            continue

        res.raise_for_status()
        return res.json()


data = post_tts({"text": "Hello from Python.", "voice_id": "eve", "language": "en"})
print(data["audio_url"])

Async variant with httpx

httpx is an optional dependency, installed separately from requests. The endpoint, headers, and JSON body are the same.

bash
pip install httpx
python
import asyncio
import os
import httpx

API_KEY = os.environ["SAYIT_API_KEY"]


async def synthesize(text):
    async with httpx.AsyncClient() as client:
        res = await client.post(
            "https://api.sayitapi.com/v1/tts",
            headers={"SAYIT-API-KEY": API_KEY},
            json={"text": text, "voice_id": "eve", "language": "en"},
        )
        res.raise_for_status()
        return res.json()


async def main():
    data = await synthesize("Hello from async Python.")
    print(data["audio_url"])


asyncio.run(main())

FAQ

Do I need a Python SDK?

No. There is no official pip package; the examples use requests against the REST endpoint. The SAYIT-API-KEY header authenticates every /v1 route except the payment webhooks and GET /v1/payments/config.

What is the maximum text per request?

Demo keys allow 250 characters, free keys 1,000, and paid keys 10,000. GET /v1/account returns the value as max_text_length; split longer text into chunks or use the batch endpoint.

Which voices and languages can I use?

Five voices: eve, ara, rex, sal, and leo. Set language to auto or a supported code; translation covers 57 languages, with native voice support for 20+.

How long is the audio URL available?

The signed audio_url expires after 24 hours, and generated audio is deleted after 24 hours. GET /v1/history returns requests from the last 24 hours, 10 per page, and replay uses audio_url until it expires.

Python quick start

import os, requests

res = requests.post(
    "https://api.sayitapi.com/v1/tts",
    headers={"SAYIT-API-KEY": os.environ["SAYIT_API_KEY"]},
    json={"text": "Hello from Python.", "voice_id": "eve", "language": "en"},
)
print(res.json()["audio_url"])

Powered by Grok TTS. Generated audio is deleted after 24 hours.

Live playground105 / 250
1.00×

API accepts 0.5–2.0. The speech engine applies 0.7–1.5.

curl -X POST https://api.sayitapi.com/v1/tts \
  -H "SAYIT-API-KEY: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"text":"Hello! This is SayIt. <emphasis>Important words</emphasis> stand out, and a pause [pause] sounds natural.","voice_id":"eve","language":"en","output_format":"mp3","speech_tags":true,"speed":1}'

Live demo uses a server-side key, limited to 250 characters. Audio expires after 24 hours.