OpenAI SDK (compatible)

Shunya Labs' TTS API is OpenAI-compatible. You can use the official OpenAI Python SDK by pointing base_url to the Shunya Labs endpoint, no other client changes needed.

Why this is useful

  • You're already using openai.audio.speech.create() and you want to switch to Shunya without rewriting your call sites.
  • You want to A/B test voices across providers from one client interface.
  • Your team standardised on the OpenAI SDK and prefers not to maintain a second SDK.

Drop-in code sample

python
from openai import OpenAI

client = OpenAI(
    api_key="YOUR_API_KEY",
    base_url="https://tts.shunyalabs.ai/v1",
)

response = client.audio.speech.create(
    model="zero-indic",
    input="Hello, how are you today?",
    voice="Varun",
    response_format="mp3",
)

response.stream_to_file("output.mp3")

Field mapping

The OpenAI Python SDK's audio.speech.create() arguments map cleanly onto Shunya's POST /v1/audio/speech body:

OpenAI SDK argumentShunya fieldNotes
modelmodelUse "zero-indic".
inputinputThe text to synthesize. Up to 10,000 characters.
voicevoiceAny of the 46 Shunya voices, see Voices & languages.
response_formatresponse_formatmp3, wav, pcm, ogg_opus, flac, mulaw, alaw.

What you keep when you switch

  • The OpenAI client's retry / timeout / streaming helpers.
  • Standard response.stream_to_file(), response.iter_bytes() patterns.
  • Same error types your code already catches.

What you give up

The OpenAI SDK only exposes the parameters in the OpenAI spec. Shunya-specific parameters, voice cloning (reference_wav, reference_text), speed, language, trim_silence, volume_normalization, background_audio, word_timestamps, max_tokens: aren't accepted by the OpenAI SDK signature. To use those, switch to the Shunya Python SDK or call the REST endpoint directly.

Streaming via the OpenAI SDK
For real-time / streaming synthesis, use Shunya's WebSocket endpoint at wss://tts.shunyalabs.ai/ws/v1/audio/speech: that path is not OpenAI-compatible. See TTS streaming.

Source: Shunyalabs TTS Developer Documentation v1.0 (March 2026), §2.2 Your First Request → "OpenAI Python SDK (compatible)". Code reproduced verbatim.