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

# LiveKit Agents integration

> Connect LiveKit Agents to Orq.ai's AI Gateway for complete observability, built-in reliability, and access to 300+ LLMs across 20+ providers.

## AI Gateway

### Overview

LiveKit Agents is a framework for building real-time voice and multimodal AI agents that communicate over WebRTC. Connecting LiveKit Agents to Orq.ai's **AI Gateway** provides production-ready voice AI with enterprise-grade LLM access without vendor lock-in.

### Key Benefits

Orq.ai's **AI Gateway** enhances LiveKit Agents with:

<CardGroup cols={2}>
  <Card title="Complete Observability" icon="chart-line">
    Track every LLM call, tool use, and agent interaction with detailed traces
  </Card>

  <Card title="Built-in Reliability" icon="shield-check">
    Automatic fallbacks, retries, and load balancing for production resilience
  </Card>

  <Card title="Cost Optimization" icon="chart-pie">
    Real-time cost tracking and spend management across all AI operations
  </Card>

  <Card title="Multi-Provider Access" icon="cubes">
    Access 300+ LLMs and 20+ providers through a single, unified integration
  </Card>
</CardGroup>

### Prerequisites

**Prerequisites:**

* An Orq.ai account and [API Key](/docs/ai-gateway/configuration/api-keys)
* Python 3.9 or higher
* A LiveKit account with URL, API key, and API secret

<Info>
  To set up an API key, see [API keys & Endpoints](/docs/ai-gateway/configuration/api-keys).
</Info>

### Installation

Install LiveKit Agents with the OpenAI plugin:

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
pip install "livekit-agents[openai]~=1.0"
```

### Configuration

Configure LiveKit Agents to use Orq.ai's AI Gateway via the OpenAI plugin's `base_url` parameter:

```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
from livekit.plugins import openai
import os

# Configure OpenAI-compatible LLM with Orq.ai AI Gateway
llm = openai.LLM(
    model="openai/gpt-4o",
    base_url="https://api.orq.ai/v3/router",
    api_key=os.getenv("ORQ_API_KEY"),
)
```

> **base\_url**: `https://api.orq.ai/v3/router`

### Environment Variables

Set the LiveKit and **Orq.ai** credentials:

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
export LIVEKIT_URL="wss://your-project.livekit.cloud"
export LIVEKIT_API_KEY="your-livekit-api-key"
export LIVEKIT_API_SECRET="your-livekit-api-secret"
export ORQ_API_KEY="your-orq-api-key"
```

### Basic Voice Agent

Here's a complete example of a voice agent using Orq.ai's AI Gateway:

```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
import os
from livekit.agents import Agent, AgentSession, WorkerOptions, cli
from livekit.plugins import openai

class Assistant(Agent):
    def __init__(self):
        super().__init__(
            instructions="You are a helpful voice assistant.",
        )

async def entrypoint(ctx):
    session = AgentSession(
        llm=openai.LLM(
            model="openai/gpt-4o",
            base_url="https://api.orq.ai/v3/router",
            api_key=os.getenv("ORQ_API_KEY"),
        ),
    )
    await session.start(ctx.room, agent=Assistant())

if __name__ == "__main__":
    cli.run_app(WorkerOptions(entrypoint_fnc=entrypoint))
```

### Agent with Function Tools

Add tools to the voice agent for dynamic responses:

```python Python theme={"theme":{"light":"github-light","dark":"github-dark"}}
import os
from livekit.agents import Agent, AgentSession, WorkerOptions, cli, function_tool
from livekit.plugins import openai

@function_tool
async def get_weather(location: str) -> str:
    """Get the current weather for a location."""
    return f"The weather in {location} is sunny and 72°F"

@function_tool
async def get_time(timezone: str) -> str:
    """Get the current time in a timezone."""
    return f"The current time in {timezone} is 14:30"

class Assistant(Agent):
    def __init__(self):
        super().__init__(
            instructions="You are a helpful voice assistant with access to weather and time tools.",
            tools=[get_weather, get_time],
        )

async def entrypoint(ctx):
    session = AgentSession(
        llm=openai.LLM(
            model="openai/gpt-4o",
            base_url="https://api.orq.ai/v3/router",
            api_key=os.getenv("ORQ_API_KEY"),
        ),
    )
    await session.start(ctx.room, agent=Assistant())

if __name__ == "__main__":
    cli.run_app(WorkerOptions(entrypoint_fnc=entrypoint))
```
