https://retellai.com/?utm_source=discord&utm_medium=seo logo
c
@AI Evy can you help
a
Thanks for tagging me @Client Nexus. I'll look through relevant sources and get back to you shortly.
### Answer Hi! I'm an AI assistant knowledgeable about Retell AI. I use documentation and other sources to help answer questions you might have. What would you like help with? Feel free to ask about: - Setting up AI voice agents - Configuring phone numbers and SIP trunks - API integrations - Conversation flows - SMS/chat functionality - Or any other Retell AI topic Let me know how I can assist!
message has been deleted
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.
c
@AI Evy Twilio 401 auth error blocking phone number purchase + SIP trunk setup for Retell Issue: We're building a multi-tenant platform using Retell AI with Twilio SIP trunking. When searching for phone numbers via Twilio REST API, we get: Error: 401 Authenticate (code 20003) Endpoint: GET /2010-04-01/Accounts/{SID}/AvailablePhoneNumbers/BR/Local.json Our Setup: Supabase Edge Functions calling Twilio API Multi-tenant: each account can have a Twilio subaccount SIP trunk function creates trunk + origination URLs + IP ACL for Retell IPs Auth: using TWILIO_ACCOUNT_SID:TWILIO_AUTH_TOKEN (Basic Auth) Flow we're trying to implement: Search available numbers (Twilio) ← failing here Purchase number (Twilio) Create/get SIP trunk for account Add number to SIP trunk Configure origination to Retell (sip.retellai.com) Register number with Retell agent Questions for Retell: Any known issues with Twilio auth for number search endpoints? For non-US countries (e.g., Brazil), are there specific SIP trunk or regulatory requirements? What's the recommended flow to attach a Twilio number to a Retell agent via SIP trunk? Should we use Retell's phone number API instead of managing Twilio directly? Credentials: We have TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN, TWILIO_API_KEY, TWILIO_API_SECRET, and RETELL_API_KEY configured.
a
Thanks for the follow-up, @Client Nexus. I'll get back to you soon.
### Answer --- ### Twilio 401 Auth Error The 401 error (code 20003) you're encountering when calling Twilio's AvailablePhoneNumbers endpoint is a Twilio-side authentication issue, not a Retell AI issue. [(1) ]() This typically means your Account SID and Auth Token combination is incorrect, or you're using subaccount credentials that don't have permission to search numbers. You'll need to verify your credentials directly with Twilio support. ### Recommended Flow for Twilio + Retell SIP Trunk Setup Here's the documented flow for connecting Twilio numbers to Retell: 1. Create an Elastic SIP Trunk in Twilio - Set up termination (for outbound) — note the termination SIP URI (ends with
.pstn.twilio.com
) - For authentication, either whitelist IPs or create credentials (username/password) - Set up origination (for inbound) with Retell's SIP server:
sip:sip.retellai.com
2. Move/purchase numbers to the Elastic SIP Trunk in Twilio 3. Import the number to Retell - Supply the termination SIP URI from step 1 - If using credential-based auth, provide username and password You can import programmatically via the Import Number API: [(2) ]()
Copy code
javascript
import Retell from 'retell-sdk';

const client = new Retell({
  apiKey: 'YOUR_RETELL_API_KEY',
}) ;

const phoneNumberResponse = await client.phoneNumber.import({
  phone_number: '+14157774444',
  termination_uri: 'someuri.pstn.twilio.com',
  sip_trunk_auth_username: 'username',
  sip_trunk_auth_password: '123456',
  inbound_agent_id: 'oBeDLoLOeuAbiuaMFXRtDOLriTJ5tSxD',
  outbound_agent_id: 'oBeDLoLOeuAbiuaMFXRtDOLriTJ5tSxD',
}) ;
### Brazil-Specific Considerations There are known regional restrictions with Brazilian numbers. [(3) ]() Some Brazilian carriers may block or restrict calls to/from certain regional prefixes (e.g., São Paulo 11 30XX numbers from other regions) . If inbound calls aren't reaching Twilio at all, the issue is likely carrier-side restrictions on the calling number, not the Twilio/Retell configuration. Contacting Twilio support to understand restrictions on Brazilian numbers is recommended. ### Should You Use Retell's Phone Number API? You can either: - Purchase numbers directly from Retell (simpler, less configuration) [(1) ]() - Use your own Twilio numbers via Elastic SIP Trunking (more control, requires the setup above) If you're managing Twilio directly for multi-tenant purposes, the SIP trunk approach works, but you'll need to handle Twilio auth and number provisioning on your end before importing to Retell. ### Common Troubleshooting - Check your Termination SIP URI for spaces and use a localized URI near your region - Verify username/credentials match exactly (username ≠ friendly name in Twilio) - For international dialing, enable countries in Twilio's "Voice Geographic Permissions" under Elastic SIP Trunking
​ To learn more, see the sources I considered: [[1] Twilio](https://docs.retellai.com/deploy/twilio) [[2] Import Phone Number](https://docs.retellai.com/api-references/import-phone-number) [[3] SIP Trunk - Twilio](https://discord.com/channels/1186424376300679209/1430255602814287964) ​
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.