Com tecnologia deChatGPTClaudeGoogle Gemini
Funciona comGoogle DriveDropboxOneDrive

Reference

Voice agent session reference

Every client and server event in a voice agent session, with payload shapes and close codes.

Voice agent sessions speak JSON text frames in both directions; binary WebSocket frames are ignored. Every frame has a type field, and audio travels base64-encoded inside the JSON.

WSS/v2/voice-agent/wsAuthenticated with a short-lived session token
ParameterRequiredDefaultNotes
tokenyesnoneSession token from POST /v2/voice-agent/token. Connect before expires_at.
modelnowhisper-voicekit-agentThe voice agent model. Pass the same value used when minting the token.
max_session_duration_secnoservice ceilingSession cap in seconds, 60 to 10800, clamped to the service ceiling (55 minutes). Pass the same value used when minting the token.

Event flow

  1. The client connects and sends session.update as the first frame.
  2. The server emits session.ready with the session_id.
  3. The client streams input.audio frames continuously.
  4. While the caller speaks, the server emits input.speech.started, transcript.user.delta partials, then input.speech.stopped and a final transcript.user.
  5. The server replies: reply.started, a stream of reply.audio chunks, transcript.agent, and reply.done.
  6. When tools are configured the server may emit tool.call mid-reply; the client answers with tool.result and the reply continues.
  7. The client sends session.end; the server emits session.ended and closes the connection.

Client to server events

EventPurpose
session.updateConfigure the agent. Must be the first frame; can also update settings mid-session.
input.audioStream a chunk of caller audio as base64 PCM16.
tool.resultReturn the output of a tool.call.
reply.createAsk the agent to speak proactively with fresh instructions.
session.endFinalize the session immediately.

session.update

Defines the agent. Send it as the first frame after connecting; the server confirms mid-session updates with session.updated.

json
{
  "type": "session.update",
  "session": {
    "system_prompt": "You are a friendly support agent for Acme Internet. Keep answers short and confirm the account before making changes.",
    "greeting": "Hi, thanks for calling Acme. How can I help today?",
    "input": { "format": { "encoding": "audio/pcm" } },
    "output": { "format": { "encoding": "audio/pcm" } },
    "tools": [
      {
        "type": "function",
        "name": "get_account_status",
        "description": "Look up the status of a customer account",
        "parameters": {
          "type": "object",
          "properties": { "account_id": { "type": "string" } },
          "required": ["account_id"]
        }
      }
    ]
  }
}
FieldTypeNotes
session.system_promptstringInstructions that define the agent's persona, rules, and task.
session.greetingstringOpening line the agent speaks as soon as the session starts.
session.input.formatobjectInput audio format, for example { "encoding": "audio/pcm" }.
session.input.keytermsarrayDomain terms to bias speech recognition toward.
session.input.turn_detectionobjectTurn-taking sensitivity tuning.
session.output.voicestringVoice used for the agent's spoken replies.
session.output.formatobjectOutput audio format for reply.audio chunks.
session.output.volumenumberPlayback volume for agent replies.
session.toolsarrayFunction tools the agent may call, declared with JSON Schema parameters.

input.audio

json
{
  "type": "input.audio",
  "audio": "<base64 encoded PCM16 audio>"
}

audio is a base64-encoded chunk of 16-bit PCM. Send frames continuously after session.ready; the server handles speech detection and turn taking.

tool.result

json
{
  "type": "tool.result",
  "call_id": "call_5d1a2b",
  "result": "{\"status\": \"active\", \"plan\": \"fiber_500\"}"
}
FieldTypeNotes
call_idstringCopied from the tool.call you are answering.
resultstringTool output. Serialize structured data as a JSON string.

reply.create

json
{
  "type": "reply.create",
  "instructions": "Let the caller know the account check is still running."
}

Triggers a spoken reply without waiting for caller speech, guided by instructions. Useful for filling silences, for example while a slow tool runs.

session.end

json
{ "type": "session.end" }

Finalizes the session immediately. The server responds with session.ended and closes the socket. No fields.

Server to client events

EventWhenPurpose
session.readyafter session.updateThe agent is live. Carries the session_id.
session.updatedafter a mid-session updateAcknowledges a configuration change.
input.speech.startedwhile streamingThe caller started speaking.
input.speech.stoppedwhile streamingThe caller stopped speaking.
transcript.user.deltawhile the caller speaksPartial transcript of the current caller turn.
transcript.userafter a caller turnFinal transcript of the caller's turn.
reply.startedbefore agent speechThe agent began composing a reply.
reply.audioduring agent speechA chunk of agent speech as base64 PCM16.
transcript.agentwith agent speechText of what the agent said.
reply.doneafter agent speechThe reply finished, or was interrupted.
tool.callmid-replyThe agent requests a tool execution.
session.endedat the endThe session is finalized. Last event before close.
session.erroron failureSomething went wrong.

session.ready

json
{
  "type": "session.ready",
  "session_id": "sess_9f2c81"
}

Sent once the agent has accepted your configuration. Do not send input.audio before it arrives.

transcript.user.delta and transcript.user

json
{
  "type": "transcript.user.delta",
  "text": "is my internet plan"
}
json
{
  "type": "transcript.user",
  "text": "What is my internet plan called?",
  "item_id": "item_2b8c4d"
}

Deltas stream while the caller talks; the final transcript.user carries the full turn and an item_id you can use to correlate with the agent's reply.

reply.audio

json
{
  "type": "reply.audio",
  "data": "<base64 encoded PCM16 audio>"
}

data is a base64-encoded chunk of 16-bit PCM agent speech in your configured output format. Decode and play chunks in arrival order.

transcript.agent

json
{
  "type": "transcript.agent",
  "text": "You are on the Fiber 500 plan.",
  "reply_id": "reply_7e3f90",
  "item_id": "item_2b8c4d",
  "interrupted": false
}

The text of the agent's reply. interrupted is true when the caller talked over the agent and the reply was cut short.

reply.done

json
{ "type": "reply.done", "status": "interrupted" }

Marks the end of a reply. status is present when the reply did not complete normally, for example interrupted when the caller barged in; stop playback of any buffered reply.audio when that happens.

tool.call

json
{
  "type": "tool.call",
  "call_id": "call_5d1a2b",
  "name": "get_account_status",
  "arguments": { "account_id": "acct_1042" }
}
FieldTypeNotes
call_idstringUnique id for this call. Echo it in tool.result.
namestringName of the tool, as declared in session.tools.
argumentsobjectArguments matching the tool's JSON Schema parameters.

session.ended

json
{
  "type": "session.ended",
  "session_duration_seconds": 312.4,
  "audio_duration_seconds": 296.8,
  "timestamp": 1784721600.512
}

The final event of every session, with wall-clock and audio duration accounting. The socket closes right after it.

Ending a session

How it endsWhat happens
You send session.endThe session finalizes immediately, session.ended is emitted, and the socket closes.
You close or lose the WebSocketThe service finalizes the session for you. Sessions never outlive the connection and are not resumable.
The session cap is reachedThe service finalizes the session and closes the socket. Start a new session to continue.

In all three cases billing stops when the connection ends. Prefer an explicit session.end so you receive session.ended and its duration accounting.

Errors and close codes

Close codeMeaning
4401The token is missing, expired, or not a voice agent session token. Mint a new token.
4400The model query parameter is unknown or not a voice agent model.

Failures during a session arrive as session.error events. When a session cannot start at all (for example the service is temporarily unavailable), you receive a session.error with only a message and the socket closes.

json
{
  "type": "session.error",
  "code": "invalid_format",
  "message": "Invalid message format"
}
FieldNotes
codeMachine-readable error code, when available.
messageHuman-readable description of what went wrong.
4.2de 21 avaliações