Zespan
Start free
LiveKit

LiveKit Integration

One call attaches Zespan to a LiveKit AgentSession. Every turn of a call becomes a trace with its speech-to-text, model, tool and text-to-speech steps, and opt-in guardrails can stop a reply before the caller hears it.

LiveKit Agents is a framework for building voice agents, where an AgentSession runs speech-to-text, a model and text-to-speech for each turn of a call, in Python or TypeScript.

zespan.com — livekit trace
Zespan voice call transcript showing a reply blocked by a guardrail before the caller heard it

Getting Started

1

Install the SDK

In Python, install zespan with the livekit extra (Python 3.10 or newer, livekit-agents 1.8 or newer). In TypeScript, install @zespan/sdk alongside @livekit/agents 1.10 or newer.

bash
pip install "zespan[livekit]"
2

Attach to the session before it starts

Call instrument_session (TypeScript: instrumentLiveKitSession) after creating your AgentSession and before session.start(), so the first turn is seen. Flush from LiveKit's shutdown callback so the last turn and the call summary are sent.

python
import os

import zespan
from zespan.integrations import instrument_session
from livekit.agents import Agent, AgentSession, JobContext

zespan.init(api_key=os.environ["ZESPAN_API_KEY"])

async def entrypoint(ctx: JobContext):
    session = AgentSession(
        stt="deepgram/nova-3",
        llm="openai/gpt-4.1-mini",
        tts="cartesia/sonic-2",
    )

    zs = instrument_session(
        session,
        job_context=ctx,
        agent_name="support-voice",
        tags={"line": "billing"},
    )

    await session.start(
        agent=Agent(instructions="You are a helpful support agent."),
        room=ctx.room,
    )

    ctx.add_shutdown_callback(zs.aflush)
3

Turn on guardrails (optional)

Pass guardrails to the instrumentation and call guard_agent (TypeScript: guardLiveKitAgent) on each agent. Input, output and tool checks run inside the voice pipeline, each with its own time budget, and a blocked turn says your blocked line instead.

python
from zespan.integrations import instrument_session, guard_agent

zs = instrument_session(
    session,
    job_context=ctx,
    guardrails={
        "blocked_line": "Sorry, I can't help with that.",
        "fail_closed": True,
        "budgets": {"input_ms": 300, "output_sentence_ms": 250, "tool_ms": 300},
    },
)

agent = Agent(instructions="You are a helpful support agent.")
guard_agent(agent, zs)

await session.start(agent=agent, room=ctx.room)
4

Open the call in Zespan

Turns of one call are grouped as one session, with the id lk:<job id>. The Call tab shows what the caller heard, and each turn's trace shows the latency waterfall.

What's captured automatically

  • One trace per turn: what the caller said, what the agent answered, and stt, chat, tool, handoff and tts spans
  • Voice latencies as LiveKit measures them: end-to-end, end-of-turn delay, transcription delay, TTS time to first byte
  • Audio pricing: speech-to-text by audio seconds, text-to-speech by characters, priced on the server
  • Guardrails on input, output sentences and tools, with a blocked line the caller hears instead
  • A call summary with turns, interruptions and close reason, plus voice evaluators for response time, dead air and interruption rate
  • No personal data by default: participant identity, room name and SIP numbers are never read unless you opt in

FAQ

Is it Python or TypeScript?

Both. TypeScript uses instrumentLiveKitSession from @zespan/sdk, Python uses instrument_session from zespan.integrations. Both read LiveKit's own session events and metrics, with or without LiveKit Cloud.

Does it touch the audio or slow the voice loop?

No. Nothing in your agent is patched. The SDK subscribes to the session, never touches audio, and its handlers do no network work on the voice loop. Guardrail checks are the exception: their time budgets add to the turn, and you set them.

Can I also send LiveKit's OpenTelemetry export to Zespan?

Use one or the other, not both. Sending both counts every turn twice and doubles cost and token totals. The OpenTelemetry path also has no speech-to-text spans, no guardrails and no voice evaluators.

What does a guardrail not cover?

Text you pass to session.say() or generate_reply(user_input=...) yourself, realtime models (input and output checks do not apply, tool checks still do), and agents you did not pass to guard_agent.

Start free — 50K traces a month, no card needed

LiveKit integration works on all plans including the free tier.

← All integrations