Commit and clear the audio buffer
On this page
Updated November 3, 2026, based on the xAI Voice API reference:
input_audio_buffer.commitis only available whenturn_detection.typeisnull; inserver_vadmode, 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:
- Creates a new conversation item with the accumulated audio
- Sends an
input_audio_buffer.committedevent to confirm - Sends a
conversation.item.addedevent with the new item - 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:
- It detects the start of speech (
speech_started) - It accumulates the audio in the buffer
- It detects the end of speech (
speech_stopped) - It commits the buffer automatically
- 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:
- You send audio with
append - You decide when the user is done
- You send
commit - You send
response.create
Comparison
| Aspect | VAD mode | Manual mode |
|---|---|---|
| Speech detection | Automatic | Up to you |
| Buffer commit | Automatic | Manual (commit) |
| Response request | Automatic | Manual (response.create) |
| Control | Less control | Full control |
| Complexity | Simple | More complex |
| Use cases | Free-flowing conversation | Push-to-talk, IVR |
Key takeaways
input_audio_buffer.commitsubmits the audio buffer as a user messageinput_audio_buffer.clearempties the buffer without processing- In VAD mode, the commit happens automatically when the end of speech is detected
- In manual mode (
turn_detection.typeset tonull), you must sendcommitand thenresponse.createexplicitly;commitis only available in this mode - Manual mode suits push-to-talk interfaces and IVR phone systems