Python TTS API: Quickstart Guide for OpenAI SDK Users

By CodeCaster editorial team · Updated 2026-11-19

This guide shows WordPress and blog creators how to generate realistic audio from text using the CodeCaster API. You will learn to integrate our lightweight, character-based TTS service directly into your content pipeline. We leverage the familiar OpenAI Python SDK structure, so you can swap in our base URL and start generating speech with minimal code changes. No heavy plugins or slow page loads required.

Whether you are building a simple audio player or automating blog posts, this page covers everything from signing up for your API key to handling errors. You will find concrete Python examples, clear explanations of voice and language parameters, and details on pricing and rate limits. If you already know the OpenAI SDK, you are ready to go.

Python TTS API: Quickstart Guide for OpenAI SDK Users

Frequently asked questions

What is the API endpoint?

Send your text to POST https://api.casicosta.cc/v1/audio/speech. You provide a JSON body containing the model, input text, voice selection, and desired audio format. This endpoint handles the synthesis process and returns the generated audio file directly in the response.

How do I set the base URL?

Configure your client to use https://api.casicosta.cc/v1 as the base URL. This allows you to use standard HTTP libraries or the OpenAI SDK by simply changing the endpoint configuration. All API requests, including speech generation and voice listing, use this base URL.

Does it work with OpenAI SDK?

Yes, the request shape matches the OpenAI speech endpoint. You can use the official OpenAI SDKs by changing the base_url to https://api.casicosta.cc/v1 and providing your CodeCaster API key. This ensures seamless integration for Python developers already familiar with the OpenAI ecosystem.

What models are available?

Two models are available: tts-1 and tts-1-hd. Both use the same engine and pricing structure. You can select either model in your API requests depending on your quality preferences, though the underlying synthesis technology remains identical for both options in this API.

What is the character limit per request?

Each API request supports up to 4096 characters of input text. For longer texts, you should split the content into chunks of this size and join the resulting audio files. This limit ensures efficient processing and consistent generation times for your content pipeline.

Can I adjust speed?

Yes, you can adjust the playback speed between 0.25 and 4.0. This allows you to speed up narration for quick updates or slow it down for clarity. The speed parameter is included in the JSON body of your request to the speech endpoint.

How do I set the language?

You can set the language using an optional ISO code in the request body. If omitted, the system guesses the language from the script, defaulting to English for Latin text. For non-English Latin text, explicitly setting the language ensures accurate synthesis.

What happens if a request fails?

If synthesis fails, the charge is returned in full. You are not billed for failed requests, ensuring you only pay for successful audio generation. This protects your budget while allowing you to retry requests without financial penalty if technical issues occur.

What are the rate limits?

You are limited to 60 requests per minute per key. Before your first top-up, this limit is reduced to 10 requests per minute. These limits apply to your active API key and help manage server load during high-volume generation periods for your blog.

Is streaming supported?

No streaming, WebSocket, or real-time partial audio is supported. The API returns the complete audio file after synthesis is finished.

Do you support SSML?

SSML is not supported. You cannot use SSML tags for fine-grained control over pronunciation or pauses. You rely on the natural voice presets and speed adjustments to control the audio output. This keeps the API lightweight and easy to integrate via simple text inputs.

How do I manage my API key?

Manage your key via the /get-api-key/ page on the site. You can view your current key, balance, and usage statistics there. The page also provides a ready-to-use curl example to help you start generating audio immediately after signing up for an account.

Can I generate multiple keys?

You have one active key per account. You can issue a new key at any time, which immediately stops the old one. This allows you to rotate keys for security or separate projects without needing multiple accounts or complex permission structures.

Is data used for training?

Your input text is used only to produce the audio and is not used for training. Generated audio is returned in the response and not stored. Request metadata is kept for billing purposes, ensuring your content remains private and secure.

First request

curl

curl https://api.casicosta.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.casicosta.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.casicosta.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

Get Your API Key

Sound wave illustration for: Get Your API Key

Start by visiting the /get-api-key/ page to create your account. You can sign up instantly using your Google account or create a standard email and password login.

Once registered, your dashboard displays your active API key, current balance, and a ready-to-use cURL example. You can issue a new key at any time, which immediately invalidates the old one.

Sign Up with Google

Sign Up with Google

Google sign-up provides an immediate $0.50 trial credit, valid for 7 days. This gives you about 50,000 characters to test the API without payment details.

Email and Password Accounts

Email and Password Accounts

Accounts created with email and password do not receive the trial credit. You must top up to begin generating audio files.

Key Management

Each account has one active key. You can generate a new key from your dashboard at any time; the previous key stops working instantly.

First Request with cURL

Sound wave illustration for: First Request with cURL

Generate audio files directly from your terminal with a single HTTP POST request. This method requires no external libraries, making it ideal for quick validation or lightweight scripts where you just need to convert text into speech instantly.

The API accepts plain text input and returns the synthesized audio file in the format of your choice. It is the most straightforward way to verify your key works before integrating into a larger Python application or WordPress plugin.

POST Endpoint

Send your request to https://api.casicosta.cc/v1/audio/speech using the HTTP POST method. This endpoint handles the synthesis process, taking your text input and converting it into an audio file.

Ensure your request includes the Authorization: Bearer tts-... header with your unique API key. The endpoint processes requests sequentially, so under load, you might experience slight delays in generation time.

  • Endpoint: POST https://api.casicosta.cc/v1/audio/speech
  • Method: POST
  • Content-Type: application/json

JSON Body Structure

The request body must be a JSON object containing the model, input, voice, and response_format fields. The input field accepts up to 4096 characters of text. You can also optionally specify speed (0.25–4.0) and language.

Use tts-1 or tts-1-hd for the model. Both use the same engine and pricing. Select one of the eight voice presets, such as 'aria' or 'milo', to determine the tone of the generated speech.

  • model: "tts-1" or "tts-1-hd"
  • input: string (max 4096 chars)
  • voice: e.g., "aria", "nova"
  • response_format: "mp3", "wav", etc.

Response Format

On success, the API returns the audio file directly in the response body. The file format matches your requested response_format, such as MP3 for web players or WAV for high-quality storage.

If the synthesis fails, you receive an error JSON object with a code and message, and your balance is not charged. Check the Content-Type header to confirm the audio format returned.

Using the OpenAI Python SDK

Sound wave illustration for: Using the OpenAI Python SDK

CodeCaster’s API mirrors the OpenAI speech endpoint structure, allowing you to leverage existing Python tools with minimal configuration. This compatibility means you can integrate realistic audio generation directly into your blog’s content pipeline without learning a new SDK from scratch.

The primary advantage is simplicity: you only need to adjust the base URL in your OpenAI client initialization. This ensures that your existing code logic for handling text inputs and processing audio responses remains largely unchanged, reducing integration time for WordPress and static site generators.

Base URL Configuration

To begin, initialize the OpenAI client by pointing it to the CodeCaster API endpoint. This single change redirects all standard speech requests to our infrastructure while maintaining the familiar request format you already know.

Use the base URL https://api.casicosta.cc/v1. Ensure your API key is passed via the api_key parameter. This setup ensures that all subsequent calls, such as client.audio.speech.create(), are routed correctly to our synthesis engine.

  • Base URL: https://api.casicosta.cc/v1
  • Auth: Pass key via api_key parameter
  • No additional libraries required

SDK Compatibility

The official OpenAI Python SDK works seamlessly because we adhere to the same JSON request shape. Fields like model, input, voice, and response_format are interpreted identically.

This means you can use standard methods like client.audio.speech.create() without modification, aside from the base URL and authentication setup. It supports both tts-1 and tts-1-hd models natively.

Note that while the SDK structure is compatible, features specific to other providers, such as streaming WebSocket connections or SSML parsing, are not supported here. You receive a complete audio file upon request completion.

Code Example

Here is a minimal Python script demonstrating how to generate audio using the OpenAI SDK. It sends a short text and saves the resulting MP3 file to your local directory.

This example assumes you have installed the openai package and configured your environment variable OPENAI_API_KEY with your CodeCaster key. The code handles the request and writes the binary response to disk.

You can modify the voice parameter to try different presets like nova for upbeat content or sage for instructional blog posts. Adjust the speed parameter between 0.25 and 4.0 to match your desired pacing.

Supported Response Formats

Sound wave illustration for: Supported Response Formats

CodeCaster supports five audio formats to suit your WordPress blog’s needs. Choose MP3 for web players, WAV for high-fidelity local storage, or Opus, FLAC, and PCM for specific pipeline requirements. Every generated file includes an inaudible watermark to mark it as synthetic speech.

Selecting the right format ensures optimal balance between quality and file size. Use the response_format parameter in your request to specify your preference. All formats are supported by the standard OpenAI SDK structure, making integration seamless for Python developers.

MP3 for Web Players

MP3 is the ideal choice for embedding audio directly into WordPress posts. It offers a small file size that loads quickly, preventing slow page speeds for your readers. Most modern web players and podcast directories support MP3 natively.

  • Best for blog posts and embedded players
  • Small file size for fast loading
  • Universal compatibility with web browsers

WAV for High Quality

Choose WAV if you need uncompressed, high-fidelity audio for local archiving or editing. This format preserves the full quality of the synthesis engine without lossy compression artifacts. It is perfect for creators who plan to remix or process the audio further.

  • Uncompressed, lossless audio quality
  • Ideal for editing and archiving
  • Larger file size than MP3

Opus, FLAC, and PCM

Opus provides efficient compression, while FLAC offers lossless compression with smaller files than WAV. PCM delivers raw, uncompressed audio data for specialized pipelines. These formats give you flexibility beyond standard MP3 and WAV options.

  • Opus: efficient compression for streaming
  • FLAC: lossless compression
  • PCM: raw, uncompressed audio data

Voice and Language Parameters

Sound wave illustration for: Voice and Language Parameters

CodeCaster provides eight distinct voice presets, ranging from the warm narration of Aria to the deep documentary style of Orion. Each voice is built from licensed recordings, ensuring natural-sounding output for your blog content without needing complex audio engineering.

Selecting a Voice

Choose a voice that matches your tone: use Nova for upbeat updates or Felix for energetic promos. The system supports eight presets, allowing you to vary audio styles across different posts while maintaining a consistent, high-quality synthetic standard.

  • Aria: Warm, clear narrator
  • Nova: Bright, upbeat
  • Luna: Soft, storytelling
  • Sage: Calm, instructional
  • Felix: Energetic, promo
  • Milo: Friendly, conversational
  • Atlas: Neutral, news
  • Orion: Deep, documentary

Setting Language Codes

While the API guesses language from the script, explicitly setting the language parameter ensures accuracy for non-English Latin text. We support 23 languages, including Spanish, German, and Japanese, guaranteeing correct pronunciation across your global audience.

  • Arabic, Chinese, Danish, Dutch
  • English, Finnish, French, German
  • Greek, Hebrew, Hindi, Italian
  • Japanese, Korean, Malay, Norwegian
  • Polish, Portuguese, Russian, Spanish
  • Swahili, Swedish, Turkish

Speed Adjustment

Adjust the speed parameter between 0.25 and 4.0 to control playback rate. This allows you to tighten pacing for quick updates or slow down narration for better comprehension, directly influencing the generation time per character.

Voice and Language Parameters

Rate Limits and Quotas

Sound wave illustration for: Rate Limits and Quotas

CodeCaster’s TTS API enforces a standard rate limit of 60 requests per minute per API key. This cap ensures stable performance for your WordPress blog or content pipeline, allowing you to generate audio files without overwhelming the server during peak publishing hours.

60 Requests Per Minute

Once your account is active, you can send up to 60 synthesis requests every minute. This limit applies to the total number of API calls, regardless of the voice or format selected. For most blog creators, this throughput is sufficient to batch-process articles or podcast scripts efficiently.

Initial Limit for New Keys

New API keys start with a lower limit of 10 requests per minute. This applies until you make your first top-up. After a successful USDT (TRC-20) transfer of at least $5, the limit increases to the standard 60 requests per minute automatically.

  • New keys: 10 requests/minute
  • After first top-up: 60 requests/minute
  • No monthly plans or seats

Queue Behavior

Requests are processed sequentially. If you exceed the rate limit, additional requests may wait in a queue rather than failing immediately. Longer texts take more generation time, so under heavy load, you might experience slight delays. Keep your scripts simple and monitor your usage via the dashboard.

Handling Errors

Sound wave illustration for: Handling Errors

Errors are straightforward because the API returns clear HTTP status codes. If synthesis fails, your balance is not charged, ensuring you only pay for successful audio generation. This makes debugging predictable and cost-effective for your WordPress or blog content pipeline.

Understanding these codes helps you adjust your Python scripts or cURL commands quickly. Common issues usually stem from invalid inputs, rate limits, or network timeouts during queue processing.

Failed Request Refunds

Failed requests are free. If the API returns an error status, the charge is returned in full. You can verify this in your account dashboard under usage history.

Common Error Codes

Use these codes to diagnose issues in your integration: 400 Bad Request (invalid JSON or missing fields), 401 Unauthorized (invalid API key), 429 Too Many Requests (exceeded 60 requests per minute limit), and 500 Internal Server Error (temporary processing issue).

For 429 errors, wait and retry. The API processes requests sequentially, so temporary queues may cause brief delays.

  • 400: Check input length (<4096 chars) and voice name.
  • 401: Verify your Bearer token in the Authorization header.
  • 429: Wait and retry; limits reset per minute.
  • 500: Retry after a few seconds; check status later.

Debugging Tips

Always log the full response body when an error occurs. The API provides a detailed message explaining the exact field that failed validation. For rate limit issues, monitor your key’s request count via the dashboard to adjust your script’s pacing before hitting the 60-requests-per-minute cap.

  • Enable debug logging in your Python SDK client.
  • Check character count before sending large texts.
  • Verify voice names against the /v1/voices endpoint.
  • Ensure correct base_url configuration in your SDK setup.

Data and Privacy

Sound wave illustration for: Data and Privacy

Your input text is used strictly for the purpose of generating the requested audio file and is not utilized for training our models. Once the synthesis is complete, the generated audio is returned directly in the response stream and is not stored on our servers.

We retain minimal request metadata—such as timestamp, character count, and status—solely for accurate billing and usage tracking. This data ensures your account reflects your actual consumption without retaining the content of your creative works.

Input Text Usage

When you send a text payload to the API, it is processed in real-time to produce the audio file. The actual text content you provide is not used for any other purpose, such as improving the model or training future voice generations. Your words remain yours.

Audio Storage

Generated audio files are delivered directly in the HTTP response and are not permanently stored in our cloud storage. You are responsible for saving the audio file to your WordPress media library or local server after receiving it.

Metadata Retention

We keep a record of request metadata, including the time of the request, the number of characters processed, and the status code. This information is retained exclusively to verify your usage for billing purposes and to help debug any issues with your key.

Listen to the 8 voices

Each sample below was generated by this API from the same sentence. However, understanding the underlying processing limits helps you avoid unexpected delays during peak traffic periods.

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. Creative Commons Attribution 4.0
  3. Python documentation
  4. Tether (USDT)
  5. MDN: Web Speech API
  6. openai-node on GitHub
  7. LibriTTS-R corpus (OpenSLR 141)
  8. FFmpeg documentation
  9. TRON developer hub: TRC-20
  10. Node.js documentation
  11. W3C WAI: making audio and video accessible
  12. curl documentation

More on this site