How do I detect a non attributed phone number from...
# ask-ai
s
How do I detect a non attributed phone number from a twirp error?
t
Thanks for reaching out, aric. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — I’m responding to your question about how to detect a non‑attributed phone number from a Twirp error when calling
create_sip_participant
. Short answer: check the Twirp error’s
metadata
for SIP fields such as
sip_status_code
and
sip_status
. A non‑attributed / not‑found phone number is typically indicated by a SIP status like 404 (Not Found) or a 403/forbidden from the SIP provider. What to check and why •
e.metadata['sip_status_code']
— numeric SIP code (e.g.,
"404"
,
"403"
). •
e.metadata['sip_status']
— textual SIP reason (e.g.,
"404 Not Found"
,
"Forbidden"
). These metadata fields are returned on SIP call errors and identify whether the provider rejected or could not route the number. Example (Python) — how to detect and handle it
Copy code
try:
    await ctx.api.sip.create_sip_participant(
        api.CreateSIPParticipantRequest(
            room_name=ctx.room.name,
            sip_trunk_id='ST_xxxx',
            sip_call_to='+15105550123',
            participant_identity='caller',
            wait_until_answered=True,
        )
    )
except api.TwirpError as e:
    sip_status = e.metadata.get('sip_status_code')
    sip_message = e.metadata.get('sip_status', '')

    # Detect non-attributed / not found
    if sip_status == '404' or 'Not Found' in sip_message:
        # handle non-attributed number
        print("Number not attributed / does not exist.")
    elif sip_status == '403' or 'Forbidden' in sip_message:
        # handle forbidden / blocked
        print("Number blocked or forbidden by provider.")
    else:
        print(f"SIP error: {sip_status} - {sip_message}")
If this detection isn’t reliable in your environment • Let me know the exact
TwirpError
payload you’re seeing (copy of
e.metadata
) and the SDK/language you’re using. • I can suggest more specific checks or parsing logic for your SDK. I can also help with next steps (retries, logging best practices, or mapping SIP codes to user‑friendly messages) if you’d like. Sources: Agents telephony integration | LiveKit Documentation