Hi, my agent is successfully deployed on LK cloud,...
# ask-ai
l
Hi, my agent is successfully deployed on LK cloud, the logs shows agent is running, but I can not connect my frontend with it, and I tried playground, but it also did not work. Agent logs show there is not any connection request at all. I check credentials, but got confused, is the agent using the same credentials as the project where it is in? The credentials I used locally tested are all good, connection goes smooth. What could be the problem. My appreciation! Here is the log: {“level”: “INFO”, “name”: “livekit.agents”, “message”: “starting worker”, “version”: “1.3.3", “rtc-version”: “1.0.19", “timestamp”: “2025-11-20T153725.810818+00:00"} {“level”: “INFO”, “name”: “livekit.agents”, “message”: “preloading plugins”, “packages”: [“livekit.plugins.openai”, “livekit.plugins.deepgram”, “livekit.plugins.silero”, “livekit.plugins.turn_detector”, “av”], “timestamp”: “2025-11-20T153725.811018+00:00"} {“level”: “INFO”, “name”: “livekit.agents”, “message”: “initializing process”, “pid”: 47, “timestamp”: “2025-11-20T153727.677012+00:00”} {“level”: “INFO”, “name”: “livekit.agents”, “message”: “initializing process”, “pid”: 50, “timestamp”: “2025-11-20T153727.695706+00:00"} {“level”: “INFO”, “name”: “livekit.agents”, “message”: “process initialized”, “pid”: 47, “elapsed_time”: 0.39, “timestamp”: “2025-11-20T153728.064016+00:00"} {“level”: “INFO”, “name”: “livekit.agents”, “message”: “process initialized”, “pid”: 50, “elapsed_time”: 0.39, “timestamp”: “2025-11-20T153728.081151+00:00"} {“level”: “INFO”, “name”: “livekit.agents”, “message”: “registered worker”, “agent_name”: “”, “id”:“CAW_tEewkx5twDq8", is it because the agent uses a different set of credentials, if so, how do i find such credentials, or is there any other way for the agent to connect with the frontend, such info can not be found in the doc, it only says this: LiveKit secrets LiveKit Cloud provides the following environment variables automatically, to ensure your agent connects to its associated LiveKit Cloud project: •
LIVEKIT_URL
- Your LiveKit Cloud server URL •
LIVEKIT_API_KEY
- An API key for your project •
LIVEKIT_API_SECRET
- An API secret for your project
t
Thanks for reaching out, James. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — I’m responding to your questions about credentials and why the agent shows as running but never receives connection requests. Short answer: the agent uses the same project credentials injected by LiveKit Cloud, and it won’t join a room until it’s dispatched (either automatically for new rooms or explicitly). Your logs show the agent registered but no dispatch/job requests, so nothing has caused it to join a room yet. What to check and do next 1. Confirm credentials and project ◦ The agent uses the project’s LIVEKIT_URL, LIVEKIT_API_KEY, and LIVEKIT_API_SECRET that LiveKit Cloud injects at runtime. You do not need (and should not) provide a separate credential set for the agent. 1. Test with a new room (most common cause) ◦ Create/connect a brand-new room from your frontend (use a new room name). If your agent has no
agent_name
it auto-joins new rooms. ◦ Do not use the Playground for agent dispatch testing — Playground won’t trigger agent dispatch. 1. Or dispatch the agent explicitly ◦ If you want to target the agent or test immediately, dispatch it with the CLI: ▪︎
lk dispatch create --agent-name your-agent-name --room my-test-room
◦ Note: your log shows
"agent_name": ""
. If you need targeted/manual dispatch, set
agent_name
when configuring your worker. 1. Verify agent status and logs ◦ Run
lk agent status
to confirm the agent is Running (not Sleeping). ◦ After creating the new room or dispatching, watch agent logs for job assignment and room connection entries. 1. Ensure frontend uses the same project ◦ Make sure your frontend connects to the same LIVEKIT_URL and uses tokens/credentials from the same project where the agent is deployed. If you’d like, tell me: • The room name you’re attempting to use (or whether it already exists), and • Whether your agent was deployed with an
agent_name
set. I can guide you through creating a new room or the
lk dispatch
steps and interpreting the agent log lines to confirm dispatch. Sources: Secrets management | LiveKit Docs | Agent dispatch | LiveKit Docs | Agent deployment CLI reference | LiveKit docs
l
But why there are more api keys listed in the project after the deployment
t
You're seeing extra keys because those are the agent's external service secrets you provided at deployment — not new LiveKit project API keys. Key points: • LiveKit project credentials (LIVEKIT_URL, LIVEKIT_API_KEY, LIVEKIT_API_SECRET) are injected automatically by LiveKit Cloud and are the same credentials the agent uses. • Additional entries you see after deployment are user-provided secrets (e.g., OPENAI_API_KEY, DEEPGRAM_API_KEY) or file mounts you passed via
--secrets
,
--secrets-file
, or
--secret-mount
. • Deployments or CLI-generated artifacts can reference multiple secrets; each secret name is tracked even though values are never shown. To inspect what your agent has configured: • Run:
Copy code
lk agent secrets --id <your-agent-id>
This lists the secret names associated with that agent. If you want, tell me the secret names you see (or paste the output of the command) and I’ll help you identify which are LiveKit vs. external-service secrets and whether any look unexpected. Sources: Secrets management | LiveKit Docs | Agent Deployment & Docker | livekit/livekit_composite | DeepWiki | Agent deployment CLI reference | LiveKit docs | Deploying to production | LiveKit Docs | Deploying to custom environments | LiveKit Docs
l
No, in the project dashboard, click api keys, the is show more api keys of the project along with the old one
t
Thanks — I’m answering your observation about seeing extra API keys in the Project > API Keys page. What’s happening • LiveKit projects can have multiple project API keys. This is normal: multiple keys are useful for rotation, separate environments (dev/stage/prod), CI/service usage, or creating scoped keys for different clients. • Deploying an agent does not automatically create new LiveKit project API keys. The extra keys you see were either created by you/your team (CLI/dashboard) or generated by platform actions (for example a service or automation that created a key). Which key the agent uses • The agent uses the project credentials that LiveKit Cloud injects at runtime (
LIVEKIT_API_KEY
/
LIVEKIT_API_SECRET
). Those injected values correspond to one of the keys listed in the dashboard. How to identify/manage keys • Compare the key IDs/creation timestamps shown in the dashboard to determine which key is newest or which was created for the agent deployment. • If you need to know exactly which key the agent received, check deployment records or the Agent/Deployment configuration used at creation (the CLI or dashboard shows which key was referenced if a specific key was supplied). • Use key rotation as usual: create a new key, update consumers, then revoke the old key. If you want, share: • A screenshot (or the key IDs and timestamps) of the API Keys list — I can help identify likely candidates and advise next steps for rotating or removing keys.
l
I put the old credentials in the .env file, are those the ones the agent uses?
t
You're correct to double-check — the
.env
file is only used for local testing. When the agent runs on LiveKit Cloud, it uses the project credentials injected at runtime (
LIVEKIT_URL
,
LIVEKIT_API_KEY
,
LIVEKIT_API_SECRET
). The values in your local
.env
are ignored by the deployed agent. If you want to confirm what the deployed agent is using: • Check the agent’s runtime/deployment record or dashboard for creation timestamps and referenced keys. • Run
lk agent status
and then create a new room or dispatch to trigger connection logs; the agent logs will show job/room connection activity after dispatch. If you'd like, paste the API key IDs or the output of
lk agent secrets --id <agent-id>
and I’ll help identify which key in the dashboard matches the injected project key.
l
Is there not a way to check what exactly the credentials are the agent is using with one command or click?
t
Short answer: No — you cannot view the exact LIVEKIT_API_KEY or LIVEKIT_API_SECRET values for a deployed agent with one command or a dashboard click. Those secret values are encrypted and not retrievable for security reasons. What you can do instead • List secret names for the agent:
Copy code
lk agent secrets --id <agent-id>
This shows which secret names are configured (values are never shown). • Verify behavior and logs:
Copy code
lk agent logs --id <agent-id>
Look for authentication errors or job/room connection entries after you create a new room or dispatch the agent. • Confirm agent runtime and dispatch:
Copy code
lk agent status
Create a new room (or run
lk dispatch create ...
) and watch logs to confirm the agent received and accepted the job. If you want, share the agent ID and the API key IDs/timestamps you see in the dashboard and I’ll help match likely candidates and suggest next steps (rotate/update keys or force a redeploy). Sources: Secrets management | LiveKit Docs | Agent deployment CLI reference | LiveKit docs | Log collection | LiveKit Docs | Builds and Dockerfiles | LiveKit Docs
l
Show me how to create a room
t
You can create a room two simple ways — let it auto-create when a participant joins (recommended), or explicitly create one. To test agent dispatch, the easiest flow is to create/join a new room so the agent will be dispatched and join. 1) Quick (recommended) — auto-create by joining from your frontend • Generate a server-side token for the room name you want (e.g.,
test-room-123
). • In your frontend, connect with that token:
Copy code
import { Room } from 'livekit-client';

const room = new Room();
await room.connect('wss://your-livekit-url', token);
console.log('Connected to room:', room.name);
When the first participant (your frontend) connects, the room is created automatically; if your agent is configured to auto-join, it will be dispatched to that new room. 2) Dispatch + create a new room (explicitly trigger agent) • Use the CLI to create a new room and dispatch the agent:
Copy code
lk dispatch create --new-room --agent-name my-agent --room test-room-123
This creates the room and assigns
my-agent
to it. Then connect your frontend to
test-room-123
with a matching token. 3) Explicit API/CLI create (only if you need custom room settings) • CLI:
Copy code
lk room create --empty-timeout 600 test-room-123
• Or via server SDK (Go example):
Copy code
room, _ := roomClient.CreateRoom(ctx, &livekit.CreateRoomRequest{
  Name: "test-room-123",
  EmptyTimeout: 600,
  MaxParticipants: 20,
})
Note: explicit CreateRoom adds cross-region sync latency; prefer auto-create on join unless you need special room config. Checklist to ensure agent joins • Use a brand-new room name (auto-join only triggers for new rooms). • Ensure frontend tokens are for the same project where the agent is deployed. • If agent has an
agent_name
, use
lk dispatch create
to target it. • Watch agent logs after creating/joining the room (lk agent logs --id <agent-id>) for job assignment and connection messages. Tell me which method you want (frontend auto-join, CLI dispatch, or API create) and I’ll give exact token-generation sample code for your stack. Sources: Rooms, participants, and tracks | LiveKit docs | CreateRoom() is Taking Too Long | Agents telephony integration | LiveKit Docs | JavaScript quickstart (web) | LiveKit docs | Authentication | LiveKit docs
l
auto create, does that mean to connect the frontend with the agent, then are we not going back to the old problem?!!! We do not know what credentials the agent is using!
t
You’re right to be concerned — let me be clear and practical. Short answer: auto-create does NOT make the frontend “connect directly to the agent.” It makes the room appear when the first participant (your frontend) joins. The agent will be dispatched to that room by LiveKit Cloud if it’s configured to auto-join. You do not need to know the agent’s secret values to make this work. Why this is safe and how it works • The agent runs with the project’s injected credentials (
LIVEKIT_URL
,
LIVEKIT_API_KEY
,
LIVEKIT_API_SECRET
). Those values are intentionally not viewable. • Your frontend must use a token generated with the same project credentials (server-side). That token authenticates the frontend to the same project and room. • When the frontend joins a new room, LiveKit Cloud will dispatch the agent (if configured) and the agent will join that room — no secret exposure required. Concrete steps to test now 1. On your server, generate a token for the room name you’ll use (same project credentials your server already uses). Example (Node.js, server-side):
Copy code
import { accessToken, RoomServiceClient, createLocalToken } from 'livekit-server-sdk';
const at = new AccessToken(YOUR_API_KEY, YOUR_API_SECRET);
at.addGrant({ room: 'test-room-123', roomJoin: true });
const token = at.toJwt();
(If you want, tell me your server stack and I’ll provide the exact snippet.) 1. In your frontend, connect to the same LiveKit URL with that token:
Copy code
await room.connect('wss://your-livekit-url', token);
1. Watch the agent logs:
Copy code
lk agent logs --id <agent-id>
After the frontend connects to the new room, the agent logs should show a job assignment and room connection. That proves the frontend and agent are in the same project/room. If the agent does not join, check these quickly • You used a brand-new room name (auto-join only triggers for new rooms). • Frontend token was generated using the same project API key/secret as the deployed agent’s project. • Agent is Running (not Sleeping):
lk agent status
. • No authentication errors in agent logs after you join. If you want, tell me: • Which server language you use for token generation, and • The room name you’ll test I’ll give an exact token-generation snippet and the exact log lines to look for.
l
you are making it very confusing now! in your first answer quite different things from the latest answer. Can I do it very simply: revoke all the api key in the dashboard, then create a new one, then use the credentials under this new one in the frontend, then problems solved?
t
Yes — that is a simple, valid way to reset everything and ensure frontend and agent use the same project credentials. Do this carefully so you don't interrupt live users. Safe step-by-step 1. Create a new API key in the Project > API Keys page. Copy its API key and secret somewhere secure. 2. Update your server-side token generator to use the new API key/secret, then deploy that token-generator change. 3. Verify frontend connections with tokens produced from the new key/secret (connect a test frontend to a new room name). 4. Confirm the agent joins that new room (watch agent logs:
lk agent logs --id <agent-id>
). 5. Once you verify frontend + agent work with the new key, revoke the old keys in the dashboard. Important notes • Do not put API secrets in frontend code; only use them server-side to mint tokens. • Revoke old keys only after you confirm the new key works to avoid downtime. • If the agent was deployed with no explicit
agent_name
it will auto-join newly created rooms — use a new room name for the test. If you’d like, tell me the agent ID and the new key’s creation timestamp and I’ll outline the exact verification log lines to expect.
l
what is this: Update your server-side token generator to use the new API key/secret, then deploy that token-generator change.
t
"Update your server-side token generator" means change the code on your backend that mints LiveKit join tokens so it uses the new API key/secret you created — then redeploy that backend so it starts issuing tokens signed with the new key. Frontends use those tokens to join rooms; they never see the API secret. Why this is necessary (short) • LiveKit API secret must stay server-side for security. • Tokens are JWTs signed with your project API key/secret; if the backend still signs tokens with an old/revoked key, frontends won’t authenticate to the project the agent is using. What to do (minimal steps) 1. Replace API key/secret in your backend’s configuration (env or secret store) with the new key/secret. 2. Redeploy/restart that backend so the new values take effect. 3. Use the backend to request a token for a test room and connect the frontend with that token. 4. Verify agent joins the new room and logs show job/connection. Example token-generation (pick your stack) • Node (server):
Copy code
import { AccessToken, VideoGrant } from 'livekit-server-sdk';
const at = new AccessToken(process.env.LK_API_KEY, process.env.LK_API_SECRET);
at.addGrant(new VideoGrant({ room: 'test-room-123', roomJoin: true }));
const token = at.toJwt();
• Python (server):
Copy code
from livekit import AccessToken, grants
at = AccessToken(os.environ['LK_API_KEY'], os.environ['LK_API_SECRET'])
at.add_grant(grants.VideoGrant(room='test-room-123', room_join=True))
token = at.to_jwt()
Important reminders • Do not put API secrets in frontend code. • Use a new room name when testing auto-join agents. • Revoke old keys only after you confirm the new key works. If you tell me your backend language (Node, Python, Go, etc.), I’ll provide the exact snippet and the one command to redeploy/update the env var.
l
you keep giving me conflicting answers, I have to delete all the keys first, then create new, because we can not know what credentials the agent is using from the dashboard as you said before.
t
You’re right — let’s make this simple and final. Revoking all existing project API keys and creating one new key is a valid way to ensure both your frontend (via server tokens) and the deployed agent use the same project credentials. Follow these exact steps to do it safely with minimal downtime. Step‑by‑step (safe, minimal disruption) 1. Create the new API key ◦ In Project → API Keys, create a new key. Save the API key and secret securely (server only). 1. Update your server token generator ◦ Replace the old API key/secret in your server’s config/env with the new ones. ◦ Redeploy or restart that server so it begins signing tokens with the new key. Example (Node):
Copy code
const at = new AccessToken(process.env.LK_API_KEY, process.env.LK_API_SECRET);
   at.addGrant(new VideoGrant({ room: 'test-room-123', roomJoin: true }));
   const token = at.toJwt();
1. Verify the new key works (do this before revoking anything) ◦ From your server, request a token for a brand-new room name (e.g.,
test-reset-123
). ◦ In your frontend, connect using that token: ▪︎ Connect to your LiveKit URL with the token. ◦ Watch agent logs for dispatch/room join:
Copy code
lk agent logs --id <agent-id>
• Confirm agent shows job assignment and room connection. 1. If verification succeeds, revoke the old keys ◦ Revoke old API keys in the dashboard. Do not revoke the new key. ◦ Confirm production traffic still works. Why this solves your problem • You cannot view injected secret values after deployment. Replacing keys guarantees both sides use the same project credentials without needing to read secrets. • The agent uses whatever project key LiveKit injects at runtime. By switching to one known key and updating your token generator, frontend tokens and the agent will authenticate to the same project. If you want, I can: • Provide the exact token-generation snippet for your backend language, or • Tell you the specific log lines to look for to confirm the agent joined. Which would you like?
l
Update your server token generator ◦ Replace the old API key/secret in your server’s config/env with the new ones. but you said before the agent will ignore the credentials in this file .env
t
You’re right to flag the confusion — here’s the clear, final explanation and exactly what to change. Short clarity • The agent deployed on LiveKit Cloud receives the project’s LIVEKIT_URL / LIVEKIT_API_KEY / LIVEKIT_API_SECRET automatically from the platform. You cannot read or change those injected values from the dashboard or .env after deployment. • Your local
.env
is only used for local testing of the agent — the deployed agent ignores your local
.env
. • Your server-side token generator is a separate component that mints JWT tokens for frontends. It must use the project API key/secret to sign tokens. Those signed tokens (not the raw secret) are what frontends use to join rooms. Why you must update the server token generator when rotating keys • If you create a new project API key/secret, you must update the server that mints tokens so it signs tokens with the new secret. If you don’t, tokens will be signed by an old (or revoked) key and frontends will fail to authenticate to the project the agent is in. Exactly what to do (minimal steps) 1. Create new API key in Project → API Keys and save key+secret securely. 2. On your token server: ◦ Replace the old key/secret in its config/env with the new key/secret. ◦ Redeploy/restart that server so it begins signing tokens with the new key. 1. Test with a new room name: ◦ From your token server request a token for
test-reset-123
. ◦ Connect frontend using that token. ◦ Check agent logs:
lk agent logs --id <agent-id>
— you should see job assignment and room join. 1. If successful, revoke old API keys in the dashboard. Example token snippets (use server-side only) • Node:
Copy code
const at = new AccessToken(process.env.LK_API_KEY, process.env.LK_API_SECRET);
at.addGrant(new VideoGrant({ room: 'test-reset-123', roomJoin: true }));
const token = at.toJwt();
• Python:
Copy code
at = AccessToken(os.environ['LK_API_KEY'], os.environ['LK_API_SECRET'])
at.add_grant(VideoGrant(room='test-reset-123', room_join=True))
token = at.to_jwt()
One last reassurance • You do NOT need to (and should not) change the agent’s deployed container
.env
. Only update the server that generates frontend tokens. Rotating keys this way guarantees both frontend tokens and the deployed agent authenticate to the same project. If you tell me your token-server language (Node, Python, Go, etc.), I’ll give the exact snippet and the single command you can run to redeploy with the new env var.
l
my backend is python, so the code will be different for deployment than the one i run locally?
t
Short answer: the Python code to generate tokens is the same locally and in production, but the environment where that code runs must be updated to use the new API key/secret and then redeployed. What to do (Python-specific, minimal) 1) Replace env vars in your deployment • Locally you may use a `.env`; in production update the environment/store your service uses (e.g., Docker env, systemd, Cloud Run secrets, Heroku config vars, etc.) so
LK_API_KEY
/
LK_API_SECRET
(or
LIVEKIT_API_KEY
/
LIVEKIT_API_SECRET
as you name them) hold the new values. 2) Redeploy/restart the token service • Restart the process or redeploy the container so the service picks up the new env values. 3) Token-generation code (same for local & prod) • Example (Python server-side):
Copy code
import os
from livekit import AccessToken, grants

def create_token(room_name: str, identity: str) -> str:
    at = AccessToken(os.environ['LK_API_KEY'], os.environ['LK_API_SECRET'], identity=identity)
    at.add_grant(grants.VideoGrant(room=room_name, room_join=True))
    return at.to_jwt()
• Call this endpoint from your frontend to get a token; never put API secrets in frontend code. 4) Test (before revoking old keys) • Generate a token for a brand-new room (e.g.,
test-reset-123
) using the redeployed server. • Connect the frontend with that token. • Watch agent logs:
Copy code
lk agent logs --id <agent-id>
You should see job assignment and room connection entries after the frontend connects. 5) Revoke old keys only after verification • Once agent + frontend connect successfully with the new key, revoke old keys in the dashboard. If you tell me where your token service is deployed (Docker, Cloud Run, Heroku, etc.), I’ll give the exact command or steps to update the env vars and redeploy.
l
in dev, the python code is only this: load_dotenv(), and it reads the credentials in the .env file, now you said the production ignores the credentials in .env, the python code does not have to change still?
t
You’re right to check — here’s the clear answer. Short: Your Python token-generation code does not need to change between dev and prod. What changes is how the environment variables are provided. Why • In dev: you use load_dotenv() to load keys from a local
.env
into
os.environ
. That’s fine for local testing. • In production: you should NOT rely on a
.env
file. Instead, set the API key/secret as environment variables in your deployment platform (Cloud Run, Docker, Heroku, systemd, etc.). The code still reads
os.environ['LK_API_KEY']
/
os.environ['LK_API_SECRET']
the same way. What to do (minimal) 1. Keep your token code unchanged. Example:
Copy code
import os
from livekit import AccessToken, grants

def create_token(room_name, identity):
    at = AccessToken(os.environ['LK_API_KEY'], os.environ['LK_API_SECRET'], identity=identity)
    at.add_grant(grants.VideoGrant(room=room_name, room_join=True))
    return at.to_jwt()
1. Remove or ignore load_dotenv() in production (optional, harmless if present). 2. Set the env vars in your deployment: ◦ Docker: pass envs in the container or use Docker secrets. ◦ Cloud Run: set environment variables or use Secret Manager. ◦ Heroku: use Config Vars. ◦ Systemd: set Environment= in the unit or export in the service’s environment file. 1. Redeploy/restart the token service so it picks up the new env vars. 2. Test with a new room token and verify the agent joins. If you tell me where you deploy (Cloud Run, Docker, Heroku, etc.), I’ll give the exact command/steps to set the env vars and restart.
l
cloud run
t
Understood — you’re on Cloud Run. Below are concise, exact steps and commands to update your token service’s env vars with the new LiveKit API key/secret, redeploy, and verify it works. 1) Create a new API key in the dashboard • Save the API_KEY and API_SECRET securely (do not expose to frontend). 2) Update Cloud Run service env vars (replace placeholders) • From Cloud Shell or where gcloud is configured:
Copy code
# Set variables
PROJECT_ID=your-gcp-project
SERVICE_NAME=your-cloud-run-service
REGION=your-region
NEW_KEY=lk_xxx_new_key
NEW_SECRET=lk_secret_xxx_new_secret

# Deploy with updated env vars (keeps existing image)
gcloud run deploy "$SERVICE_NAME" \
  --project="$PROJECT_ID" \
  --region="$REGION" \
  --update-env-vars=LK_API_KEY="$NEW_KEY",LK_API_SECRET="$NEW_SECRET"
Notes: • If your service already uses other env vars, use
--update-env-vars
(it updates/merges). If you prefer to set all envs explicitly, use
--set-env-vars
with a full list. • You can also add secrets from Secret Manager instead of plain env vars (recommended). 3) (Optional) Use Secret Manager (recommended) • Store secret values:
Copy code
echo -n "$NEW_SECRET" | gcloud secrets create livekit-api-secret --data-file=-
echo -n "$NEW_KEY"    | gcloud secrets create livekit-api-key --data-file=-
• Grant Cloud Run service account access:
Copy code
SERVICE_ACCOUNT=$(gcloud run services describe "$SERVICE_NAME" --region="$REGION" --project="$PROJECT_ID" --format='value(spec.template.spec.serviceAccountName)')
gcloud secrets add-iam-policy-binding livekit-api-secret --member="serviceAccount:$SERVICE_ACCOUNT" --role="roles/secretmanager.secretAccessor"
gcloud secrets add-iam-policy-binding livekit-api-key --member="serviceAccount:$SERVICE_ACCOUNT" --role="roles/secretmanager.secretAccessor"
• Mount at deploy:
Copy code
gcloud run deploy "$SERVICE_NAME" \
  --project="$PROJECT_ID" \
  --region="$REGION" \
  --update-secrets=LK_API_SECRET=livekit-api-secret:latest,LK_API_KEY=livekit-api-key:latest
4) Verify deployment & token generation • Confirm Cloud Run revision is ready:
Copy code
gcloud run services describe "$SERVICE_NAME" --region="$REGION" --project="$PROJECT_ID" --format="value(status.latestReadyRevisionName)"
• Call your token endpoint to get a token for a NEW room:
Copy code
curl -s https://<your-cloud-run-url>/token?room=test-reset-123 -o token.jwt
• In frontend, connect using that token to a new room (
test-reset-123
). Or locally use livekit-client to connect. 5) Confirm agent joins • After frontend connects, watch agent logs:
Copy code
lk agent logs --id <agent-id>
You should see job assignment and room connection log entries. 6) Revoke old keys • Once you confirm agent + frontend work with the new key, revoke old API keys in the LiveKit dashboard. If you want, I can: • Provide the exact curl/post body to call your token endpoint if you share its path, or • Give the single command to redeploy using Secret Manager for your SERVICE_NAME and REGION. Which would you prefer?
l
no, it is deployed following these: 1. lk cloud auth 2. 3. 4. This opens a browser window to link your LiveKit Cloud project to the CLI. If you’ve already authenticated and have linked projects, use
lk project list
to list all linked projects. Then, set the default project for agent deployment with
lk project set-default "<project-name>"
. 5. Deploy your agent: 6. lk agent create
t
Thanks — since you deployed the agent with
lk agent create
, here’s the clear, final picture and exact safe steps to rotate keys and verify frontend + agent match. Quick facts • An agent deployed via
lk agent create
receives the project’s
LIVEKIT_URL
,
LIVEKIT_API_KEY
, and
LIVEKIT_API_SECRET
automatically from LiveKit Cloud at runtime. You cannot read those injected values from the dashboard or agent. • Your local
.env
is only for local testing; the deployed agent ignores it. • Frontends authenticate by using tokens your server mints. Those tokens must be signed with the same project API key/secret the project (and thus the agent) uses. Safe, minimal steps to guarantee frontend + agent use the same credentials 1. Create a new project API key in the LiveKit dashboard. Save key + secret securely. 2. Update your token service (deployed on Cloud Run): ◦ Replace the env vars the service uses for the API key/secret with the new values (or use Secret Manager and map them into Cloud Run). ◦ Redeploy/update the Cloud Run service so it uses the new key/secret. ◦ Your Python token code stays the same; it reads from env vars. 1. Test before revoking old keys: ◦ From your token service, request a token for a BRAND-NEW room name (e.g.,
test-reset-123
). ◦ Connect your frontend with that token to create/join the room. ◦ Watch agent logs:
lk agent logs --id <agent-id>
— you should see a job assignment and room connection. 1. If the agent joins successfully, revoke old API keys in the dashboard. Why this works • You cannot view the agent’s injected secret, so rotating to a single known key and updating your token server guarantees both sides authenticate to the same project without needing to read secrets. If you want, I’ll give the exact Cloud Run command to update env vars or Secret Manager commands based on your SERVICE_NAME and REGION — which do you prefer?
l
it’s getting more and more confusing, let’s make it very simple, on the local, my frontend and backend have the same credentials,
LIVEKIT_URL
,
LIVEKIT_API_KEY
, and
LIVEKIT_API_SECRET,
they use these to find each other and communicate. period. such credentials are store in an .env for the backend and a .env. local for the frontend. Now, the agent is deployed(the backend) on livekit cloud, what changes should we do to make the agent communicate with the frontend just as local? Give me operational steps, please stop explaining things like you are give a lecture.
t
Understood — no lecture. Exact operational steps to make deployed agent communicate with your frontend like local. Prerequisite: you have dashboard access and Cloud Run token service running. 1) Create a new project API key (dashboard) • In LiveKit Project → API Keys, create a new key. Copy API_KEY and API_SECRET. 2) Update backend token service (Cloud Run) • Replace env vars on Cloud Run with the new key/secret (or use Secret Manager). Example (replace placeholders):
Copy code
gcloud run deploy YOUR_SERVICE \
    --region=YOUR_REGION \
    --update-env-vars=LK_API_KEY="NEW_KEY",LK_API_SECRET="NEW_SECRET"
• Wait for the revision to become ready. 3) Update frontend local config • Replace values in your frontend
.env.local
with: ◦ LIVEKIT_URL = your project URL (unchanged) ◦ LIVEKIT_API_KEY = NEW_KEY ◦ LIVEKIT_API_SECRET = NEW_SECRET • Important: Do NOT ship API_SECRET to production frontend; this is just for your local test only. 4) Redeploy/restart frontend (if hosted) or reload local frontend • For local test, restart dev server so it reads
.env.local
. 5) Test with a brand-new room name • From your backend token endpoint (now using NEW_KEY/NEW_SECRET), request a token for room:
test-reset-123
• In frontend, connect using that token to
test-reset-123
. 6) Verify agent joins • Tail agent logs:
Copy code
lk agent logs --id <agent-id>
• Expected: you see job assignment and room connection after frontend connects. 7) If agent joined successfully — revoke old keys • Revoke all old API keys in dashboard. If you want, give me: • Your Cloud Run SERVICE name and REGION and I’ll give the exact gcloud command with placeholders filled.
l
no, there is nothing to do with gcloud, we use livekit cloud!!!!!!!!!!!!!!!!
t
Thanks — clear, no GCloud. Exact operational steps for LiveKit Cloud (using the LiveKit CLI) so your deployed agent and your frontend match like local. Prerequisites: • You use
lk
CLI and are set to the correct LiveKit project. • You can run
lk agent
and
lk dispatch
commands. Steps 1) Create a new project API key (dashboard) • In LiveKit Project → API Keys, create a new key. Copy the API key and secret. 2) Update your token server (the backend that mints tokens) • On the machine/service that runs your token-generation code, set env vars to the new values: ◦ LIVEKIT_API_KEY = <new_key> ◦ LIVEKIT_API_SECRET = <new_secret> ◦ LIVEKIT_URL = <project_livekit_url> • Redeploy/restart that token server so it uses the new env vars. 3) Keep agent deployment unchanged • Do NOT modify the deployed agent container or its .env. LiveKit Cloud injects the project credentials into the agent automatically; you cannot and should not try to overwrite them. 4) Test with a brand-new room • From your token server (now using the new key/secret), request a token for room name: test-reset-123. • In your local frontend, call your token endpoint and connect to the room using the returned token. 5) Verify agent joined • Run: ◦ lk agent logs --id <agent-id> • After frontend connects, logs should show job assignment and room connection. 6) If it works, revoke old keys • In the dashboard, revoke old API keys. Do this only after successful verification. If the agent does not join after step 4, tell me: • Output of
lk agent status
• The room name you used I’ll tell you the exact log lines to expect and next action.
l
how do you do this step: 2) Update your token server (the backend that mints tokens) • On the machine/service that runs your token-generation code, set env vars to the new values: ◦ LIVEKIT_API_KEY = <new_key> ◦ LIVEKIT_API_SECRET = <new_secret> ◦ LIVEKIT_URL = <project_livekit_url> • Redeploy/restart that token server so it uses the new env vars.
t
Tell me where your token server runs (local machine, Docker, Cloud Run, Heroku, systemd, Kubernetes, or other). I’ll give the exact commands for that environment. If you want a quick common set, here they are: 1) Local machine • Update your
.env
(or env file) values: LIVEKIT_URL=<project_livekit_url> LIVEKIT_API_KEY=<new_key> LIVEKIT_API_SECRET=<new_secret> • Restart app (example): ◦ If using gunicorn/system: restart the process ◦ If running with `python app.py`: stop and start the process 2) Docker container • Rebuild/redeploy with new envs: docker run -e LIVEKIT_URL=<url> -e LIVEKIT_API_KEY=<new_key> -e LIVEKIT_API_SECRET=<new_secret> your-image • Or update compose and
docker-compose up -d
3) Cloud Run (if later relevant) • Use: gcloud run deploy SERVICE --region=REGION --update-env-vars=LIVEKIT_API_KEY=<new_key>,LIVEKIT_API_SECRET=<new_secret>,LIVEKIT_URL=<url> 4) Heroku • Set config: heroku config:set LIVEKIT_API_KEY=<new_key> LIVEKIT_API_SECRET=<new_secret> LIVEKIT_URL=<url> --app YOUR_APP • Restart dynos if needed:
heroku ps:restart --app YOUR_APP
5) systemd • Edit service env or /etc/default/your-service to set vars, then: sudo systemctl daemon-reload sudo systemctl restart your-service 6) Kubernetes • Update secret or deployment env and rollout restart: kubectl create secret generic livekit-creds --from-literal=LIVEKIT_API_KEY=<new_key> --from-literal=LIVEKIT_API_SECRET=<new_secret> -o yaml --dry-run=client | kubectl apply -f - kubectl set env deployment/your-deployment --from=secret/livekit-creds kubectl rollout restart deployment/your-deployment 7) Verify • Call your token endpoint to mint a token for a NEW room and connect frontend. • Tail logs or check health to confirm service picked up new envs. Tell me which environment you use and I’ll give the single exact command(s).
l
livekit cloud!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
t
Understood — no fluff. You deployed the agent with
lk agent create
on LiveKit Cloud. The only thing you need to change is the token server that mints JWTs for your frontend. You do NOT change the deployed agent. Exact steps (LiveKit Cloud context): 1) Create a new project API key in the LiveKit dashboard. Copy the API key and secret. 2) On the machine/service that runs your token server (where your Python code runs), set these env vars: • LIVEKIT_URL=<your_project_livekit_url> • LIVEKIT_API_KEY=<new_key> • LIVEKIT_API_SECRET=<new_secret> 3) Restart/redeploy that token server process so it reads the new env vars. • If local: update .env / .env.local and restart your process (stop then
python app.py
or restart your process manager). • If hosted somewhere, update that service’s env configuration and restart there. 4) Test (before revoking old keys) • Call your token endpoint to mint a token for a BRAND-NEW room (e.g.,
test-reset-123
). • In your frontend, connect to LIVEKIT_URL with that token. • Tail agent logs:
lk agent logs --id <agent-id>
— confirm job assignment and room join. 5) If agent joined, revoke old API keys in the dashboard. If you tell me exactly where the token server runs (local dev machine, Docker, Cloud Run, Heroku, Kubernetes, etc.), I’ll give the single exact command you need to set env vars and restart.
l
yes, you have repeated this for many times, i am asking you how to do this step: 2) On the machine/service that runs your token server (where your Python code runs), set these env vars: • LIVEKIT_URL=<your_project_livekit_url> • LIVEKIT_API_KEY=<new_key> • LIVEKIT_API_SECRET=<new_secret>
t
Which environment is your token server running in? Choose one: local machine, Docker, Cloud Run, Heroku, systemd, or Kubernetes. I’ll give the single exact commands for that environment.
l
livekit cloud!!!!!!!!!!!!!!!!!!!!!!!!!
t
You deployed the agent on LiveKit Cloud and want one clear operational path. Pick one of the two options below and I’ll give the single exact command(s) you need. Option A (recommended) — Host token server outside LiveKit Cloud • If you pick this, tell me EXACTLY where you will host it: local machine, Docker, Cloud Run, Heroku, systemd, or Kubernetes. • I will give the single command(s) to set these env vars and restart that service: ◦ LIVEKIT_URL=<your_project_livekit_url> ◦ LIVEKIT_API_KEY=<new_key> ◦ LIVEKIT_API_SECRET=<new_secret> Option B — Redeploy an agent that runs the token server • If you want the token server as an agent, provide: ◦ the container image name (or confirm you want the CLI to build the default), ◦ any external secret names/values you need injected. • I will give the exact
lk agent create ...
command (including `--secrets`/`--secrets-file`) using the new project API key you create. Which option and which environment (if A) or image/secrets (if B)? I’ll then give the single exact command to run.
l
……………..
t
I don't have the answer you're looking for. You could also try asking your question: • in one of the other Slack channels or • to https://deepwiki.com/livekit/livekit_composite which is trained on all LiveKit source code If you find the answer, please post it here to help others!