Python Text to Speech API Documentation and Quickstart

By IndieTTS Review editorial team · Updated 2026-11-18

This page provides concrete Python code examples for integrating our cloud text-to-speech API into your indie applications. We cover authentication, SDK setup using the official OpenAI client, and request parameters so you can generate audio files directly from your scripts without guessing the implementation details.

Designed for developers who need reliable, predictable TTS without enterprise overhead, we detail rate limits, error handling, and long-text splitting strategies. You will find exact curl equivalents and Python snippets for voice selection, format options, and speed adjustments to help you ship faster.

Python Text to Speech API Documentation and Quickstart

Frequently asked questions

How do I set the base URL in Python?

Configure the OpenAI SDK’s base_url parameter to https://api.9999winth.com/v1. This allows you to use the standard SDK methods while routing requests to our endpoint. Ensure your API key is correctly set in the environment or passed directly to the client instance for authentication.

What is the correct header for authentication?

Include the header Authorization: Bearer tts-... in your requests. You must use your unique API key generated in your account dashboard. This key authenticates your requests and tracks your usage against your balance and rate limits.

Can I use the official OpenAI Python SDK?

Yes, the official OpenAI Python SDK works by changing the base_url to https://api.9999winth.com/v1. The request shape matches the OpenAI speech endpoint, allowing you to use standard methods like Audio.speech.create() with minimal code changes.

How do I handle rate limit errors?

The limit is 60 requests per minute per key (10 before the first top-up). Requests are processed sequentially, so under load, you may experience queue delays. Implement exponential backoff in your Python code to handle HTTP 429 errors gracefully.

What happens if the input text is too long?

The API accepts up to 4096 characters per request. For longer texts, split the input into chunks of this size, generate audio for each, and join the resulting audio files in your application logic to create the final output.

Does the API support async requests?

The API does not support streaming or WebSocket connections. Requests are processed synchronously. You can implement async behavior in your Python application by using asyncio or concurrent futures, but the API itself processes requests sequentially.

How do I get a list of available voices?

Send a GET request to /v1/voices. This endpoint returns details about the 8 available voice presets, supported languages, and audio formats. Use this to dynamically populate your application’s voice selection interface.

What is the maximum speed value?

The maximum speed value is 4.0. The valid range for the speed parameter is 0.25 to 4.0. Adjusting this value scales the generation speed proportionally while maintaining voice characteristics.

Is the WAV format lossless?

The API supports WAV as a response format. WAV is one of the supported response formats. It is one of four supported formats: mp3, wav, opus, and flac.

How do I detect errors in the response?

Check the HTTP status code. Failed requests are free, and the charge is returned in full. Inspect the response body for error details. Use standard HTTP client error handling in your Python script to catch and log these events.

Can I mix voices in a single request?

No, each request accepts a single voice parameter. To use multiple voices, you must send separate requests for each voice segment and then concatenate the resulting audio files in your application.

Do I need to install a specific library?

You can use the official OpenAI Python SDK or plain HTTP libraries like requests. No proprietary library is required. The SDK is recommended for ease of use, but any HTTP client can send the JSON body.

How is the audio returned in the response?

The audio file is returned directly in the response body. The format matches the response_format parameter (mp3, wav, opus, flac, or pcm). You can save this binary data directly to a file on your local system.

First request

curl

curl https://api.9999winth.com/v1/audio/speech \
  -H "Authorization: Bearer $TTS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"tts-1","voice":"aria","input":"Hello from the API.","response_format":"mp3"}' \
  --output hello.mp3

Python (openai)

from openai import OpenAI

client = OpenAI(base_url="https://api.9999winth.com/v1", api_key="tts-...")

with client.audio.speech.with_streaming_response.create(
    model="tts-1", voice="nova", input="Hello from Python.", response_format="mp3"
) as response:
    response.stream_to_file("hello.mp3")

Node.js (openai)

import OpenAI from "openai";
import fs from "node:fs";

const client = new OpenAI({ baseURL: "https://api.9999winth.com/v1", apiKey: process.env.TTS_API_KEY });
const res = await client.audio.speech.create({ model: "tts-1", voice: "milo", input: "Hello from Node.js." });
fs.writeFileSync("hello.mp3", Buffer.from(await res.arrayBuffer()));
voice
ariafemale
novafemale
lunafemale
sagefemale
felixmale
milomale
atlasmale
orionmale
language
arالعربية
zh中文
daDansk
nlNederlands
enEnglish
fiSuomi
frFrançais
deDeutsch
elΕλληνικά
heעברית
hiहिन्दी
itItaliano
ja日本語
ko한국어
msBahasa Melayu
noNorsk
plPolski
ptPortuguês
ruРусский
esEspañol
swKiswahili
svSvenska
trTürkçe

Authentication and Keys

Sound wave illustration for: Authentication and Keys

Authentication relies on a single active Bearer token per account, issued via the /get-api-key/ dashboard. The token format is strictly tts-<random_string>, passed in the HTTP header as Authorization: Bearer tts-.... This key grants access to all endpoints and tracks your usage against your current balance.

Unlike systems with multiple scoped keys, IndieTTS uses one key per account. You can generate a new key at any time via the dashboard; the old key becomes invalid immediately upon creation, ensuring precise control over active sessions without legacy token drift.

Generating API Keys

Generating API Keys

Sign up via Google or email on the /get-api-key/ page to receive your initial key. Google sign-ups include a $0.50 trial credit (valid 7 days), while email accounts start with zero balance. The dashboard displays your active key, current balance, and character usage metrics.

  • Keys are generated exclusively on the /get-api-key/ dashboard.
  • Google sign-ups include a $0.50 trial credit.
  • Email-only accounts start with no trial credit.

Bearer Token Format

Bearer Token Format

Pass the token in the Authorization header using the Bearer scheme. The value must begin with tts- followed by the unique identifier assigned to your account. Example: Authorization: Bearer tts-a1b2c3d4e5f6. Incorrect formatting or expired keys result in a 401 Unauthorized response.

  • Header: Authorization: Bearer tts-...
  • Prefix is always tts-.
  • One active key per account.

Key Rotation Policy

Generate a new key anytime from the dashboard. The previous key stops working instantly, not after a grace period. This immediate invalidation prevents unauthorized use if a key is compromised. No downtime occurs for new keys; simply update your environment variables and restart your service.

  • Old keys invalidate immediately.
  • No grace period for rotation.
  • Update env variables and restart.

Base URL and Endpoint

Sound wave illustration for: Base URL and Endpoint

All API requests target the base URL https://api.9999winth.com/v1. The primary endpoint for synthesis is a POST request to /audio/speech, accepting JSON bodies identical to the OpenAI speech format. This compatibility allows you to use the standard OpenAI Python SDK by simply overriding the base_url parameter during client initialization.

Speech Endpoint Path

Send your text payload to https://api.9999winth.com/v1/audio/speech. The endpoint returns an audio file or binary data depending on your preferred response format. Ensure your Authorization header includes the Bearer token generated from your account dashboard.

GET Voices Endpoint

Retrieve available voice presets, supported languages, and audio formats by issuing a GET request to /voices. This endpoint lists all eight voices (e.g., aria, nova, felix) compatible with the 23 supported languages. Use this data to dynamically populate your application’s voice selection UI.

GET Models Endpoint

Query /models to confirm available engine versions. Currently, both tts-1 and tts-1-hd are supported, sharing the same pricing tier of $10 per 1 million characters.

Python SDK Integration

Sound wave illustration for: Python SDK Integration

To integrate IndieTTS Review into your Python environment, install the official OpenAI SDK and configure it to point at our API base URL. This allows you to use standard TTS methods without writing custom HTTP clients.

We provide ready-to-run code snippets that demonstrate authentication, voice selection, and audio retrieval. These examples follow the same request shape as the OpenAI speech endpoint, ensuring compatibility with existing indie developer workflows.

OpenAI SDK Setup

Install the latest OpenAI Python package via pip. You do not need a proprietary client library; the standard OpenAI SDK handles the JSON serialization and file streaming efficiently.

  • Run pip install openai to add the dependency to your project.
  • Import the OpenAI client class from the openai package in your Python script.

Base URL Configuration

Set the base_url parameter in your client initialization to https://api.9999winth.com/v1. This redirects all API calls to our infrastructure while preserving the standard SDK interface.

Use your API key in the api_key field. The format is a string starting with tts- prefixed to your unique token.

  • Base URL: https://api.9999winth.com/v1
  • Authentication header: Authorization: Bearer tts-<your_key>

Python Code Snippet

The following example demonstrates a complete request using the tts-1 model with the nova voice. It retrieves the audio bytes and saves them as an MP3 file.

This snippet assumes you have already set your API key in the environment variable OPENAI_API_KEY or passed it directly to the client.

  • Use client.audio.speech.create() to generate audio.
  • Set model="tts-1" and voice="nova".
  • Save the .content attribute to a .mp3 file.

Request Parameters

Sound wave illustration for: Request Parameters

The API accepts text input up to 4,096 characters per request. Spaces and punctuation are counted toward this limit and the billing total. For longer content, split the text into chunks and join the resulting audio files sequentially.

Input Text Field

Pass your text string in the input field. The engine processes up to 4,096 characters per call. If your script exceeds this, handle the splitting logic in your Python code before sending the request.

  • Max 4,096 characters per request
  • Spaces and punctuation count as characters
  • Split long texts in your application logic

Voice Selection

Choose from eight distinct presets like aria for clear narration or atlas for neutral news delivery. Each voice supports all 23 listed languages. If you omit the language parameter, the system guesses the language based on the script, defaulting to English for Latin text.

  • 8 presets: aria, nova, luna, sage, felix, milo, atlas, orion
  • Voices support all 23 available languages
  • Language auto-guessing defaults to English for Latin scripts

Response Format Options

Specify the response_format to control the output file type. Supported formats include mp3, wav, opus, flac, and pcm. MP3 is recommended for general use due to its balance of quality and file size, while FLAC offers lossless compression.

  • mp3: Standard compressed audio
  • wav: Uncompressed PCM audio
  • opus: Efficient compression
  • flac: Lossless compression
  • pcm: Raw uncompressed audio

Error Handling and Status Codes

Sound wave illustration for: Error Handling and Status Codes

Synthesis failures return full credits, ensuring you only pay for successful audio generation. The API provides standard HTTP status codes to distinguish between client errors, such as invalid JSON, and server-side processing issues.

Common Error Codes

Use 400 errors to debug malformed requests, such as missing the input field or exceeding the 4096-character limit. A 401 indicates an expired or invalid Bearer token, while 500s signal temporary backend issues.

Retry Logic

Implement exponential backoff for 500 and 503 errors, as the queue may temporarily stall under load. Retrying immediately on 429 (Too Many Requests) is ineffective; wait until the rate limit window resets.

Rate Limit Errors

You receive a 429 status if you exceed 60 requests per minute per key. New accounts start with a stricter limit of 10 requests per minute until the first top-up is processed.

Error Handling and Status Codes

Rate Limits and Throttling

Sound wave illustration for: Rate Limits and Throttling

The API enforces a hard limit of 60 requests per minute per active key. This applies to all endpoints, including voice listing and model queries. Exceeding this threshold triggers a 429 Too Many Requests error. You must implement retry logic with exponential backoff to handle these throttles gracefully during high-volume synthesis jobs.

Before your first top-up, the limit is stricter at 10 requests per minute. Once you add USDT (TRC-20), the standard 60 req/min limit applies immediately. Failed requests do not consume your quota or incur charges, allowing safe retries without cost penalties.

60 Requests Per Minute

Each active API key is allowed 60 requests per minute. This limit is strict and applies across all endpoint calls. If you exceed this, subsequent requests return a 429 status code until the window resets. Implement client-side rate limiting or use exponential backoff to manage bursts effectively.

  • Limit: 60 requests/minute/key
  • Applies to all endpoints
  • Returns 429 when exceeded

Pre-Top-Up Limits

Free trial accounts and those without a top-up operate under a reduced limit of 10 requests per minute. This lower tier allows testing but restricts sustained high-volume usage. Adding USDT (TRC-20) increases the limit to the standard 60 requests per minute automatically within minutes.

Queue Behavior

Requests are processed sequentially when the server is under load. If the queue is long, your request may wait before synthesis begins. This can increase latency for long texts, though typical speed remains close to real-time. Short phrases may take a few seconds due to queueing.

Audio Format Options

Sound wave illustration for: Audio Format Options

Choosing the right audio format balances file size, quality, and compatibility. Our API supports five distinct output types via the response_format parameter, allowing you to optimize for your specific deployment environment.

MP3 vs WAV

MP3 provides efficient compression with broad compatibility, ideal for web players and mobile apps where bandwidth matters. WAV offers lossless quality, suitable for high-fidelity applications or further audio processing without generation artifacts.

OPUS and FLAC Support

OPUS delivers efficient compression, suitable for storage-constrained environments. FLAC provides lossless compression, reducing file size compared to WAV while preserving exact audio fidelity.

PCM Raw Audio

PCM returns uncompressed raw audio data. Use this format when you need raw samples for immediate DSP processing or when integrating with hardware that expects raw byte streams.

Advanced Usage Patterns

Sound wave illustration for: Advanced Usage Patterns

Handling texts longer than 4096 characters requires client-side splitting. Send each segment individually and concatenate the resulting audio files to reconstruct the full narrative.

Long Text Splitting

Split input text into chunks of up to 4096 characters. Process each chunk sequentially or concurrently, then join the returned audio files into a single output file.

Speed Adjustment

Adjust playback speed between 0.25 and 4.0 using the speed parameter. This scales generation time but does not affect the final character count billing.

Language Code Override

Explicitly set the language field with an ISO code (e.g., 'de' for German). This ensures correct pronunciation for Latin-script text that might otherwise default to English.

Listen to the 8 voices

Each sample below was generated by this API from the same sentence. These platforms provide extensive toolsets for video editing, translation, and speech-to-text, which are unnecessary for simple TTS integration.

Avatar of the voice aria
ariafemale
Avatar of the voice nova
novafemale
Avatar of the voice luna
lunafemale
Avatar of the voice sage
sagefemale
Avatar of the voice felix
felixmale
Avatar of the voice milo
milomale
Avatar of the voice atlas
atlasmale
Avatar of the voice orion
orionmale

23 languages

Any voice speaks any of these languages.

Sources and further reading

  1. Wikipedia
  2. OpenAI API reference: create speech
  3. W3C WAI: making audio and video accessible
  4. LibriTTS-R paper (arXiv 2305.18802)
  5. Tether (USDT)
  6. ISO 639 language codes
  7. Creative Commons Attribution 4.0
  8. MDN: Web Speech API
  9. TRON developer hub: TRC-20
  10. Python documentation
  11. openai-python on GitHub
  12. curl documentation

More on this site