Menu

Rate this page:

Thanks for rating this page!

We are always striving to improve our documentation quality, and your feedback is valuable to us. How could this documentation serve you better?

REST API: Usage Records

The UsageRecords REST resource provides a simple API to retrieve usage made by your Twilio account during any time period and by any usage category. This makes it easy to build reporting and analytics tools for your application.

UsageRecords used in combination with Subaccounts created for each of your end-users make it possible to build recurring usage-based billing systems on top of Twilio's API with just a few simple API calls. If rectifying UsageRecords with billing, see our dedicated article.

You can also set up usage triggers to notify your application when a particular category of usage reaches a threshold on a daily, monthly, yearly, or all-time basis. Triggers can help determine if your users have reached a cap on usage or if your application has runaway requests.

UsageRecord properties

This resource and its subresources always return a list of UsageRecords. Each UsageRecord is represented by the following properties:

Names in PHP format
accountSid
sid<AC> Not PII

The SID of the Account that accrued the usage.

apiVersion
string Not PII

The API version used to create the resource.

category
enum:category Not PII

The category of usage. For more information, see Usage Categories.

count
string Not PII

The number of usage events, such as the number of calls.

countUnit
string Not PII

The units in which count is measured, such as calls for calls or messages for SMS.

description
string Not PII

A plain-language description of the usage category.

endDate
date<iso8601> Not PII

The last date for which usage is included in the UsageRecord. The date is specified in GMT and formatted as YYYY-MM-DD.

price
decimal Not PII

The total price of the usage in the currency specified in price_unit and associated with the account.

priceUnit
currency Not PII

The currency in which price is measured, in ISO 4127 format, such as usd, eur, and jpy.

startDate
date<iso8601> Not PII

The first date for which usage is included in this UsageRecord. The date is specified in GMT and formatted as YYYY-MM-DD.

subresourceUris
uri_map Not PII

A list of related resources identified by their URIs. For more information, see List Subresources.

uri
uri Not PII

The URI of the resource, relative to https://api.twilio.com.

usage
string Not PII

The amount used to bill usage and measured in units described in usage_unit.

usageUnit
string Not PII

The units in which usage is measured, such as minutes for calls or messages for SMS.

Usage, Count, and Price

Each UsageRecord contains three amounts: Usage, Count, and Price. Usage is the primary way usage is measured for that category: minutes for calls, messages for SMS, etc. Count is the number of usage events: calls for calls, etc. And Price is the price of the usage in the currency associated with the account.

Each UsageRecord also has fields that show the units in which each amount is measured: Usage is measured in units of UsageUnit, for instance. These fields make it easy to build usage dashboards. For example, you can always display human-readable strings describing usage with "$Usage $UsageUnits", "$Count $CountUnits", or "$Price $PriceUnits".

Usage Categories

A UsageRecord's Category defines the type of usage it represents. The full list of all categories is here, but you'll usually focus on just a few common categories:

Category Description
calls All voice calls. Count is the number of calls and Usage is the number of minutes.
sms All SMS messages. Count and Usage are both the number of messages sent.
pfax-minutes Programmable Fax minutes. Count is the number of faxes and Usage is the number of minutes.
pfax-pages Programmable Fax pages. Count is the number of faxes and Usage is the number of pages.
phonenumbers All phone numbers owned by the account.
recordings Recordings of voice calls. Count is the number of recordings and Usage is the number of recorded minutes.
transcriptions Transcriptions of voice calls. Count is the number of transcriptions and Usage is the number of transcribed minutes.
totalprice Total price of all usage. Usage will be the same as Price, and Count will be empty. Note that because some Twilio costs may not be included in any usage category, the sum of the Price of all UsageRecords may not be equal to the Price of TotalPrice.

Read multiple UsageRecord resources

get
https://api.twilio.com/2010-04-01/Accounts/{AccountSid}/Usage/Records.json

By default, the UsageRecords resource will return one UsageRecord for each Category, representing all usage accrued all-time for the account. You can filter the usage Category or change the date-range over which usage is counted using optional GET query parameters. Note that query parameters are case-sensitive:

Parameters
Names in None format
category
Optional
get enum:category Not PII

The usage category of the UsageRecord resources to read. Only UsageRecord resources in the specified category are retrieved.

start_date
Optional
get date<iso8601> Not PII

Only include usage that has occurred on or after this date. Specify the date in GMT and format as YYYY-MM-DD. You can also specify offsets from the current date, such as: -30days, which will set the start date to be 30 days before the current date.

end_date
Optional
get date<iso8601> Not PII

Only include usage that occurred on or before this date. Specify the date in GMT and format as YYYY-MM-DD. You can also specify offsets from the current date, such as: +30days, which will set the end date to 30 days from the current date.

include_subaccounts
Optional
get boolean Not PII

Whether to include usage from the master account and all its subaccounts. Can be: true (the default) to include usage from the master account and all subaccounts or false to retrieve usage from only the specified account.

account_sid
Required
get sid<AC> Not PII

The SID of the Account that created the UsageRecord resources to read.

Example 1
        
        
        
        
        Example 2
              
              
              
              
              Example 3
                    
                    
                    
                    
                    Example 4
                          
                          
                          
                          
                          Example 5
                                
                                
                                
                                

                                For example, you might request all usage records for the month of April, 2012. In this case, the query string would be StartDate=2012-04-01&EndDate=2012-04-30. This would return one UsageRecord for each usage-type summarizing the usage during April. The list includes paging information. See Example 2 below.

                                It's also possible to group usage by day, by month, or by year using the subresources described below.

                                List Subresources

                                The main UsageRecords list resource supports a variety of convenience subresources. In general these take the form:

                                /2010-04-01/Accounts/{AccountSid}/Usage/Records/{Subresource}
                                

                                Supported subresources are:

                                Subresource Description
                                Daily Return multiple UsageRecords for each usage category, each representing usage over a daily time-interval.
                                Monthly Return multiple UsageRecords for each usage category, each representing usage over a monthly time-interval.
                                Yearly Return multple UsageRecords for each usage category, each representing usage over a yearly time-interval.
                                AllTime Return a single UsageRecord for each usage category, each representing usage over the date-range specified. This is the same as the root /Usage/Records.
                                Today Return a single UsageRecord per usage category, for today's usage only.
                                Yesterday Return a single UsageRecord per usage category, for yesterday's usage only.
                                ThisMonth Return a single UsageRecord per usage category, for this month's usage only.
                                LastMonth Return a single UsageRecord per usage category, for last month's usage only.

                                These convenience subresources can be used to draw a graph of daily calls, display dashboards of monthly usage across all usage categories, or build a simple usage-based billing system based on last month's usage totals.

                                All subresources support the same list filters as the root UsageCounters resource.

                                Full List of All Usage Categories

                                Voice
                                Category Description
                                calls All voice calls, inbound & outbound. Count is the number of calls and Usage is the number of minutes.
                                calls-inbound All inbound voice calls, to mobile, toll-free and local numbers.
                                calls-inbound-local All inbound voice calls to local numbers.
                                calls-inbound-mobile All inbound voice calls to mobile numbers.
                                calls-inbound-tollfree All inbound voice calls to toll-free numbers.
                                calls-outbound All outbound voice calls.
                                calls-sip All SIP calls.
                                calls-sip-inbound All inbound SIP calls.
                                calls-sip-outbound All outbound SIP calls.
                                calls-client All TwilioClient voice calls.
                                calls-globalconference All global conference calls.
                                call-progess-events All call progress events.
                                recordings Recordings of voice and trunking calls. Count is the number of recordings and Usage is the number of recorded minutes.
                                calls-recordings Recordings of voice calls. Count is the number of recordings and Usage is the number of recorded minutes.
                                recordingstorage Amount of storage used by call recordings stored for the account. Count is the number of stored recordings, Usage is the number of stored recorded minutes, and Price is the price of storing the recordings.
                                transcriptions Transcriptions of voice calls. Count is the number of transcriptions and Usage is the number of transcribed minutes.
                                SMS & MMS
                                Category Description
                                sms All SMS messages, both inbound and outbound. Count and Usage are both the number of messages sent.
                                sms-inbound All inbound SMS messages, to both short-codes and long-codes.
                                sms-inbound-longcode All inbound SMS messages to long-codes.
                                sms-inbound-shortcode All inbound SMS messages to short-codes.
                                sms-outbound All outbound SMS messages, from both short-codes and long-codes.
                                sms-outbound-longcode All outbound SMS messages from long-codes.
                                sms-outbound-shortcode All outbound SMS messages from short-codes.
                                sms-messages-carrierfees All carrier fees for SMS messages.
                                mms All MMS messages, both inbound and outbound. Count and Usage are both the number of messages sent.
                                mms-inbound All inbound MMS messages, to both short-codes and long-codes.
                                mms-inbound-longcode All inbound MMS messages to long-codes.
                                mms-inbound-shortcode All inbound MMS messages to short-codes.
                                mms-outbound All outbound MMS messages, from both short-codes and long-codes.
                                mms-outbound-longcode All outbound MMS messages from long-codes.
                                mms-outbound-shortcode All outbound MMS messages from short-codes.
                                mms-messages-carrierfees All carrier fees for MMS messages.
                                mediastorage Amount of storage used by media stored for the account. Count is the number of stored media files, Usage is the number of megabyes, and Price is the price of storing the media.
                                Phone Numbers
                                Category Description
                                phonenumbers All phone numbers owned by the account, mobile, toll-free and local.
                                phonenumbers-local All local phone numbers owned by the account.
                                phonenumbers-mobile All mobile phone numbers owned by the account.
                                phonenumbers-tollfree All toll-free phone numbers owned by the account.
                                phonenumbers-cps All phone number call per second (CPS) increases.
                                phonenumbers-setups All phone number setups fees.
                                shortcodes All ShortCodes owned by the account, of all types.
                                shortcodes-customerowned All ShortCodes owned by the account that are leased from another provider.
                                shortcodes-mms-enablement All Short Code MMS enablement fees.
                                shortcodes-mps All Short Code message per second (MPS) increases.
                                shortcodes-random All randomly-assigned ShortCodes owned by the account.
                                shortcodes-uk All UK ShortCodes owned by the account.
                                shortcodes-vanity All vanity ShortCodes owned by the account.
                                Lookups
                                Category Description
                                lookups All lookups, including carrier, caller id and number format lookups.
                                carrier-lookups All carrier lookups.
                                calleridlookups All callerID (CallerName) lookups.
                                number-format-lookups All number format lookups
                                Elastic SIP Trunking
                                Category Description
                                trunking-origination All trunking origination (inbound) calls, to mobile, toll-free and local numbers.
                                trunking-origination-local All trunking origination (inbound) calls to local numbers.
                                trunking-origination-mobile All trunking origination (inbound) calls to mobile numbers.
                                trunking-origination-tollfree All trunking origination (inbound) calls to toll-free numbers.
                                trunking-termination All trunking termination (outbound) calls.
                                trunking-recordings Recordings of trunking calls. Count is the number of recordings and Usage is the number of recorded minutes.
                                trunking-cps All trunking call per second (CPS) increases.
                                trunking-secure All secured trunking calls.
                                Task Router
                                Category Description
                                taskrouter-tasks All tasks created in Task Router.
                                Network Traversal
                                Category Description
                                turnmegabytes All TURN megabytes used in network traversal.
                                Authy
                                Category Description
                                authy-authentications All Authy authentications.
                                authy-calls-outbound All Authy outbound calls. Note that this usage is also included in the Voice categories.
                                authy-monthly-fees All Authy monthly fees.
                                authy-phone-intelligence All Authy phone intelligence requests.
                                authy-phone-verifications All Authy phone verifications.
                                authy-sms-outbound All Authy outbound SMS messages. Note that this usage is also included in the SMS categories.
                                Studio
                                Category Description
                                studio-engagements All Studio Engagements
                                Monitor
                                Category Description
                                monitor-reads All Monitor events API reads.
                                monitor-writes All Monitor events writes.
                                monitor-storage All Monitor events storage fees.
                                Other
                                Category Description
                                premiumsupport All premium support fees.
                                totalprice Total price of all usage. Usage will be the same as Price, and Count will be empty. Note that because some Twilio costs may not be included in any usage category, the sum of the Price in all UsageRecords may or may not be equal to the Price of TotalPrice.

                                UsageRecords Instance Resource

                                You cannot make requests directly to a UsageRecord resource. Instead, make a request to the UsageRecords list resource or one of its subresources.

                                Rate this page:

                                Need some help?

                                We all do sometimes; code is hard. Get help now from our support team, or lean on the wisdom of the crowd browsing the Twilio tag on Stack Overflow.