docs

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:

  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. (s2s stays accepted as an alias.) This uses the default of Parakeet TDT 0.6B v3, Qwen3.8 27B, and Qwen3 TTS 1.7B.

  4. The voice agent runs these models; the defaults are marked.

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

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