Key takeaways
- One POST to the Calls endpoint with To, From and Url places a call; Twilio fetches the TwiML at Url when the call is answered.
- The From number must be a number in your Twilio account or a verified caller ID, or the request fails with error 21210.
- Setting Record to true on the Calls request records the whole call, and RecordingChannels set to dual keeps each side on its own channel.
- An outbound call to a US number costs $0.0140 a minute on Twilio, and a browser call adds $0.0040 a minute for the Voice SDK leg; partial minutes round up.
- Error 21215 (13227 for a Dial in TwiML) means the destination country is switched off in Voice Geographic Permissions.
Here is how to make outbound calls with Twilio from code. Send a POST to the Calls API, from curl, the Twilio CLI or a helper library, and Twilio dials the number and runs your TwiML when the call is answered. Or build a browser softphone with the Voice SDK so a person can talk from a web page. Both need the same account setup first: an upgraded account, a voice-capable number and your business registered in Trust Hub.
This guide is for developers. If your team only needs to call lists from a browser, Twilio outbound calling with no code covers that route.
What do you need before your first Twilio call?
You need an upgraded account, a voice-capable number, a Trust Hub registration and the right countries switched on:
- Upgrade the account. Trial accounts can only call numbers you have verified (Twilio trial limits).
- Get a number. Buy a local, voice-capable number in the Console under Phone Numbers, or port your existing one. It becomes your caller ID, so choose numbers for cold calling with care.
- Register in Trust Hub. Create a Business Profile and a SHAKEN/STIR Trust Product and assign your numbers, so calls get full attestation (Twilio SHAKEN/STIR docs).
- Check geographic permissions. Voice Geographic Permissions control which countries the account can call. Enable only the ones you need.
- Note your credentials. The Account SID and Auth Token are on the Console dashboard; keep the token secret and load it from an environment variable, never from source code.
How do you make an outbound call with the REST API?
You send one POST request to the Calls endpoint with a To number, a From number and a URL that returns instructions. Twilio dials, and once the call is answered it fetches those instructions (TwiML):
curl -X POST "https://api.twilio.com/2010-04-01/Accounts/$TWILIO_ACCOUNT_SID/Calls.json" \
--data-urlencode "To=+13125550199" \
--data-urlencode "From=+15125550123" \
--data-urlencode "Url=https://example.com/voice.xml" \
-u "$TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN"
When the person answers, Twilio requests the Url and follows the TwiML it returns, such as a Say message or a Dial that connects someone else. Numbers go in E.164 format: a plus sign, the country code and the number, with no spaces.
Add a StatusCallback URL to record the outcome: a finished call ends as completed, busy, no-answer, canceled or failed (Twilio Call resource). Store the call SID the API returns, so each status event can be joined back to the contact you called.
How do you place the same call with the Twilio CLI or Python?
The Twilio CLI and the helper libraries wrap the same Calls request, so the parameters are identical. The CLI is the quickest way to test a number or a TwiML URL:
twilio login
twilio api:core:calls:create \
--from "+15125550123" \
--to "+13125550199" \
--url "https://example.com/voice.xml"
In Python, install the twilio package and create the call from a client built with your credentials. The library names the From parameter from_, because from is a reserved word in Python:
import os
from twilio.rest import Client
client = Client(os.environ["TWILIO_ACCOUNT_SID"], os.environ["TWILIO_AUTH_TOKEN"])
call = client.calls.create(
to="+13125550199",
from_="+15125550123",
url="https://example.com/voice.xml",
)
print(call.sid)
The Node.js, C#, Java, PHP and Ruby libraries expose the same create method with the same fields.
How do you set caller ID and record a Twilio call?
Caller ID is the From parameter. Twilio accepts a number in your account or a verified caller ID, a number you own elsewhere and confirmed with Twilio; anything else fails with error 21210. On a call bridged through TwiML, the callerId attribute of Dial plays the same role. Keep caller IDs to numbers you own and answer: the FCC’s spoofing rules prohibit misleading caller ID.
To record, add Record=true to the Calls request. Twilio records from the moment the call connects, RecordingChannels=dual keeps each party on its own channel, and a RecordingStatusCallback URL is called when the file is ready (Twilio Call resource). Recording costs $0.0025 a minute on US pricing. Check consent rules before you switch it on, since some states require every party to agree.
How do you call from a browser with the Voice SDK?
You give a web page a short-lived access token, and the Voice JavaScript SDK makes the browser one end of the call. It takes four pieces:
- A TwiML app holding the voice URL Twilio calls when the browser starts a call.
- An API key and secret your server uses to sign access tokens.
- A token endpoint that returns an access token with a Voice grant naming the TwiML app.
- A voice URL that answers with a
Dialverb. Set itscallerIdattribute to your Twilio number, turn onanswerOnBridge, and nest aNumberelement holding the number the browser asked for.
In the page, the SDK’s Device takes the token and calls connect with the number. answerOnBridge keeps the browser leg ringing until the person answers.
Each browser call has two billed legs: the browser leg ($0.0040 per minute) and the phone leg to the number dialed ($0.0140 per minute on US rates), and partial minutes round up (Twilio US voice pricing).
A working softphone is only the start for a sales team: a dialer also needs lists, retries, calling hours, outcomes, callbacks, a do-not-call list and reporting.
What is the third way, if you would rather not write code?
Connect a dialer that already contains those pieces to your Twilio account. You paste the Account SID and Auth Token, and the dialer creates the API key and TwiML app for you; your numbers and recordings stay in your account. Our Twilio dialer guide compares building and buying, and best Twilio dialers compares products.
In Rapidialer, connecting creates an API key and a TwiML app, then syncs up to 200 of the account’s numbers and points their voice webhooks at Rapidialer, and Power Dial works through a list one contact at a time. One limit to know as a developer: Rapidialer only syncs numbers bought in, or ported into, the Twilio account, so it cannot use Twilio Verified Caller IDs. What connecting changes in your account is in the bring-your-own-Twilio guide.
Why did my outbound call fail?
A failed call returns an error code in the API response or the Console call log, and each code names one setting:
- 21219, To number not verified. The account is still a trial; upgrade it or verify the test number (Twilio error 21219).
- 21210, From number not verified. Use a number from your account as caller ID (Twilio error 21210).
- 21215 or 13227, geo permission. Enable the destination country under Voice Geographic Permissions (Twilio error 21215).
- An HTTP 401 from the API. The Account SID and Auth Token do not match; check you are not mixing a subaccount SID with the main account’s token.
- The person answers and hears an application error message. Twilio could not fetch or parse the TwiML at your
Url; the Console’s call log and debugger show the request it made and the response it got.
What does it cost to run calls from your own code?
On Twilio’s US rates an API call to a US number costs $0.0140 a minute, a browser call about 1.8 cents a minute with the SDK leg, recording $0.0025 a minute and a local number $1.15 a month. Building on the API yourself has no seat line, but you pay for hosting the token server and TwiML endpoints, and for the developer time to maintain them. See Twilio cost per minute for how each rate applies, or estimate your own Twilio bill at your volume.
Which way should you choose?
Pick by who is on the call. Use the REST API, CLI or a helper library when no person needs to talk, such as reminders and notifications. Build on the Voice SDK when calling is part of your own product and you have developers to maintain it. Connect a dialer when a sales team calls through lists and nobody wants to maintain the code.
A dialer is the wrong choice for calls with nobody on the line: Rapidialer only places calls a rep is on, so use the API for those.
Questions and answers
Can I make calls from the Twilio Console without code?
Not as a calling tool. The Twilio Console is where you buy numbers, set permissions and read call logs. To place calls from your own code you send a REST API request, use the Twilio CLI, or run an app built on the Voice SDK. For a no-code route, a dialer connects to the account with your Account SID and Auth Token.
How do I set the caller ID on a Twilio API call?
Twilio uses the From parameter of a Calls API request as the caller ID, and the callerId attribute of a Dial verb for calls bridged through TwiML. Twilio accepts only a number in your account or a verified caller ID; error 21210 means it is neither. Registering the number in Trust Hub improves how carriers present the call.
How do I record an outbound call with the Twilio API?
Add Record set to true to the Calls API request, and Twilio records the call from the moment it connects. RecordingChannels set to dual stores each party on its own channel, and a RecordingStatusCallback URL tells your server when the file is ready. Twilio bills recording at $0.0025 a minute on US pricing, plus storage after the free allowance.
Do browser calls cost more than phone calls?
Yes, slightly. A Twilio browser call has two billed legs: the browser leg and the phone leg to the number dialed. On US rates the browser leg adds $0.0040 per minute to the $0.0140 phone leg, about 1.8 cents a minute before recording, with partial minutes rounded up.
Am I charged for calls nobody answers?
Twilio does not bill per-minute charges for calls that end busy, no-answer, canceled or failed, according to its Call resource documentation. Twilio’s North America terms do allow a $0.015 surcharge on each unanswered or very short call when those make up 20% or more of a month’s calls, so a list full of bad numbers can still cost money.
Can I make a Twilio call with the CLI?
Yes. After twilio login stores your credentials, the command twilio api:core:calls:create with the --from, --to and --url flags sends the same request as the REST API and prints the new call’s SID. The CLI is handy for testing a number or a TwiML URL before you write application code, and it reports the same error codes as the API.