Use the voice agent in a Session
Stream a voice conversation through the voice agent API
The voice agent API combines speech-to-text (STT), a language model (LLM), and text-to-speech (TTS) behind a single Model API, so one connection runs the whole conversation: hearing the user, drafting what to say, and speaking the response.
You use the voice agent API in a Session — a persistent bidirectional connection that streams audio in and audio out — through an interface compatible with OpenAI Realtime, GPT Live, or Gemini Live. Because the interfaces are industry-standard, you connect with the standard OpenAI SDK or WebSockets for Gemini Live. There is no separate uRun SDK to learn or use.
In this walkthrough, you will do the following:
- Get a uRun API key.
- Open a Session with the voice agent API.
Prerequisites
- For compatibility with OpenAI Realtime or GPT Live, the OpenAI TypeScript and JavaScript API library.
- To use
openai/realtime/wsyou will also need thewspeer dependency, which you can install withnpm install ws.
- To use
- For compatibility with Gemini Live, the
wsnpm package. - A uRun account so you can make an API key.
Get an API key
Create an API key:
- In the console, go to API Keys and click + Create API key.
- Enter a Label for the key that will help you identify where it is used later.
- Select Create key.
- Copy the generated secret and store it somewhere safe. It is not retrievable later.
Open a Session
The industry-standard interface you choose defines most of how you connect to a Model API with uRun. So, follow the upstream guide for your interface and change three things:
-
Where the SDK asks for a base URL or host, point to uRun's host
inference.urun.sh. -
Where the SDK asks for an API key, authenticate with your uRun API key.
-
Set the
modelfield tovoice-agent. (s2sstays accepted as an alias.) This uses the default of Parakeet TDT 0.6B v3, Qwen3.8 27B, and Qwen3 TTS 1.7B. -
The voice agent runs these models; the defaults are marked.
Type Model ID STT Parakeet TDT 0.6B v3 parakeet-tdt-0.6b-v3(default)STT Whisper large-v3-turbo whisper-large-v3-turboSTT Qwen3 ASR 1.7B qwen3-asr-1.7bLLM Qwen3.8 27B qwen3.8-27b(default)LLM Gemma 4 12B gemma-4-12bTTS Qwen3 TTS 1.7B qwen3-tts-1.7b-base(default)TTS Kokoro 82M kokoro-82m
Set your host, API key, and model as described above.
import OpenAI from "openai";
import { OpenAIRealtimeWS } from "openai/realtime/ws";
const client = new OpenAI({
apiKey: "urun_sk_YOUR_KEY",
baseURL: "https://inference.urun.sh/v1",
});
// Open a Session and stream audio in and out.
// The shape follows the upstream OpenAI API.
const session = new OpenAIRealtimeWS({ model: "voice-agent" }, client);For the full syntax, refer to the upstream OpenAI Realtime reference or GPT-Live reference.
Set your host, API key, and model as described above.
import WebSocket from "ws";
const ws = new WebSocket(
"wss://inference.urun.sh/ws/google.ai.generativelanguage.v1beta.GenerativeService.BidiGenerateContent",
{ headers: { "x-goog-api-key": "urun_sk_YOUR_KEY" } }
);
// Open a live Session and stream audio in and out.
// The shape follows the upstream Gemini Live API.
ws.on("open", () => {
// Send the initial Gemini Live setup message.
ws.send(
JSON.stringify({
setup: {
model: "voice-agent",
},
})
);
});
ws.on("message", (data) => {
const message = JSON.parse(data.toString());
// Handle setupComplete, serverContent, toolCall, etc.
console.log("Server message:", message);
});
ws.on("error", (error) => {
console.error("WebSocket error:", error);
});
ws.on("close", () => {
console.log("WebSocket closed");
});For details on audio streaming patterns, refer to the upstream Gemini Live API guide.
Was this page helpful?