You can now talk to Telnyx AI Assistants over a direct WebSocket connection, with no telephony required. Stream PCM16 audio from any web or mobile client and receive real-time transcription, assistant audio, and tool-call events over the same connection.
wss://api.telnyx.com/v2/ai/assistants/{assistant_id}/conversation
and stream audio directly to your assistant, with no phone number or PSTN connection required.conversation.item.create
and the assistant responds as if the user spoke it. Useful for hybrid voice and text interfaces.function_call_output
. Build tools that access local device state or browser APIs.session.created
frame.response.cancel
for client-initiated barge-in without audio.wss://api.telnyx.com/v2/ai/assistants/{assistant_id}/conversation
with your Telnyx API v2 key as the Bearer token.input_sample_rate
and output_sample_rate
to match your audio capture and playback configuration.input_audio_buffer.append
and listen for session.created
, transcription, and assistant-audio events.
// Open a WebSocket connection to your Telnyx AI Assistant
const ws = new WebSocket(
'wss://api.telnyx.com/v2/ai/assistants/ASSISTANT_ID/conversation'
+ '?input_sample_rate=16000&output_sample_rate=24000'
);
ws.onmessage = (event) => {
const frame = JSON.parse(event.data);
console.log(frame.type);
// session.created: confirms session and negotiated audio formats
// input_audio_buffer.speech_started: user started speaking (VAD)
// conversation.item.input_audio_transcription.completed: user transcript
// response.created: assistant turn starts
// response.audio.delta: assistant audio chunk (base64 PCM16)
};
// Stream microphone audio as base64-encoded PCM16 frames
function sendAudioChunk(pcm16Buffer) {
ws.send(JSON.stringify({
type: 'input_audio_buffer.append',
audio: arrayBufferToBase64(pcm16Buffer)
}));
}
// Inject a text turn (assistant responds as if the user spoke it)
ws.send(JSON.stringify({
type: 'conversation.item.create',
item: {
type: 'message',
role: 'user',
content: [{ type: 'input_text', text: 'What are your business hours?' }]
}
}));
// Cancel the in-progress assistant response (barge-in)
ws.send(JSON.stringify({ type: 'response.cancel' }));
Learn more in the Telnyx WebSocket API reference or the Voice AI Assistants docs.