in an agent 1.x , what api do I use to unsubscribe...
# ask-ai
f
in an agent 1.x , what api do I use to unsubscribe a user from another user's audio?
t
Thanks for reaching out, Doug. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hey there! Just to make sure I’m on the right track, are you planning to set this up on the server-side using admin APIs like RoomService, or would you prefer handling subscriptions directly within the client app? Also, are you using a particular SDK for your LiveKit Agent 1.x, like Python or Node.js? I’m here to help you through it! Sources: livekit-protocol/src/livekit.rs | Multiplatform/Views/ParticipantView.swift | lib/src/publication/remote.dart | Protocol & WebRTC | livekit/livekit_composite | DeepWiki | pkg/rtc/subscriptionmanager.go
f
I need a server-side component (python)
t
Hey there! If you want to unsubscribe a user from another user’s audio using the RoomService API in Python, you can do that with the
update_subscriptions
method. Here’s a simple example to help you out:
Copy code
from livekit import api
from livekit.protocol.room import UpdateSubscriptionsRequest

# Initialize the LiveKit API client
lkapi = api.LiveKitAPI(
    url="your-livekit-url",
    api_key="your-api-key", 
    api_secret="your-api-secret"
)

# Create the unsubscribe request
update_request = UpdateSubscriptionsRequest(
    room="your-room-name",
    identity="receiving-participant-identity",  # The user you want to unsubscribe
    track_sids=["TR_AUDIO_TRACK_ID"],          # Audio track SID to unsubscribe from
    subscribe=False                             # False to unsubscribe
)

# Execute the unsubscribe operation
try:
    response = await lkapi.room.update_subscriptions(update_request)
    print("Successfully unsubscribed from audio track")
except Exception as e:
    print(f"Oops, something went wrong: {e}")
Just a couple of things to keep in mind: • Permissions: Make sure your API key has
room_admin
permissions for the room you’re working with. • Track SIDs: You’ll need the track SIDs of the audio tracks you want to unsubscribe from. You can get these by checking the list of participants and their tracks, or by listening to room events that track subscriptions. If you have any questions or want me to walk you through anything else, just give me a shout! Sources: livekit-rtc/livekit/rtc/room.py