API documentation
IndexTTS2 API quickstart
Monthly Pro includes 100 minutes per month ($14.99/month). Yearly Pro includes 180 minutes per month ($149.99/year). Website and IndexTTS2 API share the same minutes. V1 supports Chinese and English. Unused minutes expire monthly.
Integrate using AI
Copy the instructions into your AI coding assistant. The complete API reference is available as Markdown.
Choose how to provide reference audio
Use a remote audio URL
Recommended for backend integrations: send JSON with an HTTPS audio URL. No need to download the audio and upload it again.
// Node.js 20+ — server-side only
import { randomUUID } from 'node:crypto';
import { writeFile } from 'node:fs/promises';
const api = 'https://indextts.online';
const headers = { Authorization: 'Bearer ' + process.env.INDEXTTS_API_KEY };
const idempotencyKey = randomUUID(); // Save this for network retries
const response = await fetch(api + '/api/v1/tts', {
method: 'POST',
headers: { ...headers, 'Content-Type': 'application/json',
'Idempotency-Key': idempotencyKey },
body: JSON.stringify({
text: '你好,欢迎使用 IndexTTS2。',
reference_audio_url: 'https://cdn.example.com/voice.wav', // Replace with your public WAV URL
emotion: 'natural',
}),
});
const job = await response.json();
if (!response.ok && !(response.status === 503 &&
job.code === 'PROVIDER_STATUS_UNKNOWN' && job.id)) {
throw new Error(JSON.stringify(job));
}
if (!job.id) throw new Error('No task ID returned');
const taskId = job.id; // Persist for recovery after restarts
let downloaded = false;
for (let attempt = 0; attempt < 90; attempt++) {
await new Promise(resolve => setTimeout(resolve, 4000));
const poll = await fetch(api + '/api/v1/tts/' + taskId, { headers });
if (!poll.ok) throw new Error(await poll.text());
const task = await poll.json();
if (task.status === 'succeeded') {
const audio = await fetch(task.audio_url);
if (!audio.ok) throw new Error('Could not download generated audio');
await writeFile('output.wav', Buffer.from(await audio.arrayBuffer()));
downloaded = true;
break;
}
if (['failed', 'canceled'].includes(task.status))
throw new Error(JSON.stringify(task));
}
if (!downloaded) throw new Error('Still processing: poll existing taskId later');Authentication
Create an API Key in your Pro account. Send it as Authorization: Bearer YOUR_API_KEY on every request. Keep the full Key on your server; it appears only once.
1. Create a speech task
Choose a direct HTTPS reference_audio_url (JSON, recommended) or upload a local 3–30 second 16-bit PCM WAV (multipart; 16–48 kHz, 2 MiB total). For uploads, prefer mono 16 kHz. Keep the same Idempotency-Key and payload when retrying uncertain network requests.
Request fields
Send application/json with text, a public HTTPS reference_audio_url and optional emotion (natural, happy, sad, angry, calm). Alternatively, use multipart/form-data with text, a reference_audio WAV file (3–30 seconds, 16-bit PCM, 16–48 kHz, total body <= 2 MiB) and optional emotion. Provide exactly one audio source. IndexTTS2 accepts Chinese and English text only.
Use only your own voice or a reference voice you have permission to use.
2. Check task status and usage
Poll every 3–5 seconds until the task succeeds or fails. On success, download the audio using the temporary private audio_url. Successful generations count toward your shared minutes, with a 3-second minimum per task.
Minutes and downloads
Get /api/v1/usage to check your shared balance and billing period. A successful task counts at least 3 seconds; failed or canceled tasks do not consume successful audio minutes. The signed audio_url expires; poll the same successful task again for a new download link.
Retries and errors
Use a new UUID for each new task. When a network request is uncertain, retry with the same Idempotency-Key and identical input. If you receive PROVIDER_STATUS_UNKNOWN with a task ID, poll that ID; do not submit another prediction. HTTP 401 means invalid Key, 403 requires Pro, 409 means conflict or another task running, and 429 means rate/usage limit.