Skip to main content

Text-to-Speech

Generate audio from text. PolarGrid serves kokoro-82m (preset voice catalog) and tada-3b-ml (voice-cloning). The endpoint returns audio in the container format requested via response_format — supported values are pcm, wav, and mp3.
Edge endpoints accept your pg_* API key as a bearer token. See Authentication for details. The cURL examples below pin Toronto (yto-01) for concreteness — substitute another region or discover the fastest one via GET https://autorouter.polargrid.ai/v1/route. See API Overview for both patterns.

Create Speech

Generate audio from input text.

Request Body

The gateway returns 400 Bad Request if input is empty/whitespace-only, voice is empty, or response_format is anything other than pcm, wav, or mp3. Synthesis failures (invalid voice ID, upstream error) return 502 Bad Gateway — never an empty 200.

Input length limits

input length is capped per model and enforced before synthesis; over-limit requests return 413 Payload Too Large with a message naming the model and its limit (e.g. Input too long: maximum 850 characters for tada-3b-ml). The limit is applied after the gateway strips surrounding quotes and code/markdown artifacts, so it counts the text actually synthesized.
tada-3b-ml has a lower limit because longer inputs can exhaust GPU memory mid-synthesis. The 850-character cap is a deterministic, documented contract that keeps identical requests behaving identically regardless of server load. Split longer text into multiple requests and concatenate the audio client-side.

Voices

tada-3b-ml is a voice-cloning model — see the model page for how to provide a reference voice; it does not use the preset voice IDs below. The kokoro-82m model exposes eight preset voices through the PolarGrid SDKs: See the Voice AI guide for how these map to Kokoro-82M and a link to the full upstream voice list.
TADA output is deterministic. tada-3b-ml uses diffusion-based synthesis with a fixed random seed, so the same input text + same voice reference always produces byte-identical audio. This is by design — the fixed seed guarantees consistent voice identity and timing across requests, which matters for voice-agent pipelines where prosody shifts between calls would be jarring. There is no server-side cache: every request runs full inference and is billed accordingly, even when the output matches a previous call. A user-controllable seed parameter is planned for a future API version to let callers introduce deliberate prosody variation.

Audio Format

Audio is generated at 24 kHz, 16-bit, mono. The container is chosen by response_format: PCM is the lowest-latency choice and the recommended format for real-time voice-agent pipelines. Pick wav if you need a playable file with no client-side post-processing, or mp3 if bandwidth matters more than first-byte latency.
REST and SDK defaults differ. Raw HTTP requests to /v1/audio/speech default to audio/pcm (headerless 24 kHz 16-bit LE samples) when response_format is omitted. The PolarGrid JavaScript and Python SDKs default batch requests to mp3 and streaming requests to opus for OpenAI-style behavior. If you switch between raw curl/HTTP and an SDK without setting response_format explicitly, you will get different audio containers. Always pass response_format to get deterministic output regardless of calling method.
opus, aac, and flac from the OpenAI spec are not yet supported in batch mode — requesting them returns 400. For streaming, opus is supported (see below); for batch, transcode PCM client-side if you need one of those:

Streaming

Pass stream: true to receive chunked audio over a single HTTP response — first bytes typically arrive in under 300 ms, well before synthesis finishes. The PolarGrid SDKs default streaming requests to response_format: 'opus'; raw HTTP callers get pcm when response_format is omitted (the gateway’s lowest-latency default). Streamable formats: Streaming wav or mp3 returns 400 Bad Request. Streamable models:
TADA streaming: speed must be 1.0. The tada-3b-ml model does not support speed values other than 1.0 in streaming mode. Setting any other value (e.g., speed: 1.5) returns a 400 Bad Request error from the gateway. If you need speed control with TADA, use batch mode (stream: false) instead.
Response headers:
  • X-Polargrid-Stream: 1 — set on every streaming response.
  • X-Polargrid-Sample-Rate: 24000 — PCM sample rate; Opus is resampled to 48 kHz inside the Ogg container.

Detecting truncated streams

A mid-stream Triton or upstream failure closes the connection cleanly — there is no in-band error frame. Clients observe one of:
  • A ReadError / IncompleteRead / ChunkedEncodingError raised by the HTTP client.
  • For opus, an Ogg stream that never sees the end-of-stream flag on its final page.
Treat any of these as a synthesis failure and retry. The PolarGrid SDKs surface these as exceptions from the async iterator; they do not silently terminate.

Streaming example

Not supported in v1:
  • Cartesia-compatible WebSocket TTS (wss://api.cartesia.ai/tts/websocket shape). PolarGrid streaming TTS uses chunked HTTP only. Customers porting from Cartesia must swap the transport layer.
  • WebSocket TTS endpoint of any kind. There is no /v1/audio/speech/ws. PolarGrid exposes WebSockets only for completions (/v1/completions/ws) and PersonaPlex’s full-duplex voice pipeline.
  • Streaming WAV and MP3. WAV requires the full sample count for its RIFF header; MP3 frame alignment can’t hit sub-300 ms TTFB. Request pcm or opus for streaming.
If your existing pipeline depends on any of the above, file a request in the PolarGrid roadmap.

Example Request

Response

Returns the requested container as a binary body, with Content-Type set to audio/pcm, audio/wav, or audio/mpeg to match response_format. See Streaming above for the streaming TTS contract, supported formats and models, and code samples.