witty-kangaroo-6889
09/26/2025, 3:17 AMtall-airline-16756
09/26/2025, 3:17 AMtall-airline-16756
09/26/2025, 3:17 AMctx.api?
• What kind of object do you think ctx is meant to be?
• Are you working with a particular library or framework that uses get_job_context()?
Having these details will really help me get to the bottom of why ctx.api is returning a string. Looking forward to your reply!witty-kangaroo-6889
09/26/2025, 3:19 AMtall-airline-16756
09/26/2025, 3:20 AMctx is coming through as a string instead of a properly initialized JobContext object. In the LiveKit Python Agent SDK, ctx should be a JobContext instance, which includes a room attribute (an rtc.Room object) and an api attribute for server-side operations.
To help you get this sorted out, here are a couple of steps you can follow:
1. First, double-check that ctx is correctly initialized as a JobContext object. It’s a good idea to verify how ctx is being passed into your function and make sure it’s not accidentally being overridden or redefined somewhere else in your code.
2. When you’re listing participants, be sure to use the api property of the JobContext along with the ListParticipantsRequest class like this:
from livekit.api import ListParticipantsRequest
# Ensure `ctx` is a JobContext object
participants_response = await ctx.api.room.list_participants(
ListParticipantsRequest(room=ctx.room.name)
)
Remember to pass the room name explicitly through the room parameter in ListParticipantsRequest.
If you still find that ctx is unexpectedly a string, it’s worth confirming that it’s being passed correctly from the LiveKit agent framework. In a proper setup, your entrypoint function should receive a JobContext instance.
Sources: livekit-agents/livekit/agents/job.py | livekit-rtc/livekit/rtc/_proto/room_pb2.pyi | telephony/sip_lifecycle.pywitty-kangaroo-6889
09/26/2025, 3:35 AMtall-airline-16756
09/26/2025, 3:36 AMJobContext. Here’s a simple way to do it:
1. First, access the API client via ctx.api, which gives you the LiveKitAPI instance.
2. Then, use the list_participants() method to fetch participant details. Just make sure to pass the room name explicitly using the ListParticipantsRequest class.
Here’s an example to help you visualize it:
from livekit.api import ListParticipantsRequest
# Make sure `ctx` is a JobContext object
participants_response = await ctx.api.room.list_participants(
ListParticipantsRequest(room=ctx.room.name)
)
# Now, let’s access the participant details
participants = participants_response.participants
for participant in participants:
print(f"Participant Identity: {participant.identity}")
Each participant object contains useful fields like identity, name, state, metadata, and more. You can loop through the list to access all these details.
One last thing to keep in mind: please ensure your API credentials have the right permissions to use the list_participants API. If you run into any issues or have questions, I’m here to help!
Sources: livekit-agents/livekit/agents/job.py | livekit-api/livekit/api/room_service.py | mcp/server.py | Managing participants | LiveKit Docswitty-kangaroo-6889
09/26/2025, 3:44 AMtall-airline-16756
09/26/2025, 3:44 AMremove_participant API method for each participant. Here's a simple Python example to guide you through it:
from livekit import api
async def remove_all_participants(ctx):
# First, get a list of all participants in the room
participants_response = await ctx.api.room.list_participants(
api.ListParticipantsRequest(room=ctx.room.name)
)
# Then, remove each participant one by one
for participant in participants_response.participants:
await ctx.api.room.remove_participant(
api.RemoveParticipantRequest(
room=ctx.room.name,
identity=participant.identity,
)
)
On the other hand, if your goal is to disconnect everyone by deleting the room completely, you can use the delete_room method like this:
from livekit import api
async def delete_room(ctx):
await ctx.api.room.delete_room(
api.DeleteRoomRequest(room=ctx.room.name)
)
Feel free to choose the approach that best fits what you want to achieve—whether it's keeping the room ready for future use or ending the session entirely. If you have any questions or need further help, I'm here for you!
Sources: livekit-api/livekit/api/room_service.py | packages/livekit-server-sdk/src/RoomServiceClient.ts | Inside a session | LiveKit Docswitty-kangaroo-6889
09/26/2025, 3:48 AMtall-airline-16756
09/26/2025, 3:49 AMwitty-kangaroo-6889
09/26/2025, 3:53 AM