little-king-41579
02/14/2026, 7:28 AMtall-airline-16756
02/14/2026, 7:28 AMtall-airline-16756
02/14/2026, 7:28 AMimport os
import json
from livekit import api # ensure this import matches your SDK
metadata = {"example": "value"} # replace with your metadata dict
room_name = "my-room" # replace with your room name
token = api.AccessToken(
os.getenv("LIVEKIT_API_KEY"),
os.getenv("LIVEKIT_API_SECRET")
).with_identity("identity") \
.with_name("name") \
.with_metadata(metadata=json.dumps(metadata)) \
.with_grants(api.VideoGrants(
room_join=True,
room=room_name,
can_publish=True, # allow publishing local audio/video/data tracks
can_subscribe=True # allow subscribing to remote tracks
))
Key points:
• Use can_publish=True to allow the participant to publish their own audio/video/data tracks.
• Use can_subscribe=True to allow the participant to receive/play tracks published by others.
• Replace identity, name, metadata, and room_name with your actual values.
• Ensure the `livekit`/`api` import matches the LiveKit server SDK you have installed.
If you'd like, I can:
• Show an example that grants only publish for specific track types (audio/video) if your SDK supports that.
• Provide a short server endpoint example that returns this token to a client.
Which of those would help you next?
Sources: Agent dispatch | LiveKit Documentation | server-sdk-go | livekit/livekit_composite | DeepWikilittle-king-41579
02/14/2026, 7:37 AMtall-airline-16756
02/14/2026, 7:38 AMlittle-king-41579
02/14/2026, 7:41 AMtall-airline-16756
02/14/2026, 7:41 AMimport asyncio
from livekit import api
async def disable_agent_publishing(
host: str,
api_key: str,
api_secret: str,
room_name: str,
agent_identity: str
):
# Initialize LiveKit API client
lk = api.LiveKitAPI(
url=host,
api_key=api_key,
api_secret=api_secret
)
# Build the update request to disable publishing but allow subscribing
update_req = api.UpdateParticipantRequest(
room=room_name,
identity=agent_identity,
permissions=api.ParticipantPermission(
can_subscribe=True, # keep listening to others
can_publish=False, # stop publishing (speaking)
can_publish_audio=False, # explicitly disable audio publish
can_publish_video=False, # explicitly disable video publish
can_publish_data=False # optional: disable data messages if desired
)
)
# Send update
await lk.room.update_participant(update_req)
# Close client
await lk.aclose()
# Example usage
if __name__ == "__main__":
HOST = "<https://your-livekit-instance.com>" # e.g., <https://cloud.livekit.io> or your self-hosted URL
API_KEY = "YOUR_API_KEY"
API_SECRET = "YOUR_API_SECRET"
ROOM = "your-room-name"
AGENT_ID = "agent-identity"
asyncio.run(disable_agent_publishing(HOST, API_KEY, API_SECRET, ROOM, AGENT_ID))
Notes and tips:
• This change applies immediately and does not require the agent to reconnect. The agent remains in the room and can continue subscribing to remote tracks.
• If you only want to disable audio (so the agent can still publish data or video), set can_publish_audio=False and leave other publish flags as needed.
• Trigger this function when you detect participant-2 joining — via LiveKit webhooks (participant_joined) or server-side room events.
• To re-enable speaking later, call the same API with can_publish=True (and appropriate can_publish_audio/video flags).
If you want, I can:
• Provide an example webhook handler that calls this when participant-2 joins, or
• Show the re-enable (unmute) flow and a minimal client-side notification for the agent. Which would you prefer? Sources: server-sdk-kotlin | livekit/livekit_composite | DeepWiki