Realtime API (Alpha)
Start a native voice conversation in Service with OpenAI, Azure OpenAI, Gemini Live, or xAI over WebRTC or WebSocket PCM.
Service Realtime connects a client to an Agent with a native live model. Audio and text share one conversation with the Agent's tools and history. The API is Alpha; clients should allow additive fields and new event types.
Start a conversation
Select a Model with a realtime calling API as the Agent's primary model. From your backend, use a workspace API key with run access. Fetch capabilities, then request a single-use ticket:
curl -fsS "${A13N_SERVICE_URL%/}/api/v1/realtime?agent_id=$AGENT_ID" \
-H "Authorization: Bearer $A13N_API_KEY"
curl -fsS "${A13N_SERVICE_URL%/}/api/v1/realtime/sessions" \
-H "Authorization: Bearer $A13N_API_KEY" -H 'Content-Type: application/json' \
-d "{\"agent_id\":\"$AGENT_ID\",\"transport\":\"websocket\"}"Check can_start and transports before creating a ticket. Availability also reports PCM sample rates, the configured maximum duration and whether the model supports manual interruption. Check accepts_images, supported_image_types and max_images_per_input for the selected model's image attachment support.
Pass only the ticket response to the media client. Redeem the ticket within expires_in (30 seconds) by connecting to websocket_path on the Service origin. Offer the protocol and ticket, in that order:
const endpoint = new URL(ticket.websocket_path, serviceOrigin);
endpoint.protocol = endpoint.protocol === "https:" ? "wss:" : "ws:";
const socket = new WebSocket(endpoint, [ticket.subprotocol, ticket.ticket]);
socket.binaryType = "arraybuffer";
socket.onmessage = ({ data }) => {
if (typeof data !== "string") return; // Play PCM at audio_output_hz.
const event = JSON.parse(data);
if (event.type === "ready") {
socket.send(JSON.stringify({ type: "text", text: "What can you do?" }));
}
};The ticket returns session_id, thread_id, and run_id. The accepted frame confirms Run creation. Wait for ready before sending text or media; the ticket connection needs no separate start frame. To hang up, send {"type":"stop"} and stop local media immediately. sealed confirms the Run’s final status. If the connection closes first, read GET /api/v1/runs/{run_id} before reconnecting.
Continue or branch a conversation
Send agent_id in the ticket request and choose where to start the call:
| Goal | Ticket request fields |
|---|---|
| Start a new conversation | Omit thread_id and fork_run_id. Use draft for opening text, memory for session memory settings, and memories and environments for initial thread mounts. |
| Continue the conversation | Pass the existing thread_id to continue saved history once the thread is open and idle. Include that ID when checking availability. |
| Branch from an earlier call | Pass the sealed realtime run’s ID as fork_run_id and its original agent_id. The branch starts a new thread in the same session and inherits history, the agent revision, and run options from the source run. |
An idle thread can alternate ordinary text runs and realtime calls. For the call, select a revision with a realtime primary model or set options.overrides.model to the realtime model key in the ticket request. For an override, pass the same key as model in the availability query. Select a non-realtime model when switching back to an ordinary text run. Set audio: false with WebSocket for text or supported images as input and spoken replies as output; WebRTC requires audio input.
Attach images to a voice call
Attach images before a call or while it is active, with or without text. The Console offers attachments when the selected model supports them:
- OpenAI Realtime and Azure OpenAI Realtime: up to four JPEG or PNG images per message.
- Gemini Live: one JPEG per message, because a typed turn can pick up only the most recent frame.
- GPT-Live and Grok Voice: no attachments. The GPT-Live adapter does not send the typed question and image to the visual backend together.
Each image can be at most 4 MiB. The deployment's upload limits also apply.
API clients read accepts_images, supported_image_types, and max_images_per_input from GET /api/v1/realtime. Upload each file with POST /api/v1/uploads and promote it with POST /api/v1/assets. Pass the asset IDs in the ticket's draft_asset_ids for the opening draft. During the call, send {"type":"input","text":"What do you see?","asset_ids":["ast_…"],"respond":true} over the WebSocket. Omit text for an image-only message. respond defaults to true; set it to false to add input without requesting a reply. Text fields accept up to 8,192 characters. An invalid_argument frame with recoverable: true means the input was rejected and you can correct it without reconnecting.
Choose a provider and transport
| Model API | Provider | Voice transports | PCM input / output | Verification in Service |
|---|---|---|---|---|
openai.realtime | OpenAI Realtime | WebRTC, WebSocket PCM | 24 / 24 kHz | Upstream adapter and deterministic tests |
openai.live | OpenAI GPT-Live | WebRTC, WebSocket PCM | 24 / 24 kHz | Upstream adapter and deterministic tests |
azure.realtime | Azure OpenAI Realtime | WebRTC, WebSocket PCM | 24 / 24 kHz | Upstream adapter and deterministic tests |
google.realtime | Google Gemini Live | WebSocket PCM | 16 / 24 kHz | Upstream adapter and deterministic tests |
xai.realtime | xAI Grok Voice | WebSocket PCM | 24 / 24 kHz | Upstream adapter and deterministic tests |
The matrix reports verification with fake transports and adapters; it does not report live vendor calls. Verify the model and transports you intend to deploy with your own provider credentials.
- WebSocket PCM: Send and receive mono signed 16-bit little-endian PCM as binary frames. Each input frame must contain whole samples and be at most 16 KiB. Resample capture at
ready.audio_input_hzand play output atready.audio_output_hz. The legacyready.audio_hzalias always means output. Useready.supports_interruptionto decide whether to offer manual interrupt. - WebRTC: Create an audio-only
RTCPeerConnection. Ticketice_serverscan supply STUN or TURN configuration; omit entries with no optional username or credential when building the browser configuration. Send the local SDP as{"type":"offer","sdp":"…"}within 10 seconds of WebSocket acceptance (up to 32,768 characters), and applyanswer.sdp. Wait for bothreadyand the peer connection before starting audio. The browser negotiates its media format independently of the PCM rates reported by Service.
Provider credentials stay in Service. Use official endpoints: api.openai.com, api.x.ai, generativelanguage.googleapis.com, or the Azure OpenAI resource_endpoint on *.openai.azure.com. Use the provider’s API key (with the default Bearer authentication for OpenAI). Realtime calls do not accept custom gateways, additional headers, or session-affinity headers. Leave base_url unset for Azure (use resource_endpoint) and Gemini (use the default endpoint).
Handle subtitles, approvals, and barge-in
- Subtitles: Use
transcriptframes to update subtitles bymessage_idandrole(userorassistant). Replace the current text withtext;final: truemarks a finished transcription. After the call, read the saved transcript from the run’s display items. - Tool approvals: Show the tool
nameandarguments(a string) fromapproval_required. Return{"type":"approval","call_id":"…","approve":true}or setapprovetofalse. Dismiss the prompt after sending the decision or receivingapproval_expiredfor thatcall_id. Clear all prompts when the connection ends and use the recorded tool outcome to check what executed. - PCM barge-in: Track the byte offset of each output binary frame from zero, including frames you discard locally. After an output gap,
playback_position.offsetsets the next frame’s starting offset. Stop playback and discard queued audio on interruption, then send{"type":"interrupt","played_bytes":6000}(for example, if the device played 1,200 bytes of the frame starting at 4,800). Wait forinterruptedbefore playing new audio. Models that support truncation use the position to keep the portion already played. - WebRTC barge-in: Mute local playback and send
{"type":"interrupt"}. Unmute onplayback_startfor new speech, or onplayback_endif the provider continues the interrupted reply (for example, GPT-Live). Theinterruptedframe acknowledges handling. Clients can react to serverbarge_inwhen it detects speech onset or receives a provider interruption, and useready.supports_interruptionto decide whether to show a manual interrupt button.
Handle limits and failures
The ticket returns the effective max_duration_seconds. Omit the request field to use the server maximum (30 minutes by default), or request at least 30 seconds up to that maximum. The timer starts when the provider connection opens. A cap over 60 seconds triggers one limit_warning with remaining_seconds: 60. Service defaults to five minutes of conversational inactivity; speech, text, tool work and approval decisions count as activity. Ongoing foreground tool work and approval prompts suspend idle expiry. Operators can set worker.realtime_idle_seconds to 0 to disable idle expiry. Where applicable, set options.max_usage.requests to cap model requests.
ending tells the client to stop capture and playback while Service saves the Run. Inspect sealed.status, sealed.reason when present, and the code on error frames. During a rollout, also watch for a draining frame with code: "worker_draining":
| Code or reason | Client action |
|---|---|
duration_limit, idle_timeout | The run ended as completed. Start a new call on the same thread to resume. |
usage_limit_exceeded, authority_revoked | Wait for budget or access to change before starting again. |
invalid_argument | Correct the request or frame. If the error frame has recoverable: true, correct the input on the same connection. |
realtime_transport_failed, worker_draining | Check the Run and Thread, then obtain a new ticket with backoff. |
realtime_unavailable | Recheck availability and Service or provider readiness. |