Varmirdocs
Docs/API reference/WS /api/v1/stream
WS

/api/v1/stream

Bidirectional WebSocket for live transcription with sub-200 ms partials.Authentication required

Connect

Open a WebSocket and send a config message with your API key, sample rate, and optional translate_to.

JavaScript
const ws = new WebSocket("wss://api.varmir.com/api/v1/stream");

ws.onopen = () => {
  ws.send(JSON.stringify({
    type: "config",
    token: "mstk_your_key",
    sample_rate: 16000,
    translate_to: "uk",
  }));
};

Message protocol

After the first config_ok from the server, send raw PCM frames as binary messages. Text messages with type=end close the stream gracefully.

overview
// First message: config
{
  type: "config",
  token: "mstk_...",
  sample_rate: 16000,
  audio_format: "pcm_s16le",
  translate_to: "uk"
}

// Then: raw audio chunks (binary), ~40 ms each
ws.send(audioChunk);

// To stop: a close message or simply ws.close()
ws.send(JSON.stringify({ type: "end" }));

Server events

EventDirectionDescription
config_okserver → clientAcknowledges the initial config message. Stream is ready for audio chunks.
partialserver → clientInterim transcription update. Replace previous partials for the same segment.
finalserver → clientFinalised segment. Append to your transcript; partials for this segment stop.
translationserver → clientTranslation for a finalised segment. Arrives ~150 ms after the matching final.
errorserver → clientStream terminated. code is one of invalid_key, quota_exceeded, internal.

Code examples

A browser-side client that pipes microphone PCM into the stream and renders partial + final segments.

stream.js
const ws = new WebSocket("wss://api.varmir.com/api/v1/stream");

ws.onopen = () => ws.send(JSON.stringify({
  type: "config",
  token: "mstk_your_key",
  sample_rate: 16000,
  translate_to: "uk",
}));

ws.onmessage = (e) => {
  const msg = JSON.parse(e.data);
  if (msg.type === "partial") updatePartial(msg.text);
  if (msg.type === "final") commitFinal(msg.text);
  if (msg.type === "translation") commitTranslation(msg.text);
};

// Pipe browser microphone PCM frames
micFrames.on("data", (chunk) => ws.send(chunk));
WS /api/v1/stream — Varmir docs