> ## Documentation Index
> Fetch the complete documentation index at: https://docs.somya.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# LiveKit Agents

> Use SomyaLabs ASR and TTS in a LiveKit voice agent.

Use [LiveKit Agents](https://docs.livekit.io/agents/start/voice-ai/) for voice
rooms and turn handling, with SomyaLabs [Vyasa](https://docs.somya.ai/models/asr.md) for speech
recognition and [Panini](https://docs.somya.ai/models/tts.md) for speech synthesis.

> [!NOTE]
>
> SomyaLabs does not yet have a built-in LiveKit plugin or a LiveKit Inference
> model. Copy the [SomyaLabs adapter](https://docs.somya.ai/integrations/livekit-adapter.md) into your
> agent project before using the short example below.

## Install and configure

Use Python 3.10 or newer. Create a LiveKit Cloud project and a
[SomyaLabs API key](https://playground.somya.ai), then install:

```bash theme={null}
pip install "livekit-agents~=1.8" httpx python-dotenv
```

Save the [adapter code](https://docs.somya.ai/integrations/livekit-adapter.md) as `somya_livekit.py`.
Create `.env.local` in the same directory:

```dotenv theme={null}
LIVEKIT_URL=wss://your-project.livekit.cloud
LIVEKIT_API_KEY=your-livekit-api-key
LIVEKIT_API_SECRET=your-livekit-api-secret
SOMYA_API_KEY=your-somya-api-key
```

Keep this file on your agent server and out of source control and browser code.
The SomyaLabs key authenticates speech requests; LiveKit uses its own project
credentials for the room and the example LLM.

## Create the agent

Save this as `agent.py` beside `somya_livekit.py`:

```python theme={null}
import os

from dotenv import load_dotenv
from livekit import agents
from livekit.agents import Agent, AgentServer, AgentSession, inference
from somya_livekit import SomyaSTT, SomyaTTS

load_dotenv(".env.local")
server = AgentServer()


@server.rtc_session(agent_name="somya-agent")
async def somya_agent(ctx: agents.JobContext):
    key = os.environ["SOMYA_API_KEY"]
    session = AgentSession(
        stt=SomyaSTT(key),
        llm=inference.LLM(model="google/gemma-4-31b-it"),
        tts=SomyaTTS(key, voice="arjun"),
        vad=inference.VAD(model="silero"),
    )
    await session.start(
        room=ctx.room,
        agent=Agent(instructions="You are a helpful voice assistant. Keep replies short."),
    )
    await session.generate_reply(instructions="Greet the user and offer assistance.")


if __name__ == "__main__":
    agents.cli.run_app(server)
```

Run `python agent.py dev`, then open the agent in your
[LiveKit Cloud dashboard](https://cloud.livekit.io/) to speak to it. Change
`voice="arjun"` to another [voice slug](https://docs.somya.ai/models/tts.md#voices) if you prefer.

Vyasa transcribes completed speech turns, so the agent does not receive interim
transcripts. Panini streams audio chunks for playback as they arrive. See the
[adapter reference](https://docs.somya.ai/integrations/livekit-adapter.md) for how the HTTP requests and
audio conversion work.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.