Phone Number Management
Search Phone Numbers
Search available Twilio or Telnyx phone numbers by country, area code, locality, region, pattern, provider, and result limit.
POST
This endpoint allows you to search for available phone numbers for purchase from Twilio or Telnyx. You can filter results by country, area code, location, or number patterns to find the perfect number for your assistant.
Common causes:
How It Works
- Provider Selection: Choose between Twilio or Telnyx as your search provider
- Filter Application: Apply location, pattern, or feature-based filters
- Results with Pricing: Get available numbers with cost information and capabilities
- Direct Purchase: Use the returned phone numbers in the purchase endpoint
Multi-Provider Comparison: Search both Twilio and Telnyx separately to compare pricing and availability across providers for the same region.
Request Body
The request body is a JSON object containing search criteria.country_code(string, optional): Country code to search in. Defaults to"US"area_code(string, optional): Specific area code to search withincontains(string, optional): Pattern or digits the number should containlocality(string, optional): City or locality name to search inregion(string, optional): State or region to search withinlimit(integer, optional): Maximum number of results (1-50). Defaults to10provider(string, optional): Provider to search ("twilio"or"telnyx"). Defaults to"telnyx"
Request
Response
A successful request returns a200 OK status with available phone numbers.
Response
Response Fields
success(boolean): Whether the search completed successfullynumbers(array): List of available phone numbers with detailsphone_number(string): The phone number in E.164 formatfriendly_name(string): Display name for the numberlocality(string): City/locality where the number is locatedregion(string): State/region where the number is locatedcountry_code(string): Country codecapabilities(object): Features supported by this numbervoice(boolean): Supports voice callssms(boolean): Supports SMS messagesmms(boolean): Supports MMS messagesfax(boolean): Supports fax transmissions
cost(string): Monthly cost for the number (Telnyx only)setup_cost(string): One-time setup fee (Telnyx only)provider(string): Provider name (“twilio” or “telnyx”)
total_found(integer): Total number of results foundprovider(string): Provider used for the search
Error Responses
400 Bad Request
Returned when the request contains invalid parameters.- Invalid
providervalue limitoutside of 1-50 range- Invalid country code format
500 Internal Server Error
Returned when the provider API fails or is unavailable.Search Examples
Basic Area Code Search
Search for numbers in the 415 area code:Location-Based Search
Find numbers in a specific city:Pattern-Based Search
Search for numbers containing specific digits:International Search
Search for numbers in other countries:Provider Comparison
Twilio vs Telnyx
Cost Optimization Tips
- Compare Providers: Search both providers for the same criteria
- Check Setup Fees: Telnyx shows setup costs upfront
- Consider Features: Ensure the number supports required capabilities
- Location Matters: Local numbers may have better rates
Use Cases
Sales Team Numbers
Search for memorable numbers for sales teams:Local Presence
Establish local presence in multiple markets:Toll-Free Numbers
Search for toll-free numbers:Integration Examples
Node.js
Python
PHP
Best Practices
Search Strategy
- Start Broad: Begin with area code only, then add filters
- Multiple Searches: Try different combinations to find the best options
- Provider Comparison: Always compare both Twilio and Telnyx
- Capability Check: Verify the number supports your required features
Performance Tips
- Reasonable Limits: Use appropriate limit values (10-20 for UI, 5 for automation)
- Cache Results: Cache search results for a few minutes to avoid repeated calls
- Parallel Searches: Search multiple providers simultaneously for comparison
Error Handling
Always implement proper error handling for provider outages:Authorizations
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Body
application/json
Request model for searching available phone numbers.
Country code (e.g., US, GB)
Area code to search in
Pattern the number should contain
City/locality to search in
State/region to search in
Maximum number of results
Required range:
1 <= x <= 50Provider to search ('twilio', 'telnyx', or 'byo-sip-trunk')