Skip to contentSkip to navigationSkip to topbar
Page toolsOn this page
Looking for more inspiration?Visit the

Record Phone Calls


Learn to record phone calls with Twilio Programmable Voice(link takes you to an external page). For incoming calls, use the TwiML <Record> verb. For outbound calls, send a POST request with the record parameter to the /Calls.json endpoint. To enable self-service automation, create an inbound call center or outbound call center, make calls with virtual agents, use call tracking, or create transcriptions for AI or ML, follow this guide.

To learn more about the TwiML and API calls used in this guide, see Related reference documentation.


Complete the prerequisites

complete-the-prerequisites page anchor

Complete the Twilio prerequisites

complete-the-twilio-prerequisites page anchor

Complete the language prerequisites

complete-the-language-prerequisites page anchor

Select your programming language and complete the prerequisites:

PythonNode.jsPHPC# or .NETJavaRuby
  • Install Python 3.3 or later(link takes you to an external page).
  • Install Flask(link takes you to an external page) and the Twilio Python Helper Library(link takes you to an external page). Using pip(link takes you to an external page), run the following command:
    pip install flask twilio
  • Install and set up ngrok(link takes you to an external page).

Get credentials and set as environment variables

get-credentials-and-set-as-environment-variables page anchor

Extract your credentials from your Twilio account then save these credentials as environment variables.

Twilio ConsoleLegacy Console
  1. Go to the Twilio Console(link takes you to an external page). The Let's get building page appears.

  2. Click API keys and Auth tokens. The API keys & auth tokens page appears with the Auth Tokens tab selected.

  3. Scroll to your Account SID.

  4. Click the copy button next to your Account SID.

  5. Run the following command, replacing YOUR_ACCOUNT_SID with your Account SID.

    macOS TerminalWindows command linePowerShell
    export TWILIO_ACCOUNT_SID=YOUR_ACCOUNT_SID

    This command creates an environment variable on your development system for your account SID.

  6. To display the Auth Token, click the eye button in the Primary auth token box.

  7. Highlight and copy the Auth Token.

  8. Run the following command, replacing YOUR_AUTH_TOKEN with your Authentication Token.

    macOS TerminalWindows command linePowerShell
    export TWILIO_AUTH_TOKEN=YOUR_AUTH_TOKEN

    This command creates an environment variable on your development system for your auth token.


To record an inbound call, send a recording request to Twilio using one of these helper libraries.

PythonNode.jsPHPC# or .NETJavaRuby

Python only requires the Twilio Python helper library as noted in the prerequisites.

Record part of an incoming callLink to code sample: Record part of an incoming call
1
from flask import Flask
2
from twilio.twiml.voice_response import VoiceResponse
3
4
app = Flask(__name__)
5
6
7
@app.route("/record", methods=['GET', 'POST'])
8
def record():
9
"""Returns TwiML which prompts the caller to record a message"""
10
# Start our TwiML response
11
response = VoiceResponse()
12
13
# Use <Say> to give the caller some instructions
14
response.say('Hello. Please leave a message after the beep.')
15
16
# Use <Record> to record the caller's message
17
response.record()
18
19
# End the call with <Hangup>
20
response.hangup()
21
22
return str(response)
23
24
if __name__ == "__main__":
25
app.run()

This code generates a <Record> TwiML document then sends it to Twilio. Twilio consumes the instructions in this TwiML document and records the call. To set additional parameters, see the <Record> documentation.


To record an outbound call, create a call that includes the record parameter.

PythonNode.jsPHPC# or .NETJavaRuby

With your credentials, instantiate a Twilio Python SDK client for the Twilio API. Pass the record parameter to the client.calls.create method. Twilio records the entire phone call.

1
# Download the helper library from https://www.twilio.com/docs/python/install
2
import os
3
from twilio.rest import Client
4
5
# Find your Account SID and Auth Token at twilio.com/console
6
# and set the environment variables. See http://twil.io/secure
7
account_sid = os.environ["TWILIO_ACCOUNT_SID"]
8
auth_token = os.environ["TWILIO_AUTH_TOKEN"]
9
client = Client(account_sid, auth_token)
10
11
call = client.calls.create(
12
record=True,
13
url="http://demo.twilio.com/docs/voice.xml",
14
to="+14155551212",
15
from_="+15017122661",
16
)
17
18
print(call.sid)

Add notification of completed recording

add-notification-of-completed-recording page anchor

To get a notification of a completed recording through a Webhook, pass the Webhook URL as the value of the RecordingStatusCallback parameter for your Recording. When the recording finishes, Twilio sends a request to this URL. In this webhook payload, the RecordingUrl property value has the link to the recording audio file.

To learn more about the RecordingStatusCallback parameter, see the Call resource page.



Use cases for recording phone calls with Twilio Programmable Voice

use-cases-for-recording-phone-calls-with-twilio-programmable-voice page anchor

This guide teaches the basics required for the following use cases:

Enable self-service automation with Twilio Programmable Voice

enable-self-service-automation-with-twilio-programmable-voice page anchor

Together with the gather guide, you can use this guide to record outbound calls that gather user input using the keypad for self-service automation.

To learn more advanced features that you can use with self-service automation, see Voice self-service automation.

Create an inbound call center with Twilio Programmable Voice

create-an-inbound-call-center-with-twilio-programmable-voice page anchor

You can use this guide to create a programmatic inbound call center that records calls and handles customer inquiries.

To learn more advanced features that you can use with inbound call centers, see Inbound call center.

Create an outbound call center with Twilio Programmable Voice

create-an-outbound-call-center-with-twilio-programmable-voice page anchor

You can use this guide to record outbound calls that you make from an outbound call center.

To learn more advanced features that you can use with outbound call centers, see Outbound call center.

Make calls with virtual agents with Twilio Programmable Voice

make-calls-with-virtual-agents-with-twilio-programmable-voice page anchor

You can use this guide to record calls that you make and handle with virtual AI-powered agents.

To learn more advanced features that you can use with virtual agents, see AI agents.

Use call tracking with Twilio Programmable Voice

use-call-tracking-with-twilio-programmable-voice page anchor

By monitoring active links, recording phone conversations, and assessing how interactions map to specific phone routing flows, you can programmatically implement robust call tracking.

To learn more about how to implement call tracking, see Call tracking.

Create transcriptions for AI or ML with Twilio Programmable Voice

create-transcriptions-for-ai-or-ml-with-twilio-programmable-voice page anchor

You can use this guide to capture the audio of your outbound calls for AI-driven analysis. By recording the call, you can send raw audio to machine learning models for real-time transcription, sentiment analysis, or post-call summarization.

To learn more advanced features that you can use with AI or ML transcription, see Voice AI and ML transcription.


After following this guide, you can record inbound and outbound calls programmatically with Twilio Programmable Voice. You might also have configured webhooks by using the RecordingStatusCallback parameter to track and manage call audio files as soon as they complete.


Explore the following guides to build on what you've learned in this guide: