# IndexTTS2 Developer API V1

Base URL: https://indextts.online

## Plans

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. Unused minutes expire at the end of the cycle.
The API supports IndexTTS2 only (Chinese/English text, reference WAV voice cloning and emotion presets). No IndexTTS 2.5, language selection, speed control, streaming, batch mode or callbacks.
API success normally costs generated audio seconds with a minimum of 3 seconds per job. A last job may be capped at the remaining quota. Failed and canceled jobs do not consume successful audio minutes.

## Authentication

Sign in and subscribe to Pro at https://indextts.online/pricing, then create your Key at https://indextts.online/account/api. Full Key is shown once; store it in server-side environment variable INDEXTTS_API_KEY.
All API requests need: Authorization: Bearer YOUR_API_KEY

## POST /api/v1/tts

Headers: Authorization: Bearer YOUR_API_KEY; Idempotency-Key: a UUID unique to each logical task. Reuse the same UUID AND identical payload on uncertain network retries.
Input options: reference_audio (file upload), or reference_audio_url (public HTTPS URL). Choose exactly one. URL input is forwarded to the inference provider directly, not copied into IndexTTS storage. A publicly reachable HTTPS URL without authentication cookies is required; no IP literal, private/local hostname, URL credentials or fragments. Prefer a stable WAV file. URL validity, media type and duration are not pre-verified when using direct URL passthrough; if upstream cannot fetch or decode it, the task fails.
For URL inputs, POST application/json: {"text":"Hello", "reference_audio_url":"https://cdn.example.com/voice.wav", "emotion":"natural"}. JSON body <= 16KiB. Multipart also accepts reference_audio_url as an alternative to reference_audio. The cdn.example.com URL is a placeholder: replace it with a public HTTPS audio URL that remains valid while the model fetches it.

### Recommended: URL input (Node.js 20+)
~~~javascript
import {randomUUID} from "node:crypto";
const api = "https://indextts.online";
const headers = {Authorization:"Bearer " + process.env.INDEXTTS_API_KEY};
const response = await fetch(api+"/api/v1/tts", {
  method:"POST", headers:{...headers, "Content-Type":"application/json", "Idempotency-Key":randomUUID()},
  body:JSON.stringify({text:"Hello from IndexTTS2", reference_audio_url:"https://cdn.example.com/voice.wav", emotion:"natural"})
});
const task = await response.json();
if (!response.ok && !(response.status === 503 && task.code === "PROVIDER_STATUS_UNKNOWN" && task.id)) throw Error(JSON.stringify(task));
// Store task.id, poll GET /api/v1/tts/{id} until succeeded/failed/canceled.
// If succeeded, download task audio_url. Always reuse the same UUID for ambiguous POST retries.
~~~

### File upload (WAV)
Content-Type: multipart/form-data with:
- text: required, 1–1000 Unicode characters
- reference_audio: required when no URL; 3–30 second 16-bit PCM WAV, 16–48 kHz sample rate; entire HTTP body <= 2 MiB (recommend mono 16kHz WAV)
- reference_audio_url: public HTTPS URL when no file; URL is forwarded to provider without storing input audio in IndexTTS R2
- emotion: optional natural|happy|sad|angry|calm; default natural

~~~bash
export INDEXTTS_API_KEY="itts_live_YOUR_KEY"
export INDEXTTS_REQUEST_ID="$(python3 -c 'import uuid; print(uuid.uuid4())')"
curl -X POST "https://indextts.online/api/v1/tts" \
  -H "Authorization: Bearer $INDEXTTS_API_KEY" \
  -H "Idempotency-Key: $INDEXTTS_REQUEST_ID" \
  -F "text=你好，欢迎使用 IndexTTS2。" \
  -F "reference_audio=@voice.wav;type=audio/wav" \
  -F "emotion=natural"
~~~

Success: HTTP 202 {"id":"TASK_ID","status":"starting","model":"indextts-2"}. Save the task ID.

## GET /api/v1/tts/{id}

Poll every 3–5 seconds using Authorization Bearer header. Status: queued, starting, processing, succeeded, failed, canceled.
Success: {"id":"TASK_ID","status":"succeeded","model":"indextts-2","duration_seconds":12.4,"billed_seconds":12.4,"audio_url":"SHORT_LIVED_PRIVATE_WAV_URL"}. Download audio_url promptly. Other accounts and expired tasks cannot be read.

## GET /api/v1/usage

Returns plan, period_start, period_end, total_seconds (6000 monthly Pro, 10800 yearly Pro), used_seconds, remaining_seconds, can_generate, source_breakdown.web_seconds and source_breakdown.api_seconds. Billing periods follow your paid subscription and do not roll over. A few seconds may remain while can_generate=false if insufficient for the next task.

## Python 3 example

Install: pip install requests

~~~python
import os, time, uuid, requests
base = "https://indextts.online"
headers = {"Authorization": "Bearer " + os.environ["INDEXTTS_API_KEY"]}
key = str(uuid.uuid4())
with open("voice.wav", "rb") as voice:
    r = requests.post(base+"/api/v1/tts", headers={**headers,"Idempotency-Key":key}, data={"text":"Hello from IndexTTS2.","emotion":"natural"}, files={"reference_audio":("voice.wav",voice,"audio/wav")}, timeout=30)
result = r.json()
if r.status_code == 503 and result.get("code") == "PROVIDER_STATUS_UNKNOWN":
    # The provider may already be processing. Preserve the returned task ID.
    task_id = result["id"]
else:
    r.raise_for_status()
    task_id = result["id"]
for attempt in range(90):
    r = requests.get(base+"/api/v1/tts/"+task_id, headers=headers, timeout=20)
    r.raise_for_status()
    task = r.json()
    if task["status"] == "succeeded":
        wav = requests.get(task["audio_url"], timeout=60)
        wav.raise_for_status()
        with open("output.wav","wb") as out: out.write(wav.content)
        break
    if task["status"] in ("failed","canceled"): raise RuntimeError(task)
    time.sleep(4)
else: raise TimeoutError("Query the existing task ID again later.")
~~~

For POST retries, keep the original UUID and exact same request body. A terminal failed task does not restart with the same UUID. A 503 PROVIDER_STATUS_UNKNOWN response includes the existing task ID; poll it instead of starting a new prediction.

## Errors

400 INVALID_REQUEST/INVALID_AUDIO/INVALID_AUDIO_URL/TEXT_LIMIT: correct inputs, URL or audio format. Remote URL must be public HTTPS and reachable by the inference provider.
401 INVALID_API_KEY: rotate/check Key.
403 SUBSCRIPTION_REQUIRED/ACCOUNT_RESTRICTED: renew Pro/resolve restriction.
404 TASK_NOT_FOUND: inaccessible or expired task.
409 IDEMPOTENCY_CONFLICT/GENERATION_IN_PROGRESS: fix duplicate body or wait.
429 MONTHLY_QUOTA_EXHAUSTED/QUOTA_INSUFFICIENT: wait for billing cycle or shorten text.
503 PROVIDER_STATUS_UNKNOWN: a task ID is returned. Poll that task ID; do not submit another POST because remote inference may be running.
503 MODEL_UNAVAILABLE: no task was accepted when the provider definitively rejected it. Check service availability before initiating a new logical request.

## Instructions for AI coding agents

Read this guide and the OpenAPI document https://indextts.online/openapi.json. Never expose a Key to browser code or source control. Do not invent IndexTTS 2.5 endpoints, stream mode, language/speed fields or external callback APIs. For remote public HTTPS reference audio, send application/json with reference_audio_url (no re-upload); for local WAV files, send multipart/form-data with reference_audio. Use exactly one input source, persist task ID and Idempotency-Key, poll to terminal state, download audio_url and respect shared Pro minutes.