give me python code to delete sip trunk
# ask-ai
c
give me python code to delete sip trunk
t
Thanks for reaching out, ZaidKaraymeh. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Here's a friendly example of how you can delete a SIP trunk using the LiveKit Python SDK:
Copy code
from 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.
c
(env) voys@voysera-poc:~ $ vi delete_outbound.py (env) voys@voysera-poc:~ $ python3 delete_outbound.py Traceback (most recent call last): File "/home/users/voys/delete_outbound.py", line 1, in <module> from livekit import sip ImportError: cannot import name 'sip' from 'livekit' (unknown location)
t
Hey there! The ImportError is happening because the SIP functionality isn’t directly available under
livekit
. No worries though—you just need to tweak your import statement to point to the right module. Here’s a quick fix for you:
Copy code
# 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:
Copy code
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