Skip to main content
Lesson 8 of 16 · Voice Agent API: real-time conversations

Commit and clear the audio buffer

Lesson 8 of 16 Updated November 3, 2026 Developer
On this page
  1. Managing the audio buffer
  2. input_audio_buffer.commit
  3. input_audio_buffer.clear
  4. VAD mode versus manual mode
  5. Key takeaways

Updated November 3, 2026, based on the xAI Voice API reference: input_audio_buffer.commit is only available when turn_detection.type is null; in server_vad mode, the server commits the audio itself. Source: Voice API.

Managing the audio buffer

When you send audio with input_audio_buffer.append, the data accumulates in a buffer on the server. Two operations control that buffer: commit to submit its contents as a user message, and clear to empty it without processing.

input_audio_buffer.commit

This event commits the current contents of the audio buffer as a user message. It’s required in manual mode (push-to-talk) and automatic in VAD mode:

{
  "type": "input_audio_buffer.commit"
}

When the server receives a commit, it:

  1. Creates a new conversation item with the accumulated audio
  2. Sends an input_audio_buffer.committed event to confirm
  3. Sends a conversation.item.added event with the new item
  4. Starts transcribing the audio (if enabled)

The server’s response

{
  "type": "input_audio_buffer.committed",
  "item_id": "item_audio_001"
}

The item_id lets you refer to this message in the conversation later.

When to commit manually

  • Push-to-talk: the user holds a button to talk and releases it to send
  • Manual segmentation: you split the audio stream into logical segments on the client
  • Phone integration: you receive audio chunks from a PBX and commit them at the end of each turn
// Push-to-talk example
talkButton.addEventListener("mousedown", () => {
  isRecording = true;
  startCapture();
});

talkButton.addEventListener("mouseup", () => {
  isRecording = false;
  stopCapture();

  // Commit the buffer
  ws.send(JSON.stringify({
    type: "input_audio_buffer.commit"
  }));

  // Request a response
  ws.send(JSON.stringify({
    type: "response.create"
  }));
});

input_audio_buffer.clear

This event empties the audio buffer without creating a message in the conversation:

{
  "type": "input_audio_buffer.clear"
}

The server confirms with:

{
  "type": "input_audio_buffer.cleared"
}

When to clear

  • Cancellation: the user presses a “Cancel” button while speaking
  • Interruption: the user starts speaking, then another event interrupts the turn
  • Reset: after an error or a timeout, clear the buffer before starting over
  • Background noise: the system detects that the buffer contains only noise, not speech
cancelButton.addEventListener("click", () => {
  stopCapture();
  ws.send(JSON.stringify({
    type: "input_audio_buffer.clear"
  }));
  showMessage("Recording canceled");
});

VAD mode versus manual mode

In VAD mode (server_vad), the server handles the whole cycle automatically:

  1. It detects the start of speech (speech_started)
  2. It accumulates the audio in the buffer
  3. It detects the end of speech (speech_stopped)
  4. It commits the buffer automatically
  5. It starts generating the response automatically

In manual mode (turn_detection.type set to null), you handle each step yourself, and it’s the only mode where input_audio_buffer.commit is available:

  1. You send audio with append
  2. You decide when the user is done
  3. You send commit
  4. You send response.create

Comparison

AspectVAD modeManual mode
Speech detectionAutomaticUp to you
Buffer commitAutomaticManual (commit)
Response requestAutomaticManual (response.create)
ControlLess controlFull control
ComplexitySimpleMore complex
Use casesFree-flowing conversationPush-to-talk, IVR

Key takeaways

  • input_audio_buffer.commit submits the audio buffer as a user message
  • input_audio_buffer.clear empties the buffer without processing
  • In VAD mode, the commit happens automatically when the end of speech is detected
  • In manual mode (turn_detection.type set to null), you must send commit and then response.create explicitly; commit is only available in this mode
  • Manual mode suits push-to-talk interfaces and IVR phone systems