Skip to main content

When to use

  • Low-latency voice-to-voice with natural barge-in.
  • Prompts, voice, and turn detection configured inline per session via an ephemeral OpenAI client secret.
  • You don’t want to run a separate agent runtime.
For Cartesia Line-managed agents, see Cartesia. For backend-driven scripted speech, see Legacy text-echo.

Prerequisites

  • OpenAI API key with Realtime API access. Only the GA version is supported — the beta is not.
  • Avaturn API key (dashboard).

1. Mint a client secret

On your backend, exchange your OpenAI API key for a short-lived client secret. Avaturn uses this secret to open the Realtime WebSocket on the user’s behalf.
Mint a fresh secret per user session. The default lifetime is 600 seconds (max 7200). The secret governs token issuance — an existing WebSocket continues working after the secret expires.

2. Create an Avaturn session

Response:
  • session_id — backend handle (terminate, telemetry)
  • token — short-lived credential for the Web SDK
Optional session fields: avatar_id, background, render_model (avatar render preset, not the LLM), user_absent_timeout (default 60s, min 10), max_duration (default 3600s, max 86400). See the API reference.

3. Connect from the frontend

Configuring the agent

The session object you pass to client_secrets.create() is applied to the WebSocket Avaturn opens on the user’s behalf — full control over instructions, voice, VAD, and transcription.

Instructions and voice

OpenAI currently recommends marin and cedar voices for best quality. Other supported values: alloy, ash, ballad, coral, echo, sage, shimmer, verse.
User transcripts require audio.input.transcription. Without it, OpenAI doesn’t emit transcription events and Avaturn has nothing to forward to the SDK. Avatar response transcripts (assistant side) flow regardless.

Stored prompts

Full configuration surface (turn detection variants, transcription, audio params): OpenAI session reference.

Engine behavior

  • Audio. 24 kHz mono PCM in both directions.
  • Interruptions. OpenAI server VAD (or semantic VAD, if configured). When the user starts speaking, Avaturn discards in-flight avatar audio.
  • Transcripts. Assistant transcripts (response.output_audio_transcript.done) flow by default. User transcripts (conversation.item.input_audio_transcription.completed) flow only when audio.input.transcription is configured. Both are forwarded to the SDK via ce_events.realtime.*.
  • Tools. Tool definitions sent in the session config are parsed by OpenAI, but Avaturn doesn’t surface response.function_call_arguments.* events to the Web SDK nor relay function results back. Tool calls won’t execute end-to-end — avoid them at this layer until proper support lands.
  • GA only. Beta or mixed beta/GA usage causes a session_lifecycle_error with code openai-realtime-version-mismatch. See beta-to-GA migration.

Session lifecycle

A session ends on any of:
  • Explicit DELETE /api/v1/sessions/{session_id}
  • user_absent_timeout elapses with the user disconnected (default 60s)
  • max_duration cap reached (default 3600s, max 86400s)
Call avatar.dispose() on the frontend to tear down the local SDK state. The backend session terminates as described above — dispose() does not directly close it. Don’t try to resume a session after it ends; mint a new client secret and create a fresh session.

Reference