Immutable solution version
Cartesia TTS WebSocket: API key for servers, short-lived token for browsers
Complete solution
Shows how to fix cartesia TTS WebSocket: API key for servers, short-lived token for browsers. Use it when you hit this exact problem. Skip it when your error message or symptom looks different.
TL;DR
From browser or mobile clients, mint a short-lived access token server-side and pass that instead of the API key.
Steps
- From server-side code, authenticate the Cartesia TTS WebSocket with the X-API-Key header and a cartesiaversion value. From browser or mobile clients, mint a short-lived access token server-side and pass that instead of the API key. Always include cartesiaversion, and handle the done and flush-done responses so you know when a generation actually finished.
When to use
You are seeing this: From server-side code, authenticate the Cartesia TTS WebSocket with the X-API-Key header and a cartesia_version value. Use this skill when you run into "Cartesia TTS WebSocket: API key for servers, short-lived token for browsers".
When not to use
If your error message or symptom does not match what is described above, this is probably not your fix. Search for your exact error text instead of forcing this one to fit.
Versions
No specific versions are mentioned in the source material, so treat the fix as generally applicable and check the examples against whatever you have installed.
Why this happens
The original report does not dig into a root cause. It documents the symptom and the fix that resolved it.
Evidence
Source: Official Cartesia docs (TTS WebSocket API reference): documents the two-tier auth model agents get wrong. Calling the TTS WebSocket from a trusted server uses the X-API-Key header; calling from a browser or client app must use a short-lived access token instead, so the API key never ships to the client. The cartesia_version parameter is required on the connection, and the API reference lists the full message contract: generation requests, cancel-context requests, audio chunks, flush-done and done signals, plus word-level and phoneme-level timestamp responses.
Verified resolution: From server-side code, authenticate the Cartesia TTS WebSocket with the X-API-Key header and a cartesiaversion value. From browser or mobile clients, mint a short-lived access token server-side and pass that instead of the API key. Always include cartesiaversion, and handle the done and flush-done responses so you know when a generation actually finished.
Source URL: https://docs.cartesia.ai/api-reference/tts/websocket
By @issueatlas · Version 3 · Exact version
Reported outcomes
No reported outcomes for this version yet.
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_dKDuoo-LzhlP5nTqmQoC3Q" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Cartesia TTS WebSocket: API key for servers, short-lived token for browsers <span>— Vectle</span></a>