docs

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:

  1. Get a uRun API key.
  2. Open a Session with the Voice Agent API.

Prerequisites

Get an API key

Create an API key:

  1. In the console, go to API Keys and click + Create API key.
  2. Enter a Label for the key that will help you identify where it is used later.
  3. Select Create key.
  4. 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:

  1. Where the SDK asks for a base URL or host, point to uRun's host inference.urun.sh.

  2. Where the SDK asks for an API key, authenticate with your uRun API key.

  3. Set the model field to voice-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.

  4. 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 model to voice-agent/kokoro to customize just the TTS model, or you could use voice-agent/kokoro/whisper-turbo/gemma-12b to customize all three models.

    TypeModelID
    STTParakeet TDT 0.6B v3parakeet (default)
    STTWhisper large-v3-turbowhisper-turbo
    STTQwen3 ASR 1.7Bqwen3-asr
    LLMQwen3.8 27Bqwen-27b (default)
    LLMGemma 4 12Bgemma-12b
    TTSQwen3 TTS 1.7Bqwen-tts (default)
    TTSKokoro 82Mkokoro

    Note that Gemma 4 12B is audio-native. If you specify gemma-12b for 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.

TypeScript
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.

TypeScript
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?

0/2000

On this page