Use the Voice Agent API
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 real-time interface, so one connection runs the whole conversation: hearing the user, drafting what to say, and speaking the response. All the models run on one GPU with no network hop between stages.
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. This uses the default of Parakeet TDT 0.6B v3 for speech-to-text, Qwen3.8 27B for the language model, and Qwen3 TTS 1.7B for text-to-speech. -
Optionally override one or more of the default models with a supported model. Order does not matter; the model's role in the cascade is inferred. For example, you could set
modeltovoice-agent/kokoroto customize just the TTS model, or you could usevoice-agent/kokoro/whisper-turbo/gemma-12bto customize all three models.Type Model ID STT Parakeet TDT 0.6B v3 parakeet(default)STT Whisper large-v3-turbo whisper-turboSTT Qwen3 ASR 1.7B qwen3-asrLLM Qwen3.8 27B qwen-27b(default)LLM Gemma 4 12B gemma-12bTTS Qwen3 TTS 1.7B qwen-tts(default)TTS Kokoro 82M kokoroNote that Gemma 4 12B is audio-native. If you specify
gemma-12bfor your LLM without specifying an STT model, then audio is sent straight to the LLM without producing a transcript.
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?