what API should I use on my server side to list al...
# ask-ai
a
what API should I use on my server side to list all my deployed agents?
t
Thanks for reaching out, Anne. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hey there! You can easily use the CloudAgent API on your server side to get a list of all your deployed agents. The
ListAgents
method is just what you need for this. It’s available through LiveKit server SDKs, like the Go SDK, where you’ll find the
ListAgents
function inside the
AgentClient
. Just a heads up, the
ListAgents
method needs you to authenticate with a LiveKit API key and secret that have the right permissions. You’ll pass in a
ListAgentsRequest
object when calling it. If you send an empty request, it’ll happily return all the agents in your project. The response you get back includes a list of
AgentInfo
objects, each one packed with details like the agent’s ID, version, when it was deployed, the region, current status, and resource usage. If you want a hand with setting this up or have any questions, just give me a shout—I’m here to help! Sources: cmd/lk/agent.go | protobufs/livekit_cloud_agent.proto | agent_client.go | Agent deployment CLI reference | LiveKit Docs
a
can you please give me a python example, I use this
Copy code
lkapi = livekit_api.LiveKitAPI(
            url=config.livekit_url, api_key=config.livekit_api_key, api_secret=config.livekit_api_secret
        )
t
Here's a friendly Python example to help you use the
ListAgents
method and list all your deployed agents:
Copy code
import requests
import json
import base64
import hmac
import hashlib

# Configuration
base_url = "https://your-project.livekit.cloud"
api_key = "your_api_key"
api_secret = "your_api_secret"

# Function to create JWT token
def create_jwt_token(api_key, api_secret):
    header = {"alg": "HS256", "typ": "JWT"}
    payload = {"iss": api_key}
    encoded_header = base64.urlsafe_b64encode(json.dumps(header).encode()).decode().strip("=")
    encoded_payload = base64.urlsafe_b64encode(json.dumps(payload).encode()).decode().strip("=")
    signature_input = f"{encoded_header}.{encoded_payload}"
    signature = hmac.new(api_secret.encode(), signature_input.encode(), hashlib.sha256).digest()
    signature_b64 = base64.urlsafe_b64encode(signature).decode().strip("=")
    return f"{encoded_header}.{encoded_payload}.{signature_b64}"

# Construct request
url = f"{base_url}/twirp/livekit.CloudAgent/ListAgents"
headers = {
    "Content-Type": "application/json",
    "Authorization": f"Bearer {create_jwt_token(api_key, api_secret)}"
}

# Request payload
data = {}  # Empty payload to list all agents

response = requests.post(url, headers=headers, json=data)
if response.status_code == 200:
    agents = response.json().get("agents", [])
    for agent in agents:
        print(f"ID: {agent['agent_id']}, Name: {agent['agent_name']}, Version: {agent['version']}")
else:
    print(f"Oops! Something went wrong: {response.status_code}, {response.text}")
Just swap out
your-project.livekit.cloud
,
your_api_key
, and
your_api_secret
with your own LiveKit project details. This example also shows how to generate the JWT token you’ll need for authentication with the LiveKit API. If you hit any snags or have questions, feel free to ask—I’m here to help! Sources: README.md | livekit/livekit_cloud_agent.pb.go | cmd/lk/agent.go | Agent deployment CLI reference | LiveKit Docs
a
what should the base_url be ?|
t
Hey there! The
base_url
for your LiveKit API requests should be the URL of your LiveKit server or your cloud project. For instance, if you’re using LiveKit Cloud, it usually looks something like this:
https://your-project.livekit.cloud
Just swap out
your-project
with the actual name of your LiveKit project. And if you’re running LiveKit on your own server, go ahead and use your server’s URL instead. If you’re unsure about your project URL or want a hand figuring it out, just give me a shout—I’m here to help!
a
I get a 200 but response.json(). raises an error
t
Hey there! If
response.json()
is giving you trouble, it might be because of a couple of reasons: • The response body isn’t valid JSON. This can happen if the server sent back something unexpected or an error message that’s not in JSON format. • The server might have returned an error (like permission denied) with a status code other than 200, and the code tried to parse it as JSON without checking the status first. To get to the bottom of this, try checking out the raw response content and status code before calling `response.json()`:
Copy code
print(response.status_code)
print(response.text)
If the status code isn’t 200, the response might actually have an error message in JSON. Feel free to share what you find, and I’ll be happy to help you figure it out! Sources: cmd/lk/agent.go | livekit-api/livekit/api/twirp_client.py
a
this prints 200 and OK
t
Hey there! If you’re seeing a status code 200 with the response text "OK," it usually means the server sent back plain text instead of JSON. This can happen if the request went through fine but the endpoint doesn’t return data in the format we expected. To help figure this out, could you please check a few things for me? • Are you using the right endpoint URL (
/twirp/livekit.CloudAgent/ListAgents
)? • Is the
Content-Type
header set to
application/json
in your request? • Are you sending an empty JSON object (
{}
) as the request payload? Just let me know what you find, and I’ll be happy to help you troubleshoot from there!
a
this is my code
Copy code
# Function to create JWT token
def create_jwt_token(api_key:str, api_secret:str)->str:
    header = {"alg": "HS256", "typ": "JWT"}
    payload = {"iss": api_key}
    encoded_header = base64.urlsafe_b64encode(json.dumps(header).encode()).decode().strip("=")
    encoded_payload = base64.urlsafe_b64encode(json.dumps(payload).encode()).decode().strip("=")
    signature_input = f"{encoded_header}.{encoded_payload}"
    signature = hmac.new(api_secret.encode(), signature_input.encode(), hashlib.sha256).digest()
    signature_b64 = base64.urlsafe_b64encode(signature).decode().strip("=")
    return f"{encoded_header}.{encoded_payload}.{signature_b64}"


def list_cloud_deployed_agent()->None:
    # Construct request
    url = f"https://ribbon-v8vqjd47.livekit.cloud/twirp/livekit.CloudAgent/ListAgents"
    headers = {
        "Content-Type": "application/json",
        "Authorization": f"Bearer {create_jwt_token(api_key=config.livekit_api_key, api_secret=config.livekit_api_secret)}"
    }

    response = requests.post(url, headers=headers, json={})
    
    print(f"Response status: {response.status_code}")
    print(f"Response headers: {response.headers}")
    print(f"Response text: '{response.text}'")
    print(f"Response content length: {len(response.content)}")
t
Thanks so much for sharing your code! It looks like the issue might be that the server is sending back a plain text response instead of JSON. Here are a few things you can try to dig a little deeper: • Make sure the
Authorization
header is properly formatted with the JWT token from your
create_jwt_token
function. • Double-check that the
Content-Type
header is set to
application/json
in your request. • Take a peek at the response headers and content length to see if the server is giving any extra info. Looking at your code, the
Response text
and
Response content length
should give some helpful hints. If you’re still just getting "OK" without any other details, it might mean there’s something up with the endpoint or the request payload. Feel free to share what you find, and I’m here to help you figure it out!
a
it prints this
Copy code
Response headers: {'Content-Length': '2', 'Content-Type': 'text/plain; charset=utf-8', 'Date': 'Mon, 08 Sep 2025 17:58:20 GMT', 'Vary': 'Origin'}
Response text: 'OK'
Response content length: 2
t
It looks like the server is sending back a plain text response ('OK') instead of the JSON we were expecting. This usually means the request might not be hitting the right endpoint, or the server isn’t handling it quite as we hoped. Let’s try a few things to get this sorted: • First, double-check the endpoint URL: make sure it’s
https://ribbon-v8vqjd47.livekit.cloud/twirp/livekit.CloudAgent/ListAgents
. • Next, take a look at the
Authorization
header to confirm it has a valid JWT token created with the correct API key and secret. • Also, the request payload should be an empty JSON object (
{}
) since that’s what the
ListAgents
method expects. • Lastly, make sure agent hosting is enabled for your LiveKit project — if it’s not, the server might not handle the request properly. If you’ve checked all these and things still aren’t working, no worries! Just let me know, and we can dig a little deeper together.