while self hosting, after creating the livekit ser...
# ask-ai
m
while self hosting, after creating the livekit server and turn server, i have the API key, secret and URL, now if i want to deploy an agent from my local machine to my self hosted server in a VM , how to do that? give me a step by step explanation.
t
Thanks for reaching out, Milind. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To help you deploy an agent from your local machine to your self-hosted LiveKit server in a VM, here’s a simple step-by-step guide: 1. Configure Your LiveKit Server • First, make sure your LiveKit server is up and running on the VM. If it’s not set up yet, you can deploy it easily using Docker Compose and Caddy. You might find the
cloud-init
or
init_script.sh
methods handy for this setup. • Double-check that the server is accessible through its URL and that you have your API key and secret on hand. 2. Prepare the Agent • Create an environment configuration file (like a
.env
) including these details:
Copy code
LIVEKIT_URL=wss://your-domain.com
LIVEKIT_API_KEY=your_api_key
LIVEKIT_API_SECRET=your_api_secret
• Make sure your agent code is all set to connect to the LiveKit server. For instance, if you’re using Python, you can start it with:
python main.py dev
3. Deploy the Agent • Transfer your agent code over to the VM using tools like SCP or Git. • Run the agent on the VM, making sure it connects smoothly to the LiveKit server with the credentials you’ve provided. If you have any questions along the way or need help with things like scaling multiple agents, please don’t hesitate to reach out—I’m here to help! Sources: Deploy to a VM | LiveKit docs | An open source stack for real-time multimodal AI | Deploying to production | LiveKit Docs | README.md | cmd/lk/agent.go
m
is it necessary to run the agents in the vm? can't i just run lk agent create and get it deployed within the VM?
t
Thanks for reaching out! I wanted to share that the
lk agent create
and
lk agent deploy
commands are tailored specifically for LiveKit Cloud deployments, so they won’t work with self-hosted LiveKit servers. These commands connect directly with LiveKit's cloud infrastructure to manage agents, which doesn’t apply to self-hosted setups. For self-hosted servers, you’ll need to deploy and manage agents manually, usually using tools like Docker or Kubernetes. This means setting up the agent’s environment configuration yourself and running it on your own infrastructure. If you'd like, I’m here to help guide you through deploying agents manually or creating a custom workflow that fits your needs—just let me know! Sources: livekit/livekit_composite | DeepWiki | livekit/livekit_composite | DeepWiki | CLI Tools & Token Management | livekit/livekit_composite | DeepWiki | LiveKit Pricing | cmd/lk/agent.go
m
okay, i have the agent in my local machine, how do get it running in the vm?
t
Let's get your agent up and running in the VM together! Just follow these simple steps: 1. Transfer the Agent Code • First, package your agent code and transfer it to the VM. You can use handy tools like
scp
,
rsync
, or Git—whichever feels easiest for you. 2. Configure the Agent • Once you're on the VM, create an
.env
file inside the agent directory with these details:
Copy code
LIVEKIT_URL=wss://your-domain.com
LIVEKIT_API_KEY=your_api_key
LIVEKIT_API_SECRET=your_api_secret
3. Install Dependencies • Head over to the agent directory on the VM. • If you're using a Python agent, it’s a good idea to create a virtual environment and then run:
pip install -r requirements.txt
4. Run the Agent • Now, start the agent with this command:
python main.py dev
• This will connect your agent to your self-hosted LiveKit server smoothly. 5. Networking • Make sure the VM’s firewall is set to allow traffic on the necessary ports (like port
7880
for signaling and UDP ports for media). If you run into any bumps or have questions along the way, please don’t hesitate to reach out—I’m here to help! Sources: README.md | README.md | Running LiveKit locally | LiveKit Docs | Self-hosted SIP server | LiveKit docs | OpenAI and LiveKit partner to turn Advanced Voice into an API