colossal-lock-10836
08/17/2025, 10:43 AMtall-airline-16756
08/17/2025, 10:43 AMtall-airline-16756
08/17/2025, 10:43 AMfrom livekit import sip
from livekit.api import LiveKitAPI
async def delete_sip_trunk(
sip_trunk_id: str,
api_key: str,
api_secret: str,
url: str = <BASE_API_URL>,
):
"""
Deletes a SIP Trunk using the LiveKit SIP API.
Args:
sip_trunk_id: The ID of the SIP trunk to delete
api_key: LiveKit API Key
api_secret: LiveKit API Secret
url: (Optional) LiveKit API URL (defaults to production)
"""
lk = LiveKitAPI(api_key, api_secret, url)
sip_service = lk.sip
request = sip.DeleteSIPTrunkRequest(sip_trunk_id=sip_trunk_id)
try:
result = await sip_service.delete_sip_trunk(request)
print(f"SIP Trunk {sip_trunk_id} deleted successfully")
return result
except Exception as e:
print(f"Oops! Failed to delete SIP Trunk: {str(e)}")
raise
# Here's how you might use it:
if __name__ == "__main__":
import asyncio
# Just swap these out with your real API credentials and SIP trunk ID
API_KEY = "your-api-key"
API_SECRET = "your-api-secret"
SIP_TRUNK_ID = "your-sip-trunk-id"
asyncio.run(delete_sip_trunk(SIP_TRUNK_ID, API_KEY, API_SECRET))
Just a few things to keep in mind:
• Make sure to replace API_KEY
, API_SECRET
, and SIP_TRUNK_ID
with your actual LiveKit credentials and the SIP trunk ID you want to remove.
• Swap out <BASE_API_URL>
with the correct LiveKit API URL for your setup.
• If you haven’t already, you can install the LiveKit Python SDK easily with pip install livekit-python-sdk
.
• Deleting a SIP trunk is permanent, so double-check before you proceed.colossal-lock-10836
08/17/2025, 10:47 AMtall-airline-16756
08/17/2025, 10:48 AMlivekit
. No worries though—you just need to tweak your import statement to point to the right module. Here’s a quick fix for you:
# Correct import for SIP functionality
from livekit.protocol import sip
# Or, if you’re using the API client
from livekit import api
# Example usage with the API client
livekit_api = api.LiveKitAPI(api_key, api_secret, <BASE_API_URL>)
response = await livekit_api.sip.delete_sip_trunk(
api.DeleteSIPTrunkRequest(sip_trunk_id=sip_trunk_id)
)
Also, just double-check that you have the right LiveKit packages installed with this command:
pip install livekit-api livekit-protocol
If you hit any snags or want to chat more about it, I’m here to help!
Sources: complex-agents/ivr-agent/flask_livekit/extension.py | livekit-rtc/livekit/rtc/__init__.py