Agent connects to LiveKit Cloud instead of local self-hosted server

This question originally came up in our Slack community and the thread has been consolidated here for long-term reference.

I am new to LiveKit and self-hosted servers. I created an agent.py using the docs, but when I run uv run agent.py console it always connects to wss://agent-gateway.livekit.cloud/v1/stt instead of my local server.

I have added ws_url, api_key, api_secret, host, and port to AgentServer.

It sounds like you need to set your default project to your local environment. When you build and deploy, you’re probably building off a cloud project, so it’s assuming cloud auth and URL.

Use the LiveKit CLI to add your local project:

lk project add my-project \
  --url http://localhost:7880 \
  --api-key <my-api-key> \
  --api-secret <my-api-secret> \
  --default

Check your current projects with:

lk project list

See the documentation: Project management | LiveKit Documentation