LiveKit Agents already traces every session with OpenTelemetry. opentoken.init() sends those traces to Open Token and fills in what LiveKit doesn't put on its spans, so each call arrives complete:
- One call, one trace. The session is the run; each caller turn and each agent reply are child spans, with the LLM, TTS and tool calls under them.
- Cost per call and per minute across the LLM (tokens), speech-to-text (audio minutes) and text-to-speech (characters), priced with the provider's list price or your own rate. Speech-to-speech models (Amazon Nova Sonic, OpenAI Realtime, Gemini Live) are priced by text and audio tokens.
- Latency by stage for every reply: end of turn, transcription, LLM time to first token, TTS time to first byte and the total until the caller hears the agent.
- Interruptions: replies the caller barged into, apart from the ones your agent cut itself.
- Attribution: agent, project, LiveKit room, and for phone calls the SIP trunk, your number and the direction (inbound or outbound).
- Chat sessions (text only) work the same way, without minutes.
Everything shows up under Voice agents in the dashboard, and each call opens as a trace under Traces.
1. Install
pip install "getopentoken[livekit]" "livekit-agents[deepgram,openai,cartesia,silero]"Keep the LiveKit plugins you already use; the ones above are only the example's.
2. Environment
Create an ingest key under API keys (scope Ingest) and export it as OT_INGEST_KEY. The service name is the agent's name in Open Token, unless you dispatch it by name (then agent_name wins).
# OT_INGEST_KEY: an ingest key from API keys (scope: Ingest). Keep it in your secret store.
export OTEL_EXPORTER_OTLP_ENDPOINT="https://getopentoken.com/api/otel"
export OTEL_SERVICE_NAME="support-line"
# LIVEKIT_URL, LIVEKIT_API_KEY, LIVEKIT_API_SECRET and your provider keys stay as they are.3. Add one line to your agent
Call opentoken.init() at the top of the file, before LiveKit starts, so it runs in the worker and in every job process.
import opentoken
opentoken.init() # each call becomes one trace: turns, latency by stage, interruptions, LLM + STT + TTS cost
from livekit import agents
from livekit.agents import Agent, AgentServer, AgentSession
from livekit.plugins import cartesia, deepgram, openai, silero
server = AgentServer()
@server.rtc_session(agent_name="support-line")
async def support_line(ctx: agents.JobContext):
await ctx.connect()
session = AgentSession(
vad=silero.VAD.load(),
stt=deepgram.STT(model="nova-3"),
llm=openai.LLM(model="gpt-4o-mini"),
tts=cartesia.TTS(model="sonic-2"),
)
await session.start(room=ctx.room, agent=Agent(instructions="You are ACME's support line. Be brief."))
if __name__ == "__main__":
agents.cli.run_app(server)Run it as usual (python agent.py start, or dev locally), place a call, then open Voice agents: the call shows its minutes, cost per minute, each reply's latency by stage and any barge-ins. Full trace opens the same call as a waterfall.
Phone calls (SIP)
Nothing to add. For calls that come in through a LiveKit SIP trunk, Open Token reads the trunk, your phone number and the call id from the session, and marks the call inbound (a dispatch rule answered it) or outbound (you placed it with CreateSIPParticipant). The caller's phone number is never stored.
To report the direction yourself (for example for a web call your app treats as outbound), set the span attribute opentoken.voice.direction to inbound or outbound.
Chat sessions
A session without audio is a chat session: same trace, LLM cost and time to first token per reply, no minutes.
import asyncio
import opentoken
opentoken.init()
from livekit.agents import Agent, AgentSession
from livekit.plugins import openai
async def main():
async with AgentSession(llm=openai.LLM(model="gpt-4o-mini")) as session:
await session.start(Agent(instructions="You are ACME's chat assistant."))
await session.run(user_input="Where is my order?")
asyncio.run(main())
opentoken.shutdown() # flush before a short-lived process exitsNode.js
The Node SDK does the same for @livekit/agents. Call init() at the top of the agent file.
npm install @getopentoken/sdk @opentelemetry/api @opentelemetry/sdk-trace-node @opentelemetry/exporter-trace-otlp-proto @opentelemetry/resources @livekit/agents \
@livekit/agents-plugin-deepgram @livekit/agents-plugin-openai @livekit/agents-plugin-cartesia @livekit/agents-plugin-sileroimport { init } from "@getopentoken/sdk";
import { type JobContext, cli, defineAgent, voice, ServerOptions } from "@livekit/agents";
import * as cartesia from "@livekit/agents-plugin-cartesia";
import * as deepgram from "@livekit/agents-plugin-deepgram";
import * as openai from "@livekit/agents-plugin-openai";
import * as silero from "@livekit/agents-plugin-silero";
import { fileURLToPath } from "node:url";
init(); // hands @livekit/agents Open Token's tracer provider; every session becomes one trace with cost
export default defineAgent({
entry: async (ctx: JobContext) => {
await ctx.connect();
const session = new voice.AgentSession({
vad: await silero.VAD.load(),
stt: new deepgram.STT({ model: "nova-3" }),
llm: new openai.LLM({ model: "gpt-4o-mini" }),
tts: new cartesia.TTS({ model: "sonic-2" }),
});
await session.start({ room: ctx.room, agent: new voice.Agent({ instructions: "You are ACME's support line." }) });
},
});
cli.runApp(new ServerOptions({ agent: fileURLToPath(import.meta.url), agentName: "support-line" }));Cost
- Units. Speech-to-text is billed per minute of audio sent to the provider, silence included (that's how providers bill streaming). Text-to-speech is billed per character synthesized. LLMs are billed per token; Bedrock models use the AWS price list, other models the voice price table.
- Your rates. Voice agents → Prices lists every list price Open Token uses. If you negotiated a different rate, enter it there: new calls use it, and calls already recorded keep the price they were costed at.
- No double counting. If the agent's LLM goes through the Open Token gateway, the gateway meters it and the span isn't counted again.
- Unknown providers show usage (minutes, characters) with no cost until the provider is in the table. Ask us to add it, or set your own price.
Privacy
- Transcripts and replies stay out by default. LiveKit marks every conversational attribute (transcripts, replies, tool arguments, room names, phone numbers);
init()turns on LiveKit's own filter so they never leave your process, and Open Token drops them again at ingest. - To store transcript text, set
OT_CAPTURE_CONTENT=1in the agent and turn on content capture for the project under Traces → Trace settings. Both are needed. - Audio is never sent or stored.
Troubleshooting
- No speech-to-text cost. LiveKit reports speech-to-text usage only as a metrics event.
opentoken.init()turns it into spans; a plain OpenTelemetry exporter without the SDK gets everything except STT. - A call is missing. A call is recorded when its session ends (the caller hangs up or the job shuts down).
init()flushes spans when each job ends; if you run sessions outside a LiveKit job, callopentoken.shutdown()before the process exits. - LiveKit Cloud observability too. It keeps working: LiveKit Cloud receives its own copy with the project's settings.
- Also in Langfuse. Add
OT_ALSO_EXPORT=langfuseand yourLANGFUSE_*keys; the same trace reaches both. See SDK.