Skip to content
All guides
API guide6 min readPublished Updated

Integrate the FasihTTS Arabic TTS REST API

A server-side HD integration guide: submit once with a saved idempotency key, poll the job, and download the MP3.

Submit once, poll, and download

Create an API key from the dashboard and call the API from trusted server code with a paid speech allowance. Never embed the key in a public browser bundle. Save a unique Idempotency-Key and the complete request before submitting. If the request is interrupted, retry only with that same key and identical input. Use a new key only for an intentional new generation.

POST https://xrwqtifhqycpxfjzfrip.supabase.co/functions/v1/generate-tts-v2
x-api-key: YOUR_API_KEY
Idempotency-Key: YOUR_SAVED_REQUEST_KEY
Content-Type: application/json

{
  "text": "مرحبًا بكم في فصيح",
  "dialect": "ar-msa",
  "voice": "ar-msa-formal-male-2"
}

202 {"jobId":"JOB_ID","status":"queued"}

POST https://xrwqtifhqycpxfjzfrip.supabase.co/functions/v1/get-long-tts-job
x-api-key: YOUR_API_KEY
Content-Type: application/json

{"id":"JOB_ID"}

200 {"job":{"status":"completed","audio_url":"SIGNED_MP3_URL"}}

GET SIGNED_MP3_URL
200 <MP3 audio>

Keep polling the existing job

The submit endpoint returns HTTP 202 with jobId. Save it and POST {id: jobId} to get-long-tts-job every 2–5 seconds. A queued or processing job is still running. Polling reads or resumes the existing job; do not resubmit generation while waiting. A failed job needs review before you choose whether to start another generation.

When job.status is completed, download job.audio_url as MP3. The signed URL is temporary; never send your API key to it. If the download fails, poll the same job for a fresh link while the audio is retained. If the audio has expired or no URL is returned, check the job rather than automatically creating another paid generation.

Validate before sending

  • Use /v1/dialects and /v1/voices as the public catalog instead of inventing IDs. Send HD voice IDs to generate-tts-v2, not the previous /v1/tts endpoint.
  • Confirm that the selected voice belongs to the selected dialect. Eight speakers across 16 dialects produce 128 public voice IDs, not 128 distinct speakers.
  • Reject empty text and enforce your own product-level length limits before the API call. Leave quotaUnit unset for automatic allowance selection unless you intentionally need a particular balance.

Errors, retries, and speech usage

Retry transient request failures with bounded backoff and the original key and input. After receiving jobId, resume polling that job. HTTP 409 idempotency_conflict means that key was reused with changed input; 403 quota_exceeded means insufficient allowance; 410 voice_retired means you must explicitly choose a replacement. Keep the request key and jobId in your server logs for support.

Failed speech generations do not use your speech allowance. Completed audio is charged according to the job's quota unit; existing character balances stay separate from audio-minute balances. Voice Design is a separate operation: design attempts count when submitted, including failed designs.

Previous voices: keep your existing integration

The previous /v1/tts endpoint and its synchronous base64 audioContent response are for eligible accounts using previous voice IDs during migration. That contract is not the onboarding path for new HD voices. Use the asynchronous workflow above for HD IDs and see the API documentation for downloadable Node.js and Python examples and the separate previous-voice reference.

POST https://api.fasihtts.com/v1/tts
x-api-key: YOUR_API_KEY
Content-Type: application/json

{"text":"مرحبًا بكم في فصيح","dialect":"ar-msa","voice":"ar-msa-formal-male-1"}

200 {"audioContent":"BASE64_AUDIO","format":"mp3"}