Track usage, costs, and application health for Twilio Programmable Voice
Learn how to track usage, costs, and application health for Twilio Programmable Voice by using the Twilio Console, making a GET request to the Twilio API's UsageRecord resource, or integrating with Datadog. You can use this guide to send notifications and track calls.
See Related reference documentation to learn more about the API resources used in this guide.
To learn how to track health and quality of your Twilio calls, see Voice Insights and the Reports API.
You can track the usage and costs for your Twilio Programmable Voice applications in the Twilio Console, with the Twilio API's UsageRecord resource, or with the Twilio Datadog integration. Check Resolving call log and call usage discrepancies for common issues and solutions.
To track the usage and costs for your Programmable Voice application in the Twilio Console, view the Usage and Spend section:
- In the left navigation of the Twilio Console, go to the Billing and Usage section.
- Click Usage and Spend.
- In the Usage Summary tab, expand Programmable Voice to see a breakdown of your usage and costs for your voice applications. You can use the filters to narrow results.
You can also set alert triggers to notify you by email or webhook when your application reaches a certain usage threshold:
- In the left navigation of the Twilio Console, go to the Billing and Usage section.
- Click Usage and Spend.
- Click the Usage Triggers tab.
- Click the Create Usage Trigger button.
- Complete the Create Usage Trigger form. Set the usage threshold and select the notification method (email or webhook).
- Click the Submit button to save your usage trigger.
To pull usage and cost data for your voice applications programmatically, you can use the UsageRecords resource:
-
Find your Account SID and Auth Token:
Twilio ConsoleLegacy Console- On the Twilio Console landing page, under Let's get building, click API keys and Auth tokens.
- Click the Auth Tokens tab to find your Account SID and Auth Token. Copy these values for the next step.
-
Set the environment variables for your Account SID and Auth Token.
(warning)Improve security with API keys
To better control access, use API keys instead of the Account SID and Auth Token when you deploy to production. To learn more, see Why you should use API keys.
On Mac or Linux:
-
Run the following commands to add your credentials as environment variables in a
twilio.envfile and source them. ReplaceACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXwith your Account SID and replaceyour_auth_tokenwith your Auth Token.1echo "export TWILIO_ACCOUNT_SID='ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'" > twilio.env2echo "export TWILIO_AUTH_TOKEN='your_auth_token'" >> twilio.env3source ./twilio.env -
If you're committing code with Git, run the following command to add the
twilio.envfile to.gitignoreto avoid uploading your credentials in plain text:echo "twilio.env" >> .gitignore
On Windows command line (cmd.exe), run the following commands. Replace
ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXwith your Account SID and replaceyour_auth_tokenwith your Auth Token.1set TWILIO_ACCOUNT_SID=ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX2set TWILIO_AUTH_TOKEN=your_auth_tokenTo learn more, see Store your Twilio credentials safely.
-
-
Make a
GETrequest to the API endpoint for the desired time period and filters to retrieve usage and cost data for your voice applications. For example, to retrieve voice usage and cost data for the current month using cURL, you can make the following request:1curl -X GET "https://api.twilio.com/2010-04-01/Accounts/$TWILIO_ACCOUNT_SID/Usage/Records/LastMonth.json?Category=calls&PageSize=20" \2-u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKENFor more info and examples, see Read multiple UsageRecord resources.
To view Twilio usage and cost data alongside your other business metrics, you can use the Twilio Datadog integration to pull usage and cost data into your Datadog dashboard:
-
Generate an API key and find your Account SID:
Twilio ConsoleLegacy Console- On the Twilio Console landing page, under Let's get building, click API keys and Auth tokens.
- Click the API Keys tab.
- Click the Create API Key button and follow the prompts to generate a new API key. Copy the generated API key and secret and paste them in a temporary local file for use when you connect to Datadog.
- Copy your Account SID in the Twilio Console landing page under Let's get building. Paste it in the temporary local file.
-
Follow the steps in the Twilio Datadog integration documentation to connect your Twilio account to Datadog using your Account SID, API key, and secret from the temporary local file.
After you connect your Twilio account to Datadog, you can view your Twilio usage and cost data in your Datadog Cloud Cost Management dashboard alongside your other business metrics.
To track the health of your Twilio Programmable Voice applications, you can set alert triggers to notify you by email or webhook when application errors occur.
- In the left navigation of the Twilio Console, go to the Develop section.
- Click Troubleshoot > Alarms.
- Click the Create Alarm button.
- Complete the Create Alarm form. Set the alarm conditions and select the notification method (email or webhook).
- Click the Create alarm button to save your alarm.
This guide applies to the following use cases:
You can use this guide to track the delivery costs and performance metrics of your voice notifications. For example, you can monitor billing thresholds to ensure your alert systems remain cost-effective.
To learn more advanced features that you can use with voice notifications, see Voice notifications.
You can use this guide to analyze and break down phone call usage and operational expenses across your campaigns. This helps you identify which numbers or tracking resources generate the highest ROI or call volume.
To learn more advanced features that you can use with call tracking, see Voice call tracking.
After following this guide, you can monitor your Twilio Programmable Voice metrics programmatically and through external dashboards. You might also have created alert triggers to immediately notify your team by email or webhook when unexpected usage spikes or application errors occur.
Explore the following guides to build on what you've learned in this guide:
- Retrieve call logs: Review complete records of your call data and activities.