The cartesia provider implements
Speaker
(text-to-speech) only. Cartesia's Sonic family is built around
real-time conversational synthesis with first-token latencies in
the ~40 ms range — choose this provider when end-to-end latency is
the critical constraint.
With no WithBaseURL override, the provider targets
https://api.cartesia.ai. TTS requests go to
{BaseURL}/tts/bytes for non-streaming and
{BaseURL}/tts/sse for streaming (SSE).
WebSocket streaming
(wss://api.cartesia.ai/tts/websocket) is on the
v0.4 roadmap;
v0.3 streams via SSE which is sufficient for most server-side
pipelines.
Authentication is via the X-API-Key header. Cartesia
also requires a Cartesia-Version header pinned to a
stable API version; the provider sets a sensible default
(currently 2024-11-13) and will be bumped as Cartesia
publishes new versions.
Models
sonic-2 — current production model. 15 languages,
sub-100 ms first-token latency, the recommended default.
sonic-2-2025-03-07 — pinned snapshot of
sonic-2. Use this when you need reproducible output.
sonic-turbo — even lower latency for English-only
use cases. Slightly lower quality.
Voice IDs
Cartesia voices are referenced by UUID-shaped IDs. Pass the ID
string in SpeechRequest.Voice. A handful of public
voice IDs from Cartesia's library (subject to change):
Voice
ID
Newsman
d46abd1d-2d02-43e8-819f-51fb652c1c61
Casual British woman
156fb8d2-335b-4950-9cb3-a2d33befec77
Friendly Australian man
421b3369-f63f-4b03-8980-37a44df1d4e8
For custom-trained voices, use the voice ID returned by
Cartesia's voice-cloning endpoint. The library does not wrap voice
management — call the Cartesia REST API directly for that.
Output format mapping
Cartesia uses an output_format object with
container, encoding, and
sample_rate. The library maps
SpeechRequest.Format as follows:
Cartesia's defining property is first-token latency low enough for
barge-in voice agents. The end-to-end pattern looks like:
Chat provider emits a delta chunk.
You buffer until a sentence boundary or N characters.
You call Speak with Stream=true and pipe the audio to the client (WebRTC / WebSocket / phone).
If the user interrupts, cancel both the chat Stream and the audio AudioStream via context.
Cancellation propagates: cancelling the audio context closes the
Cartesia HTTP request, which stops billing immediately.
Speed and emotion
SpeechRequest.Speed maps to Cartesia's
speed field (range -1.0 to
1.0; the library rescales 0.5..2.0 to
that range). Emotion controls are not on the typed surface; pass
them via Raw:
WebSocket streaming lands in v0.4. The SSE path
is sufficient for server-side use; WebSocket matters for
browser-direct streaming where every millisecond of handshake
counts.
API version header. Cartesia versions its API
via a header rather than a path prefix. The provider sets the
header; if Cartesia ships a breaking change, bump
llmrouter.