AniwaffleDocsHomeStudio

Text to Speech

Long-form audio

Submit long text as a job and download the audio when it is ready, without holding a connection open while it generates.

Overview

A job takes the same request body as POST /v1/tts, up to 20,000 characters, and runs in the background:

  1. Submit the text with POST /v1/tts/jobs. The response is 202 Accepted with a job ID.
  2. Poll GET /v1/tts/jobs/{id} until the status is completed.
  3. Download the audio from GET /v1/tts/jobs/{id}/audio.

The audio stays available for 24 hours after you submit the job. For text over 20,000 characters, split it at paragraph or sentence boundaries and submit one job per part.

Submit a job

Jobs require an Idempotency-Key header. Use a value that identifies this exact text, such as a document revision ID, so a retried submission returns the same job instead of creating a new one.

curl https://aniwaffle.com/v1/tts/jobs \
  --header "Authorization: Bearer $ANIWAFFLE_API_KEY" \
  --header "Content-Type: application/json" \
  --header "Idempotency-Key: chapter-1-rev-3" \
  --data '{
    "text": "Chapter one. It was a quiet morning in the village...",
    "voice_id": "'"$ANIWAFFLE_VOICE_ID"'",
    "output_format": "pcm_48000"
  }'
Response · 202
{
  "id": "JOB_ID",
  "request_id": "rq_...",
  "status": "queued",
  "expires_at": "2026-11-24T09:00:00.000Z",
  "status_url": "/v1/tts/jobs/JOB_ID",
  "audio_url": null
}

Wait for the result

Poll the job every few seconds until status is completed, failed or expired.

while (job.status === 'queued' || job.status === 'running') {
  await new Promise((resolve) => setTimeout(resolve, 2000))
  job = await (await fetch(`https://aniwaffle.com/v1/tts/jobs/${job.id}`, {
    headers: { Authorization: `Bearer ${process.env.ANIWAFFLE_API_KEY}` },
  })).json()
}
if (job.status !== 'completed') throw new Error(`Job ${job.status}`)
StatusMeaning
queuedAccepted and waiting to start.
runningGenerating audio.
completedThe audio is ready at audio_url.
failedGeneration failed. The job includes "error_code": "synthesis_failed". Submit a new job with a new Idempotency-Key.
expiredMore than 24 hours have passed. The audio is no longer available.

Download the audio

curl "https://aniwaffle.com/v1/tts/jobs/$JOB_ID/audio" \
  --header "Authorization: Bearer $ANIWAFFLE_API_KEY" \
  --output chapter-1.pcm

The download has the same Content-Type, X-Audio-Format, X-Audio-Channels and X-Audio-Duration-Ms headers as POST /v1/tts. Downloading again within 24 hours costs nothing. Stream long files to disk instead of buffering them in memory.

Resume an interrupted download

The download supports HTTP range requests. Save the ETag from the first response and the number of bytes you wrote, then request the rest:

http
GET /v1/tts/jobs/JOB_ID/audio
Authorization: Bearer awp_...
Range: bytes=1048576-
If-Range: "ETAG_FROM_FIRST_RESPONSE"
  • 206 Partial Content returns only the requested bytes. Check that Content-Range starts at your offset, then append.
  • 200 OK returns the whole file. Replace your partial copy.
  • 416 Range Not Satisfiable includes Content-Range: bytes */TOTAL. If your file already has that many bytes and the ETag matches, it is complete.

Retries and limits

  • Idempotency. Submitting the same Idempotency-Key with the same body returns the original job. The same key with a different body returns 409 idempotency_conflict. A key stays reserved after the job fails or expires, so use a new key for a new attempt.
  • Queue limit. A workspace can have 20 jobs queued or running at once. More return 429 batch_queue_full with Retry-After: 10.
  • Not ready yet. Downloading before the job completes returns 409 batch_in_progress with Retry-After: 2.
  • Gone. A failed or expired job's audio returns 410 batch_result_unavailable.
  • Key rotation. Any API key in the same workspace can read and download a job. Save the job ID before rotating keys.
  • Revocation. Revoking the submitting key before the job starts cancels it.

See Speech jobs for the full reference.

Contact our team

Tell us about your character and what you’d like to build.