# 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](#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](/docs/voice/voice-insights) and the [Reports API](/docs/voice/voice-insights/api/reports-api).

## Track Twilio Programmable Voice usage and costs

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](/docs/voice/resolve-call-log-usage-discrepancies) for common issues and solutions.

### Track usage and costs in the Twilio Console

To track the usage and costs for your Programmable Voice application in the Twilio Console, view the **Usage and Spend** section:

## Twilio Console

1. In the left navigation of the Twilio Console, go to the **Billing and Usage** section.
2. Click **Usage and Spend**.
3. 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.

## Legacy Console

1. In the top navigation of the Legacy Console, click **Admin** > **Account Billing**.
2. In the left navigation, under **Usage**, click **Usage Summary**.
3. Expand your account name, then expand **Programmable Voice** to see a breakdown of your usage and costs for your voice applications.

You can also set alert triggers to notify you by email or webhook when your application reaches a certain usage threshold:

## Twilio Console

1. In the left navigation of the Twilio Console, go to the **Billing and Usage** section.
2. Click **Usage and Spend**.
3. Click the **Usage Triggers** tab.
4. Click the **Create Usage Trigger** button.
5. Complete the **Create Usage Trigger** form. Set the usage threshold and select the notification method (email or webhook).
6. Click the **Submit** button to save your usage trigger.

## Legacy Console

1. In the top navigation of the Legacy Console, click **Admin** > **Account Billing**.
2. In the left navigation, under **Usage**, click **Triggers**
3. Click the **Create New Trigger** button.
4. Complete the **Create a New Trigger** form. Set the trigger value and select the notification action (email or webhook).
5. Click the **Save** button to save your usage trigger.

### Track usage and costs with the Twilio API

To pull usage and cost data for your voice applications programmatically, you can use the [UsageRecords resource](/docs/usage/api/usage-record):

1. Find your Account SID and Auth Token:

   ## Twilio Console

   1. On the [Twilio Console landing page](https://1console.twilio.com/), under **Let's get building**, click **API keys and Auth tokens**.
   2. Click the **Auth Tokens** tab to find your Account SID and Auth Token. Copy these values for the next step.

   ## Legacy Console

   At the bottom of the [Legacy Console landing page](https://console.twilio.com/), find your Account SID and Auth Token. Copy these values for the next step.
2. Set the environment variables for your Account SID and Auth Token.

   > \[!WARNING]
   >
   > 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](/docs/iam/api-keys#why-you-should-use-api-keys).

   On Mac or Linux:

   1. Run the following commands to add your credentials as environment variables in a `twilio.env` file and source them. Replace `ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX` with your Account SID and replace `your_auth_token` with your Auth Token.

      ```bash
      echo "export TWILIO_ACCOUNT_SID='ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'" > twilio.env
      echo "export TWILIO_AUTH_TOKEN='your_auth_token'" >> twilio.env
       source ./twilio.env
      ```
   2. If you're committing code with Git, run the following command to add the `twilio.env` file to `.gitignore` to avoid uploading your credentials in plain text:

      ```bash
      echo "twilio.env" >> .gitignore
      ```

   On Windows command line (cmd.exe), run the following commands. Replace `ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX` with your Account SID and replace `your_auth_token` with your Auth Token.

   ```bash
   set TWILIO_ACCOUNT_SID=ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
   set TWILIO_AUTH_TOKEN=your_auth_token
   ```

   To learn more, see [Store your Twilio credentials safely](/docs/usage/secure-credentials).
3. Make a `GET` request 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:
   ```bash
   curl -X GET "https://api.twilio.com/2010-04-01/Accounts/$TWILIO_ACCOUNT_SID/Usage/Records/LastMonth.json?Category=calls&PageSize=20" \
   -u $TWILIO_ACCOUNT_SID:$TWILIO_AUTH_TOKEN
   ```
   For more info and examples, see [Read multiple UsageRecord resources](/docs/usage/api/usage-record#read-multiple-usagerecord-resources).

### Track usage and costs with Datadog

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:

1. Generate an API key and find your Account SID:

   ## Twilio Console

   1. On the [Twilio Console landing page](https://1console.twilio.com/), under **Let's get building**, click **API keys and Auth tokens**.
   2. Click the **API Keys** tab.
   3. 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.
   4. Copy your Account SID in the [Twilio Console landing page](https://1console.twilio.com/) under **Let's get building**. Paste it in the temporary local file.

   ## Legacy Console

   1. At the bottom of the [Legacy Console landing page](https://console.twilio.com/), find your Account SID. Copy the account SID and paste it in a temporary local file for use when you connect to Datadog.
   2. Click **Go to API keys**.
   3. 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 the temporary local file.
2. Follow the steps in the [Twilio Datadog integration documentation](https://docs.datadoghq.com/integrations/twilio/) 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.

## Track Twilio Programmable Voice application health

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.

## Twilio Console

1. In the left navigation of the Twilio Console, go to the **Develop** section.
2. Click **Troubleshoot** > **Alarms**.
3. Click the **Create Alarm** button.
4. Complete the **Create Alarm** form. Set the alarm conditions and select the notification method (email or webhook).
5. Click the **Create alarm** button to save your alarm.

## Legacy Console

1. In the left navigation of the Legacy Console, click the **Monitor** tab.
2. Click **Alarms** > **Manage Alarms**.
3. Click the **Create Alarm** button.
4. Complete the **Create Alarm** form. Set the alarm conditions and select the notification method (email or webhook).
5. Click the **Save** button to save your alarm.

## Use cases for tracking usage, costs, and health with Twilio Programmable Voice

This guide applies to the following use cases:

### Send voice notifications with Twilio Programmable Voice

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](/docs/voice/guides/notifications).

### Track calls with Twilio Programmable Voice

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](/docs/voice/guides/call-tracking).

## Result

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.

## Next steps

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

* [Retrieve call logs](/docs/voice/tutorials/how-to-retrieve-call-logs): Review complete records of your call data and activities.

## Related reference documentation

Find reference documentation for the topics on this page.

* [UsageRecords resource](/docs/usage/api/usage-record)
