Skip to main content
WSS
The WebSocket TTS endpoint enables bidirectional streaming for low-latency text-to-speech generation with MessagePack serialization.
The request payload inside StartEvent uses the same parameters as the HTTP Text to Speech API. For more detailed field guidance, model-specific behavior, and examples, see that page. In WebSocket mode, request.text is typically empty in StartEvent, and the text content is sent through subsequent TextEvent messages.
To connect directly from a browser, mobile, or desktop client without exposing your sk-fish- API key, mint a single-use ek-fish- token with tts:write and pass ["bearer", token] as the WebSocket subprotocol. Because browser WebSocket connections cannot send custom headers like model, browser-direct sessions use the default model (s2.1-pro); relay through your server or use HTTP fetch with CORS when you need a specific model header. See Ephemeral Tokens for Browsers and Client Apps.
bearerAuth
type:http

API key authentication using Bearer token.

Get your API key from https://fish.audio/app/api-keys

Pass the token in the Authorization header: Authorization: Bearer YOUR_API_KEY

headers
type:object
model
type:enum

TTS model to use for this session. If omitted or set to an unrecognized value, the session falls back to s2.1-pro. Use s3-pro, s3-pro-free, an S2.1-Pro model, or s2-pro for multi-speaker dialogue synthesis. s1 is deprecated and will be retired on December 31, 2026. After that date, requests that specify s1 are served by s3-pro.

Available options: s1, s2-pro, s2.1-pro, drama-3, s3-pro, s3-pro-free
Start TTS Session
type:object

Initiates a TTS streaming session with configuration.

This must be the first message sent after connecting. It contains all the configuration for voice, audio format, and generation parameters.

The request payload uses the same fields as the HTTP TTS API. In WebSocket mode, request.text is typically empty in the StartEvent and the actual text is streamed through subsequent TextEvent messages.

For full parameter details, examples, and model-specific guidance, see the HTTP Text to Speech API.

Send Text Chunk
type:object

Sends a chunk of text for synthesis.

You can send multiple TextEvent messages in sequence. The server will buffer and synthesize text according to the chunk_length parameter from StartEvent.

Flush Buffered Text
type:object

Forces immediate synthesis of all buffered text.

Use this when you want audio generated immediately without waiting for more text or for the buffer to fill up. Useful for ensuring low latency in interactive applications.

End TTS Session
type:object

Signals the end of the text stream.

After sending this event, the server will finish synthesizing any remaining buffered text and send a FinishEvent. The connection stays open.

Audio Chunk
type:object

Contains generated audio bytes.

You will receive multiple AudioEvent messages as audio is generated. Each message contains a chunk of audio in the format you specified. Concatenate all chunks to get the complete audio.

Session Complete
type:object

Signals that the TTS session has completed.

  • If reason='stop', synthesis completed successfully
  • If reason='error', an error occurred (client should handle gracefully)

After a session that completed (reason='stop'), the WebSocket connection stays open. To run another session, send a new StartEvent on it. When you no longer need the connection, close it with code 1000. An open connection between sessions does not count against your concurrency limit.

Request Error
type:object

Reports a request-level failure. After an invalid StartEvent, a missing voice reference, or another error in what you sent, the session ends but the socket stays open, so you can send another StartEvent. After a concurrency refusal the socket closes, and a server-side failure can close it too.