Skip to contentSkip to navigationSkip to topbar
Page tools
Useful for sharing or LLM
Accelerate development with AI

On this page
Looking for more inspiration?Visit the

Usage API guide


The Billing Usage API provides comprehensive, invoice-aligned usage data for programmatic cost tracking and reporting. This guide covers authentication, query optimization, and advanced integration patterns.


Authentication and OAuth setup

authentication-and-oauth-setup page anchor

The Billing Usage API requires OAuth 2.0 authentication for all requests. All API requests must be authenticated using an OAuth access token.

Register an OAuth application

register-an-oauth-application page anchor

Before generating a token, create an OAuth application in OneConsole to acquire your client credentials. The application type depends on the scope of the endpoints you intend to query:

  • Organization-level applications: Required if you're querying Billing Group-level endpoints.
  • Account-level applications: Required if you're querying Account level endpoints.

Configure permission scopes

configure-permission-scopes page anchor

Ensure your application is explicitly configured with the following permission scope:

twilio/billing-insights/usage/read

This scope grants read access to billing usage data at the appropriate level (organization or account).

Generate an OAuth access token

generate-an-oauth-access-token page anchor

Obtain an access token by submitting a request to the token endpoint using your client credentials. Include this access token in the Authorization header of every API request:

Authorization: Bearer YOUR_OAUTH_ACCESS_TOKEN

The Billing Usage API provides data you can reconcile with your invoice. It includes:

  • Structured JSON payloads: Use POST requests with JSON request bodies to combine date, product, aggregation, and pagination filters for precise query customization.
  • Invoice-aligned product taxonomy: The productCategory parameter aligns with the standardized, multi-level product taxonomy used in the Console and billing statements.
  • Separated usage and price data: Response payloads clearly separate usage measurements and costs into distinct, structured objects for easier integration.
  • Predictable query ranges: A custom date range can cover up to 365 days. Use explicit dates instead of legacy endpoints (such as /Today and /Alltime).
  • Token-based pagination: Use nextToken from the response metadata to page through results, replacing legacy page indexing.
  • Standardized data freshness: Data updates in predictable 24-hour batches, which keeps intra-month reporting consistent.

Retrieve usage data by Billing Group

retrieve-usage-data-by-billing-group page anchor

Billing Group usage data is retrieved through the Billing Usage API using two complementary methods:

MethodURL endpointDescription
POSThttps://billing.twilio.com/v2/Public/Usage/BillingGroups/{billingGroupId}/RecordsInitiate a query with filter parameters in the request body.
GEThttps://billing.twilio.com/v2/Public/Usage/BillingGroups/{billingGroupId}/RecordsPaginate results using pageToken and pageSize parameters.

Replace {billingGroupId} with the specific billing_group_ string retrieved from the Console. This ensures the API correctly identifies the billing entity for which you are requesting records.

Sample request structure

sample-request-structure page anchor
POST https://billing.twilio.com/v2/Public/Usage/BillingGroups/{billingGroupId}/Records

The request body is a JSON object containing your filter parameters:

1
{
2
"startOn": "2025-01-01",
3
"endOn": "2025-01-31",
4
"productCategory": "sms",
5
"aggregationPeriod": "DAILY",
6
"pageSize": 100
7
}

Query optimization: Request parameters and filtering

query-optimization-request-parameters-and-filtering page anchor

Precise data retrieval makes analysis more effective. By using request parameters, you can isolate specific cost drivers, filter by product categories, and define exact timeframes.

(information)

Info

The timePeriod parameter is an alternative to startOn and endOn. Do not use them in the same request.

ParameterTypeDescription
startOnDate (YYYY-MM-DD)Filter usage from this date (inclusive). Maximum range is 365 days.
endOnDate (YYYY-MM-DD)Filter usage to this date (inclusive). Maximum range is 365 days.
timePeriodEnum: YESTERDAY, THIS_MONTH, LAST_MONTH, THIS_YEARA predefined filter as an alternative to custom start and end dates.
productCategoryStringIsolate usage data for a specific Twilio product category (for example, sms, voice, video).
aggregationPeriodEnum: DAILY, MONTHLYDefine how records are grouped within the requested range.
pageSizeIntegerLimit the number of items returned in a single response. Range is 1-1000.
pageTokenStringToken from the previous response's meta.nextToken field to retrieve the next page of results.

Choosing aggregation periods

choosing-aggregation-periods page anchor

The aggregationPeriod is a critical tool for financial granularity:

  • DAILY: Identify specific usage spikes or trends within a month. Vital for spotting anomalies and understanding daily cost drivers. Use daily aggregation when investigating unexpected charges or tracking hour-to-hour changes.
  • MONTHLY: Provides a high-level executive view of spend for period-over-period analysis.
(warning)

Warning

Queries are currently limited to a maximum date range of one month. If you attempt to request data spanning more than one month, the system will return an error or incomplete results. This is a temporary limitation while Twilio works to enhance system capabilities. Use timePeriod shortcuts (such as THIS_MONTH or LAST_MONTH) for month-long queries, or break larger date ranges into monthly chunks.


Data interpretation: Analyzing the usage response

data-interpretation-analyzing-the-usage-response page anchor

The Usage API returns structured output that maps technical usage metrics directly to costs. The response shows what was used, when it was used, and the associated price.

The API returns records with the following properties:

PropertyTypeDescription
asOfDate (YYYY-MM-DD)The latest date/time for the records, formatted in UTC. This represents when the data snapshot was taken.
updatedOnDate (YYYY-MM-DD)The date the data was last updated, formatted in UTC. The latest value is typically the day before the request date because the current day's data is still being computed.
productNameStringA human-readable name of the Twilio product (for example, United States-Outbound-LC-MMS).
productCategoryStringThe standardized category for the product (for example, united-states-outbound-lc-mms).
startOnDate (YYYY-MM-DD)The first date for which usage is included (UTC).
endOnDate (YYYY-MM-DD)The last date for which usage is included (UTC).
usageObjectContains amount (numeric volume) and unit (metric type, such as segments, minutes, or messages).
priceObjectContains amount (total cost in the billing currency) and currency (ISO 4217 code, such as USD, GBP, EUR).
1
{
2
"updatedOn": "2025-01-31",
3
"records": [
4
{
5
"productName": "United States-Outbound-LC-MMS",
6
"productCategory": "united-states-outbound-lc-mms",
7
"startOn": "2025-01-01",
8
"endOn": "2025-01-31",
9
"usage": {
10
"amount": 66505,
11
"unit": "segments"
12
},
13
"price": {
14
"amount": 100.5,
15
"currency": "USD"
16
}
17
},
18
{
19
"productName": "United States-Outbound-SMS",
20
"productCategory": "united-states-outbound-sms",
21
"startOn": "2025-01-01",
22
"endOn": "2025-01-31",
23
"usage": {
24
"amount": 1250000,
25
"unit": "messages"
26
},
27
"price": {
28
"amount": 625.0,
29
"currency": "USD"
30
}
31
}
32
],
33
"meta": {
34
"key": "records",
35
"pageSize": 100,
36
"previousToken": "eyJzdGFydE9uIjoiMjAyNS0wMS0wMSIsImVuZE9uIjoiMjAyNS0wMS0zMSIsInBhZ2UiOiIxIiwicGFnZVNpemUiOiIxMDAifQ",
37
"nextToken": "eyJzdGFydE9uIjoiMjAyNS0wMS0wMSIsImVuZE9uIjoiMjAyNS0wMS0zMSIsInBhZ2UiOiIyIiwicGFnZVNpemUiOiIxMDAifQ"
38
}
39
}

For organizations with high volume usage, managing pagination is critical:

The meta section of the response contains:

  • pageSize: The number of records returned in the current response.
  • previousToken: Token to retrieve the previous page (if available).
  • nextToken: Token to retrieve the next page (if available).

To iterate through all records without missing data:

  1. Execute your initial query with your desired filters.
  2. Process the records returned in the records array.
  3. If meta.nextToken is present, make another request with the same filters. Add "pageToken": "NEXT_TOKEN" to the request body, replacing NEXT_TOKEN with the value of meta.nextToken.
  4. Repeat until meta.nextToken is not present or is null.

This token-based pagination replaces legacy page-number indexing and lets you traverse large datasets reliably.

Example pagination workflow

example-pagination-workflow page anchor
1
// First request
2
{
3
"startOn": "2025-01-01",
4
"endOn": "2025-01-31",
5
"pageSize": 100
6
}
7
8
// Response includes meta.nextToken
9
10
// Second request with pagination
11
{
12
"startOn": "2025-01-01",
13
"endOn": "2025-01-31",
14
"pageSize": 100,
15
"pageToken": "eyJzdGFydE9uIjoiMjAyNS0wMS0wMSIsImVuZE9uIjoiMjAyNS0wMS0zMSIsInBhZ2UiOiIyIiwicGFnZVNpemUiOiIxMDAifQ"
16
}

Usage data is updated in batches and may be up to 24 hours behind current activity. The latest available updatedOn value is typically the day before the request date because the current day's data is still being computed. This standardized cadence ensures every record reflects verified billing data, eliminating data drift and intra-day reconciliation discrepancies.

(warning)

Warning

Usage API data is an estimate. Actual billed usage is reflected on your invoice or usage statement after month-end. Use the Usage API for real-time cost tracking and internal reporting, but reconcile with your official invoice for final billing records.