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://api.agtcloud.cn/v1/live/sessions/{session_id}/attachConnection parameters
Configuration updates
Update only background configuration in the same delegation mode. Wait for session.updated before using the new configuration.
Connection flow
- First create a WebRTC session and save the complete
session.id. - Connect attach on the same API address using the same account and API Key that created the session.
- Continuously receive transcripts and background events. After sending a control command, wait for its acknowledgment or error.
- To disconnect attach only, close this WebSocket. To end the entire voice session, send
session.closeand wait forsession.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
| Category | Main events |
|---|---|
| Background configuration | session.update, session.updated |
| Background responses | response.item.create, response.create, response.event, session.delegation.created |
| Context | session.instructions.append, session.thinking.append, session.commentary.append and their acknowledgments |
| Transcripts and media state | session.input_transcript.delta, session.output_transcript.delta, session.paused, session.resumed |
| Usage and closing | session.usage.updated, session.close, session.closed, error |
session.update
Update background configuration within the same delegation mode; wait for session.updated.
Reconnection and event handling
| Scenario | Resolution |
|---|---|
| Attach reconnection | May replay events from approximately the last 3 seconds. Deduplicate using existing event_id values; this is not full history recovery |
| Receiving on multiple channels | DataChannel and attach may receive the same event; only one should execute tools or application side effects |
| Background responses | Correlate Responses terminal states, tool results and usage using response.id. Do not rerun completed tasks |
| Reflected audio | session.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 failure | Correlate 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
| Symptom | Resolution |
|---|---|
| Cannot attach to the session | Check the full session ID, creating account and token, and whether the session is still active |
| Update rejected | Keep the original delegation mode. When supplying delegation, include its original type and change only allowed background fields |
| Speech continues after closing | Closing attach disconnects only the control channel. Send session.close to end speech |
| Duplicate events received | Deduplicate non-empty event_id values; this rule does not apply to reflected audio |