Live transcript in the browser
Goal: show a call's transcript, word by word, in your web app — without exposing your API key.
browser ──(1) GET /stream-token?call=…──▶ your server ──(2) POST /v1/stream-tokens──▶ Kolwire
browser ◀──────────── token ─────────────
browser ══(3) wss://stream.kolwire.com/v1/stream?token=…══▶ realtime gateway1. Mint a stream token on your server
A stream token is short-lived, scoped to your workspace (optionally one call) and to scopes like transcript.
import express from "express";
import { Kolwire } from "@kolwire/sdk";
const vi = new Kolwire();
const app = express();
app.get("/stream-token", async (req, res) => {
// Authorize your own user here before handing out access to the call!
const { token, expires_at } = await vi.streamTokens.create({
call_id: String(req.query.call),
scopes: ["events", "transcript"],
ttl_sec: 900,
});
res.json({ token, expires_at });
});from fastapi import FastAPI
from kolwire import Kolwire
client = Kolwire()
app = FastAPI()
@app.get("/stream-token")
def stream_token(call: str):
# Authorize your own user here before handing out access to the call!
t = client.stream_tokens.create(call_id=call, scopes=["events", "transcript"], ttl_sec=900)
return {"token": t.token, "expires_at": t.expires_at}2. Connect from the browser
@kolwire/sdk/realtime is browser-safe (no API key, no Node built-ins). Pass a function as token so the client fetches a fresh one whenever it reconnects; it resumes from the last event it saw.
import { StreamClient } from "@kolwire/sdk/realtime";
const callId = "call_123";
const stream = new StreamClient({
url: "wss://stream.kolwire.com/v1/stream",
token: async () => (await (await fetch(`/stream-token?call=${callId}`)).json()).token,
subscribe: { call_id: callId, events: ["call.transcript.*", "call.ended"] },
});
const lines = new Map<string, HTMLElement>(); // segment_id → element
const list = document.querySelector("#transcript")!;
stream.on("call.transcript.partial", (e) => render(e.data.segment_id, e.data.speaker, e.data.text, false));
stream.on("call.transcript.final", (e) => render(e.data.segment_id, e.data.speaker, e.data.text, true));
stream.on("call.ended", () => stream.close());
stream.on("reconnecting", ({ attempt }) => console.log("reconnecting…", attempt));
await stream.connect();
function render(id: string, speaker: string, text: string, final: boolean) {
let el = lines.get(id);
if (!el) {
el = document.createElement("p");
lines.set(id, el);
list.append(el);
}
el.textContent = `${speaker}: ${text}`;
el.style.opacity = final ? "1" : "0.6";
}Partial segments are replaced by later partials with the same segment_id, then by a final one. speaker is agent / customer on dual-channel calls, speaker_N otherwise.
Server-side consumers
On your server you can skip the token dance — the SDK mints and refreshes tokens for you:
const stream = await vi.realtime({ callId: "call_123", events: ["call.transcript.final"] });
for await (const e of stream.events("call.transcript.final")) {
console.log(`${e.data.speaker}: ${e.data.text}`);
}from kolwire import AsyncKolwire
aclient = AsyncKolwire()
stream = await aclient.realtime(call_id="call_123", events=["call.transcript.final"])
async for e in stream.events("call.transcript.final"):
print(f"{e.data.speaker}: {e.data.text}")Prefer prebuilt UI? The embeddable widgets include a live transcript component that takes the same stream token. See also the realtime protocol.