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

WebRTC server control

Attach to an existing WebRTC session to receive events and control background processing.

Create a sideband WebSocket using session.id from the create response. The browser keeps its WebRTC audio tracks; the server receives events, updates background configuration or ends the session. Attach does not create a new session or send session.start.

WSS
wss://api.agtcloud.cn/v1/live/sessions/{session_id}/attach

Connection parameters

Configuration updates

Update only background configuration in the same delegation mode. Wait for session.updated before using the new configuration.

Send only delegation fields to update. Omitted fields are retained; arrays are replaced entirely. Foreground model, instructions, audio, input and client cannot be reset.

Connection flow

  1. First create a WebRTC session and save the complete session.id.
  2. Connect attach on the same API address using the same account and API Key that created the session.
  3. Continuously receive transcripts and background events. After sending a control command, wait for its acknowledgment or error.
  4. To disconnect attach only, close this WebSocket. To end the entire voice session, send session.close and wait for session.closed.

This endpoint attaches only to active WebRTC sessions created by the platform, not main WebSocket sessions. Native browser WebSocket cannot set arbitrary Authorization Headers. Use the server examples below and never put the key in the URL.

Event Reference

CategoryMain events
Background configurationsession.update, session.updated
Background responsesresponse.item.create, response.create, response.event, session.delegation.created
Contextsession.instructions.append, session.thinking.append, session.commentary.append and their acknowledgments
Transcripts and media statesession.input_transcript.delta, session.output_transcript.delta, session.paused, session.resumed
Usage and closingsession.usage.updated, session.close, session.closed, error
Event direction
Category
Event

session.update

Update background configuration within the same delegation mode; wait for session.updated.

Reconnection and event handling

ScenarioResolution
Attach reconnectionMay replay events from approximately the last 3 seconds. Deduplicate using existing event_id values; this is not full history recovery
Receiving on multiple channelsDataChannel and attach may receive the same event; only one should execute tools or application side effects
Background responsesCorrelate Responses terminal states, tool results and usage using response.id. Do not rerun completed tasks
Reflected audiosession.input_audio.append and session.output_audio.delta are PCM16LE/24 kHz copies without event_id; they do not indicate actual model consumption or completed device playback
Control failureCorrelate commands with client_event_id. After a timeout, check state first; do not automatically replay creation or tool execution

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
Cannot attach to the sessionCheck the full session ID, creating account and token, and whether the session is still active
Update rejectedKeep the original delegation mode. When supplying delegation, include its original type and change only allowed background fields
Speech continues after closingClosing attach disconnects only the control channel. Send session.close to end speech
Duplicate events receivedDeduplicate non-empty event_id values; this rule does not apply to reflected audio