https://retellai.com/?utm_source=discord&utm_medium=seo logo
how to add phone number via api
# ❓・ai-evy-support
r
@AI Evy how to add phone number via api ?
a
Thanks for tagging me @ruta1212_29251. I'll look through relevant sources and get back to you shortly.
### Answer You can add a phone number via API using the Import Phone Number endpoint if you're bringing in a number from custom telephony [(1) ]() . Here's how to import a phone number:
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',
}) ;

console.log(phoneNumberResponse.inbound_agent_id) ;
Required parameters: - `phone_number`: The number in E.164 format (e.g.,
"+14157774444"
) - `termination_uri`: The termination URI to uniquely identify your elastic SIP trunk (for Twilio elastic SIP trunks it always ends with ".pstn.twilio.com") Optional parameters: - `sip_trunk_auth_username`: Username for SIP trunk authentication - `sip_trunk_auth_password`: Password for SIP trunk authentication - `inbound_agent_id`: Agent ID to bind for inbound calls - `outbound_agent_id`: Agent ID to bind for outbound calls - `nickname`: A reference name for the number - `inbound_webhook_url`: Webhook URL for inbound calls If you want to purchase a new number from Retell instead, check out the [Create Phone Number API Reference]() [(2) ]() .
​ To learn more, see the sources I considered: [[1] Import Phone Number](https://docs.retellai.com/api-references/import-phone-number) [[2] Purchase phone number](https://docs.retellai.com/deploy/purchase-number) ​
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.
r
@AI Evy keep getting internal error even though the phone number is bought in twilio and has a termination uri
a
Thanks for the follow-up, @ruta1212_29251. I'll get back to you soon.
### Answer Internal errors when importing a Twilio number often stem from incomplete Elastic SIP Trunk configuration. Here are the key setup steps: 1. Verify Your Elastic SIP Trunk Configuration [(1) ]() Your Twilio trunk needs both termination (outbound) and origination (inbound) properly configured: - **Termination SIP URI**: Use a localized termination URI near your region (e.g.,
someuri.pstn.twilio.com
) . Remove any spaces in the URI - **Origination SIP URI**: Must be set to
sip:sip.retellai.com
2. Authentication Setup For termination to accept Retell's outbound requests, you need either: - Whitelist all IP addresses in the range (Retell currently doesn't have static IPs) - Create credentials with username and password 3. Move Number to Elastic SIP Trunk Ensure your purchased number is actually assigned to the Elastic SIP trunk you created 4. Import with Correct Parameters [(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',  // if using auth
  sip_trunk_auth_password: '123456',    // if using auth
}) ;
Common Issues: [(1) ]() - Space in Termination SIP URI - Wrong username (use the actual username, not the friendly name from credential list) - Number not moved to the trunk - Missing geo permissions for international dialing Check your Twilio console to verify all these settings are correct.
​ 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) ​
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.
r
@AI Evy how about delete phone number request
a
Thanks for the follow-up, @ruta1212_29251. I'll get back to you soon.
### Answer ### Answer You can delete a phone number via the Delete Phone Number API endpoint [(1) ]() . Here's how to delete a phone number:
Copy code
javascript
import Retell from 'retell-sdk';
const client = new Retell({
 apiKey: 'YOUR_RETELL_API_KEY',
}) ;
await client.phoneNumber.delete('+14157774444') ;
API Details: - **Method**: DELETE - **Endpoint**:
/delete-phone-number/{phone_number}
- **Authorization**: Bearer token with your API key in the header - **Path Parameter**:
phone_number
in E.164 format (e.g.,
"+14157774444"
) - **Response**: 204 No Content on success The phone number parameter must be in E.164 format (country code + number with no spaces or special characters) . According to community discussions, when you delete a number purchased through Retell, billing for that number stops [(2) ]() [(3) ]() . The Delete Phone Number API is available at the endpoint documented in the official API reference [(3) ]() .
​ To learn more, see the sources I considered: [[1] Delete Phone Number](https://docs.retellai.com/api-references/delete-phone-number) [[2] Discord message from @rish404 on 2025-09-03](https://discord.com/channels/1186424376300679209/1186462578310910112/1412840895790845992) [[3] Discord message from @dumpfile on 2025-09-03](https://discord.com/channels/1186424376300679209/1186462578310910112/1412842051036381367) ​
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.
r
@AI Evy since boolean values need to be strings, do null values also need to be strings?
a
Thanks for the follow-up, @ruta1212_29251. I'll get back to you soon.
### Answer ### Answer Yes, all values in
retell_llm_dynamic_variables
must be strings
[(1) ]() . This requirement applies to all data types—numbers, booleans, and null values must all be converted to strings . Based on the documentation, when using the inbound webhook to pre-populate dynamic variables, any non-string values (including INT and BOOL values) will cause issues . The solution is to cast all values to strings before sending them . So for null values, you should convert them to the string
"null"
or use an empty string
""
depending on your use case, rather than sending a raw null value. **
​ To learn more, see the sources I considered: [[1] Dynamic Variables via inbound webhook break if non-string values are sent](https://discord.com/channels/1186424376300679209/1420429628979282011) ​
Feel free to tag @AI Evy with additional questions. I also appreciate feedback, it helps me improve.