Integrate LinguaRiff Text-to-Speech with Python

By LinguaRiff editorial team · Updated 2026-11-19

This guide provides a precise integration path for Python applications consuming the LinguaRiff text-to-speech API. It covers authentication, request structures, and error handling tailored for production environments where deterministic pricing and transparent character billing are critical for agency workflows managing multiple creator accounts.

Readers will find concrete code examples for synthesizing audio via the OpenAI-compatible Python library, handling long-text splitting, and managing rate limits. The documentation details supported output formats, voice presets, and key rotation procedures to ensure reliable high-volume content pipelines without unexpected downtime or billing surprises.

Integrate LinguaRiff Text-to-Speech with Python

Frequently asked questions

What is the base URL for the API?

The API base URL is https://api.99grill.cc/v1. You use this endpoint for all requests, including speech generation and voice listing. This URL is required when configuring your client library to ensure requests are routed correctly to the LinguaRiff infrastructure.

Which Python library should I use?

Use the official OpenAI Python SDK. The API endpoint shape matches the OpenAI speech endpoint exactly. You can use the standard library to send requests by simply changing the base URL configuration to point to https://api.99grill.cc/v1.

How do I set the base URL in OpenAI SDK?

Initialize the OpenAI client with the base_url parameter set to https://api.99grill.cc/v1. Pass your API key via the api_key argument. This allows you to use standard OpenAI SDK methods while routing traffic through the LinguaRiff infrastructure.

What are the available response formats?

Supported formats are mp3, wav, opus, flac, and pcm. Specify the desired format in the response_format field of your request body. The API returns the audio file in the selected format directly in the response.

How do I handle texts longer than 4096 characters?

Split your input text into chunks of up to 4096 characters. Send each chunk as a separate request to the speech endpoint. Then, join the resulting audio files sequentially in your pipeline to create the final audio output.

What happens if I exceed the rate limit?

The limit is 60 requests per minute per key. If you exceed this, subsequent requests may wait in a queue. Requests are processed one after another, so latency increases under load until the queue clears.

How do I rotate my API key?

Issue a new key from your account dashboard. The new key becomes active immediately. The old key stops working at once. You can rotate keys anytime without downtime, ensuring secure access management for your production environments.

Is the API synchronous or asynchronous?

The API is synchronous. You send a POST request and receive the audio file in the response. There is no WebSocket or streaming endpoint for partial audio. You must wait for the full generation to complete before proceeding.

Do I need to install a specific SDK?

No specific SDK is required. Use the standard OpenAI Python SDK or plain HTTP libraries. The endpoint compatibility allows you to use existing tools by simply updating the base URL configuration to point to the LinguaRiff API.

First request

curl

curl https://api.99grill.cc/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.99grill.cc/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.99grill.cc/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

Sound wave illustration for: Authentication

Authentication relies on a single active Bearer token per account, passed via the Authorization header. The token format is Bearer tts-<your_key>. Each account maintains one active key; issuance of a new key immediately invalidates the previous one, ensuring strict access control for agency pipelines.

Keys are generated during sign-up on the /get-api-key/ page. The interface displays the current key, balance, and usage statistics. No additional authentication layers or API key scopes are supported.

Bearer token format

Bearer token format

Include the header Authorization: Bearer tts-<key> in every request. The prefix tts- is mandatory. Incorrect formatting results in a 401 Unauthorized error. The token grants full access to all endpoints for the associated account.

Key generation limits

Key generation limits

Each account is limited to one active API key at any given time. There is no limit on the number of keys ever generated, but only the most recently issued key remains valid.

  • One active key per account.
  • No role-based access control (RBAC).
  • No key expiration by default.

Key rotation process

To rotate your key, generate a new one via the dashboard. The old key stops working immediately upon generation of the new one. Update your application configuration promptly to avoid service interruption during deployment.

Quickstart

Sound wave illustration for: Quickstart

For agencies managing high-volume YouTube pipelines, integrating LinguaRiff requires minimal overhead. The standard OpenAI Python client is the recommended tool, leveraging its existing infrastructure for reliable request handling and JSON parsing.

Install OpenAI Python library

Install the official package via pip to ensure compatibility with the standard request shape. This library handles the HTTP transport and JSON serialization required by the API.

  • pip install openai

Configure base_url

Direct the client to the LinguaRiff endpoint by overriding the default base URL. This allows the use of standard SDK methods without custom HTTP logic.

  • base_url='https://api.99grill.cc/v1'

First synthesis request

Invoke the speech endpoint with your Bearer token and desired parameters. The API returns the audio file directly, ready for immediate ingestion into your content pipeline.

  • client.audio.speech.create(model='tts-1', voice='nova', input='Hello world', response_format='mp3')

Endpoint Details

Sound wave illustration for: Endpoint Details

The API exposes three primary endpoints for integration. The speech endpoint handles synthesis, while the voices and models endpoints provide metadata for configuration and billing calculations.

POST /v1/audio/speech

This endpoint accepts a JSON body containing the text input, voice ID, and format preferences. It returns the generated audio file directly in the response stream. Text is limited to 4,096 characters per request.

  • Supports mp3, wav, opus, flac, and pcm formats.
  • Accepts speed adjustments between 0.25 and 4.0.

GET /v1/voices

Returns a list of available voice presets, their associated languages, and supported audio formats. This data allows your application to dynamically populate voice selection interfaces without hardcoding IDs.

  • Includes 8 distinct voice presets.
  • Covers 23 supported languages.

GET /v1/models

Provides details on the underlying synthesis engines, specifically tts-1 and tts-1-hd. Both models use the same engine and pricing structure, allowing for straightforward model selection without cost variance.

  • Returns model ID and name.
  • Indicates pricing tier.

Request Parameters

Sound wave illustration for: Request Parameters

LinguaRiff offers two model configurations, tts-1 and tts-1-hd, which utilize the same underlying engine and pricing structure. Selecting between them allows you to balance processing priority without affecting the per-character cost of $0.01 per 1,000 characters. Both models support the full range of voice presets and language options defined in the API specification.

Model selection (tts-1, tts-1-hd)

The model field accepts either "tts-1" or "tts-1-hd". Since both variants share identical pricing and voice capabilities, the choice depends on your infrastructure needs rather than audio quality differences. Each request consumes character credits equally regardless of the selected model variant.

Input text length limits

Each API call accepts a maximum of 4,096 characters in the input field. Spaces and punctuation are counted toward this limit. For longer scripts, split the text into chunks of 4,000 characters or fewer and concatenate the resulting audio files. Short phrases typically require a few seconds to synthesize, while longer texts process at roughly real-time speed.

  • Maximum input: 4,096 characters per request
  • Spaces and punctuation count as characters
  • Concatenate multiple audio files for longer content

Voice ID selection

Assign one of eight voice presets via the voice parameter. These include female voices like aria and nova, and male voices such as atlas and orion. Any voice can speak any of the 23 supported languages. If the language field is omitted, the system guesses the language, defaulting to English for Latin-script text.

  • 8 presets: aria, nova, luna, sage, felix, milo, atlas, orion
  • Cross-language capability: any voice supports all 23 languages
  • Set language explicitly to avoid English default guessing

Response Formats

Sound wave illustration for: Response Formats

Select the response_format parameter in your POST request to determine the output container. Supported formats include MP3, WAV, Opus, FLAC, and PCM, allowing you to balance file size and audio fidelity according to your pipeline requirements.

MP3 output

MP3 is the default format, offering efficient compression for general use. It is suitable for most YouTube content workflows where bandwidth efficiency is prioritized without significant quality loss.

WAV output

WAV provides uncompressed PCM audio, ensuring maximum fidelity for professional editing. Use this format if your downstream processing requires lossless audio data or specific sample rate compatibility.

Opus/FLAC/PCM support

Opus offers high-quality compression. FLAC provides lossless compression, reducing storage size while preserving audio quality. PCM returns raw, uncompressed audio data, ideal for immediate playback or further processing without decoding overhead.

Response Formats

Rate Limits

Sound wave illustration for: Rate Limits

Your API key allows 60 requests per minute under normal conditions. This limit applies per key. Failed requests do not consume your quota and are refunded automatically.

60 requests per minute

Standard accounts process 60 requests per minute. This throughput supports steady-state pipelines for agency workflows. Monitor your usage dashboard to stay within limits.

  • Limit: 60 requests/minute per key
  • Applies to successful and attempted requests
  • Failed requests are free and do not count

10 requests before top-up

Accounts start with a 10-request per minute limit before the first top-up. This restriction lifts automatically after the first top-up. Ensure your balance is sufficient before scaling volume.

  • Initial limit: 10 requests/minute
  • Unlocks after first $5+ top-up
  • Top-ups are processed within minutes

Queue behavior under load

Requests are processed sequentially. Under high load, subsequent requests may wait in a queue. Expect slight delays for batch operations during peak usage. Plan your timing accordingly.

  • Sequential processing model
  • Queuing occurs under heavy load
  • No guaranteed real-time latency

Error Handling

Sound wave illustration for: Error Handling

Production pipelines require robust error handling to maintain audio generation throughput. The API returns standard HTTP status codes to indicate success or failure, allowing your Python clients to route requests appropriately without manual intervention.

Common HTTP errors

The API returns 4xx errors for invalid requests, such as exceeding the 4096-character limit or using an unsupported voice ID. A 429 error indicates you have exceeded the rate limit.

  • 400: Bad Request (invalid JSON or missing fields)
  • 401: Unauthorized (invalid or expired API key)
  • 429: Too Many Requests (rate limit exceeded)
  • 500: Internal Server Error (transient engine failure)

Retry logic

Implement exponential backoff for transient 5xx errors. Since requests are processed sequentially under load, a 429 response may resolve quickly if you wait briefly before retrying. Avoid aggressive retry loops to prevent additional rate limit penalties.

Failed request refunds

If synthesis fails, the charge is returned in full. This applies to server-side errors and certain client-side failures where no audio was generated. Your account balance is automatically restored, ensuring deterministic pricing even during outages.

Code Examples

Sound wave illustration for: Code Examples

The following Python examples demonstrate how agencies can integrate LinguaRiff into their YouTube content pipelines. Each snippet uses the official OpenAI SDK with a custom base URL, ensuring deterministic billing and reliable audio generation for high-volume workflows.

These scripts handle authentication, voice selection, and response processing without external dependencies beyond the standard library and openai package. They are designed for batch execution in CI/CD environments or local agency dashboards.

Basic Python script

This example initializes the client with your API key and sends a simple text-to-speech request. It retrieves the audio binary and saves it as an MP3 file. Ensure your OPENAI_BASE_URL points to https://api.99grill.cc/v1. The script handles the basic HTTP POST request and error codes.

The code demonstrates the minimum viable integration for a single voice generation. It uses the tts-1 model and the nova voice, which is suitable for upbeat YouTube intros. Adjust the input string and voice parameter as needed for your specific content requirements.

  • Install: pip install openai
  • Set environment variable: OPENAI_API_KEY=tts-...
  • Set OPENAI_BASE_URL=https://api.99grill.cc/v1

Handling long text

Since the API limits input to 4096 characters per request, long scripts must be split. This script splits the text by sentences, synthesizes each chunk, and concatenates the resulting audio files. This approach ensures that no part of your narration is truncated due to length limits.

The example uses a simple regex to split text, preserving punctuation. Each chunk is processed sequentially, respecting the rate limit of 60 requests per minute. The final audio file is saved as a single MP3, ready for upload to YouTube or other platforms.

  • Split text into chunks < 4096 chars
  • Synthesize each chunk independently
  • Concatenate audio files sequentially

Batch processing example

For agencies managing multiple creator accounts, this script processes a list of text-voice pairs. It iterates through the list, generating audio for each entry. The script includes basic error handling to skip failed requests without stopping the entire batch, ensuring high throughput.

Each request is logged with its character count and status. The script respects the rate limit by adding a small delay if necessary. The output is a directory of MP3 files, named by the input text snippet, ready for integration into your video editing pipeline.

  • Process multiple text-voice pairs
  • Log character count and status
  • Skip failed requests without stopping batch

Listen to the 8 voices

Each sample below was generated by this API from the same sentence. Transfers are credited automatically within minutes, ensuring your production pipeline remains uninterrupted.

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. LibriTTS-R paper (arXiv 2305.18802)
  3. ISO 639 language codes
  4. FFmpeg documentation
  5. Tether (USDT)
  6. MDN: Web Speech API
  7. LibriVox public-domain audiobooks
  8. Node.js documentation
  9. IETF RFC 7845: Ogg Opus
  10. curl documentation
  11. W3C WAI: making audio and video accessible
  12. Python documentation

More on this site