AGTCloud API Docs
GuidesAPI ReferenceIntegrations and resourcesUpdate and help
RealtimeGPT-Live Realtime Voice

WebSocket connection

Send audio over WebSocket and receive speech, transcripts and session events.

After connecting, send session.start and wait for session.started before sending audio. Specify the model in the startup configuration, not URL query parameters. Keep long-lived API Keys on the server.

WSS
wss://api.agtcloud.cn/v1/live/sessions

Connection parameters

Startup configuration

Place this configuration in the session object of the first session.start. Wait for session.started before sending audio.

Session flow

  1. Connect the main WebSocket with a Bearer API Key.
  2. Send session.start to configure the voice model, instructions, audio and delegation mode.
  3. After session.started, send session.input_audio.append and continuously process transcripts and audio.
  4. When finished, stop audio production, send session.close and wait for the final close event.

Prepare audio

EncodingInput and output requirements
audio/pcmMono, 16-bit little-endian, sample rate 16000 or 24000; no WAV header
audio/pcmu, audio/pcmaMono G.711, sample rate 8000

Input and output use the same startup encoding. The Node.js example sends 4800 bytes of 24 kHz PCM every 100 ms and saves output to reply.pcm. The Python example only checks startup and closing.

ffmpeg -i input.wav -f s16le -acodec pcm_s16le -ac 1 -ar 24000 audio.pcm
ffplay -f s16le -ar 24000 -ac 1 reply.pcm

The Node.js example requires ws; the Python example requires websocket-client. Supply the key through the API_KEY environment variable.

Event Reference

This endpoint uses JSON events and Base64 audio, not OpenAI Realtime input_audio_buffer.*. Filter by direction, category or event name below; inspect fields on the left and copy examples on the right.

CategoryMain events
Sessionsession.start, session.started, session.update, session.updated, session.close, session.closed
Audio and transcriptssession.input_audio.append, session.output_audio.delta, session.input_transcript.delta, session.output_transcript.delta
Context and delegationsession.instructions.append, session.thinking.append, session.commentary.append, session.delegation.created, response.item.create, response.create, response.event
Usage and errorssession.usage.updated, error, info
Event direction
Category
Event

session.start

First command on the main WebSocket; wait for session.started before sending audio.

Configuration and delegation

ConfigurationUsage
Foreground voicemodel, instructions and audio are fixed after startup. Append instructions with session.instructions.append
client delegationDefault mode; the application handles delegated tasks. Reference the corresponding delegation_id when appending results
responses delegationSupply the background responses.model at startup, separately from the voice model. Update background configuration with session.update; the delegation mode cannot change
Append contextEach appended instructions, thinking or commentary content is limited to 500 tokens. Set delegation_id to null for general context and Responses mode
Fixture audio playbacksession.output_audio.fixture.play plays up to 30 seconds of mono PCM16LE/24 kHz audio. Input is discarded and context appends are rejected during playback

Usage and ending the session

session.usage.updated is a cumulative snapshot; do not sum snapshots. To end the entire session, send session.close, wait for session.closed, and save final usage before releasing the connection. A voice turn ending does not require closing the session.

Voice sessions, background Responses and tool calls may be billed separately. See Model catalog for pricing.

Common issues

SymptomResolution
Handshake failureCheck the address, Bearer API Key and model access; the path is /v1/live/sessions
Startup failureUse session.start as the first command and wait for session.started before sending other events
No sound or distorted audioCheck encoding, sample rate, byte order, channels and WAV headers
Instruction update rejectedsession.update updates only allowed background delegation configuration; use append events for foreground instructions
Connection ended unexpectedlySave the session ID, error and last usage snapshot; do not automatically replay sent audio or tool tasks