- The Python SDK (
client.beta.realtime.transcription()), which handles the WebSocket, reconnection, and audio replay for you. Use this for most applications. - The raw WebSocket protocol, for languages other than Python or when you need full control over the wire.
Python SDK
The Python SDK for real-time transcription is in beta, and the API surface may change before it stabilizes. Share feedback with [email protected].
realtime extra:
Basic usage
Callclient.beta.realtime.transcription() to open a session, feed audio with session.append(), and consume events by iterating the session. Each TranscriptDelta is an interim result that updates while a phrase is being spoken; each TranscriptCompleted is the finalized transcript for one utterance.
session.append() never blocks on network state, so it is safe to call from a capture loop. Instead of iterating the session, you can pass an event_callback= function to handle events as they arrive.
Audio format
Audio in is 16 kHz mono 16-bit PCM (pcm_s16le_16000). Resample your source before appending. Passing sample_rate= lets the SDK reject a mismatch loudly instead of silently transcribing the wrong sample rate.
Utterance boundaries
Utterance boundaries are detected server-side by default. Final transcripts arrive on their own as the speaker pauses. To control segmentation yourself, passturn_detection={"type": "none"} and call await session.commit() when each segment ends.
Session events
Iterate the session (or passevent_callback=) to receive normalized events. Import them from together.realtime.
TranscriptDelta and TranscriptCompleted may also include optional quality fields when the server sends them: logprobs (avg_logprob, token_logprobs, token_texts) and tokens (per-token token_id, text, and confidence).
Reconnection and replay
When the connection drops, the session emitsReconnecting and Reconnected events and retries on its own. By default the SDK makes up to two same-endpoint reconnect attempts (reconnect={"max_attempts": 2}) before raising. Transcripts recomputed from speech carried across the reconnect are marked replayed=True and may overlap text you already received. Voice agents that act on each final result can set buffer={"max_replay_seconds": 0} to resume live with no re-emission instead.
Failover across endpoints
If an endpoint fails for good, calls raiseRealtimeConnectionError. When the server reports it cannot currently serve (exc.code == "no_healthy_workers", including WebSocket close code 4503), the SDK raises immediately with no same-endpoint retry so you can rotate. To keep a conversation alive across endpoint outages, run a failover ring: on failure, session.pending_audio() hands you the un-transcribed speech to seed a new session on another endpoint.
Synchronous usage
Together().beta.realtime.transcription(...) mirrors the async API on a background thread. Use it for a handful of concurrent sessions. For high concurrency, use the async client.
Key parameters
For full manual control over the raw wire events with no automatic recovery, use
client.beta.realtime.connect().
Raw WebSocket protocol
Use the raw WebSocket protocol from languages other than Python, or when you need full control over the wire. The SDK above wraps this same protocol.Establish a connection
Connect to:wss://api.together.ai/v1/realtime?model={model}&input_audio_format=pcm_s16le_16000
Headers: