can we use "projects" with api key and secret with...
# ask-ai
a
can we use "projects" with api key and secret with separate URL in self hosting livekit too?
t
Thanks for reaching out, Hiren. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Yes, you can use API keys and secrets with separate URLs in a self-hosted LiveKit setup. For self-hosted servers, it is recommended to use separate deployments for different environments (e.g., staging, production, and development). Each deployment would have its own unique URL, API key, and secret, similar to how LiveKit Cloud uses separate projects for each environment. You can configure each environment using environment variables in files like
.env.local
or
.env.development.local
, containing:
Copy code
LIVEKIT_API_KEY=<your api key>
LIVEKIT_API_SECRET=<your api secret>
LIVEKIT_URL=<your livekit server url>
This setup ensures proper separation and management of environments. Sources: Deploying to production | LiveKit Docs | Next.js 13+ quickstart | LiveKit Docs
a
Nope, here I've a single livekit server running, on which I want to use different different voicepipeline agents like industry wise, how can I do that?
t
To use different voice pipeline agents (e.g., industry-specific) on a single LiveKit server, you can achieve this through explicit agent dispatch. Here’s how you can set it up: 1. Set the
agent_name
field:
When registering your agents, specify the
agent_name
in `WorkerOptions`: `opts = WorkerOptions( ... agent_name="test-agent", )`This ensures the agent is not automatically dispatched to newly created rooms. 2. Dispatch agents to rooms: You can dispatch these named agents in several ways: ◦ Via API: Use the
AgentDispatchService
to explicitly dispatch agents to rooms:
Copy code
import asyncio
from livekit import api

async def create_explicit_dispatch():
    lkapi = api.LiveKitAPI()
    dispatch = await lkapi.agent_dispatch.create_dispatch(
        api.CreateAgentDispatchRequest(
            agent_name=agent_name, room=room_name, metadata="my_job_metadata"
        )
    )
From inbound SIP calls: Use SIP dispatch rules to route calls to specific agents. ◦ On participant connection: Configure a participant’s token to include agent dispatch:
Copy code
from livekit.api import (
    AccessToken,
    RoomAgentDispatch,
    RoomConfiguration,
    VideoGrants,
)

def create_token_with_agent_dispatch() -> str:
    token = (
        AccessToken()
        .with_identity("my_participant")
        .with_grants(VideoGrants(room_join=True, room=room_name))
        .with_room_config(
            RoomConfiguration(
                agents=[
                    RoomAgentDispatch(agent_name="test-agent", metadata="my_metadata")
                ],
            ),
        )
        .to_jwt()
    )
    return token
1. Multi-agent systems: You can also implement a multi-agent system where one agent hands off to another during a session. Refer to the
multi_agent.py
example for guidance. This setup allows you to manage and dispatch agents effectively on a single LiveKit server. Sources: Dispatching agents | LiveKit Docs | Tree View: | dse-workbench