> ## Documentation Index
> Fetch the complete documentation index at: https://developers.telnyx.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Get a usage summary by product

> List the products the account has usage on in the time range, with the record count and the total cost in each currency. Products with no usage are omitted. Use it to find which products to request from the usage reports endpoint.

Provide either `date_range` or both `start_date` and `end_date`. The time range can span at most 31 days. Usage is counted by the hour, so the range is widened to whole UTC hours, and `meta` returns the range that was counted.



## OpenAPI

````yaml /openapi/source/external/usage-reports/usage-reports.json get /usage_reports/summary
openapi: 3.1.0
info:
  version: 2.0.0
  x-latency-category: responsive
  x-endpoint-cost: light
  title: Telnyx API
  description: Usage reports for all products.
  contact:
    email: support@telnyx.com
servers:
  - url: https://api.telnyx.com/v2
    description: Version 2.0.0 of the Telnyx API
security:
  - bearerAuth: []
tags:
  - name: Usage Reports
    description: Usage data reporting across Telnyx products
paths:
  /usage_reports/summary:
    get:
      tags:
        - Usage Reports
      summary: Get a usage summary by product
      description: >-
        List the products the account has usage on in the time range, with the
        record count and the total cost in each currency. Products with no usage
        are omitted. Use it to find which products to request from the usage
        reports endpoint.


        Provide either `date_range` or both `start_date` and `end_date`. The
        time range can span at most 31 days. Usage is counted by the hour, so
        the range is widened to whole UTC hours, and `meta` returns the range
        that was counted.
      operationId: GetUsageReportsSummary
      parameters:
        - name: start_date
          in: query
          description: >-
            The start of the time range. Usage is counted by the hour, so the
            start is rounded down to the hour. The maximum time range is 31
            days. Format: YYYY-MM-DDTHH:mm:ssZ
          required: false
          schema:
            type: string
          examples:
            start_date=2024-02-01T00:00:00Z:
              value: '2024-02-01T00:00:00Z'
              summary: Usage from this hour on
        - name: end_date
          in: query
          description: >-
            The end of the time range (exclusive). Usage is counted by the hour,
            so an hour that starts before the end is included in full. The
            maximum time range is 31 days. Format: YYYY-MM-DDTHH:mm:ssZ
          required: false
          schema:
            type: string
          examples:
            end_date=2024-03-01T00:00:00Z:
              value: '2024-03-01T00:00:00Z'
              summary: Usage before this time
        - name: date_range
          in: query
          description: >-
            A date literal that sets the time range, used instead of
            `start_date` and `end_date`. The range it resolves to can span at
            most 31 days.
          required: false
          schema:
            type: string
          examples:
            date_range=last_7_days:
              value: last_7_days
              summary: last_7_days - Usage since `00:00:00` 7 days ago
            date_range=last_month:
              value: last_month
              summary: last_month - Usage of the previous calendar month
        - name: authorization_bearer
          in: header
          description: Bearer token used to authenticate the request.
          schema:
            type: string
            description: Authenticates the request with your Telnyx API V2 KEY
      responses:
        '200':
          description: Successful
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UsageReportsSummaryResponse'
              example:
                meta:
                  start_time: '2024-02-01T00:00:00.000Z'
                  end_time: '2024-03-01T00:00:00.000Z'
                data:
                  - product: messaging
                    record_count: 1520
                    costs:
                      - currency: USD
                        amount: 12.345
                  - product: sip-trunking
                    record_count: 8734
                    costs:
                      - currency: EUR
                        amount: 3.2
                      - currency: USD
                        amount: 41.0625
                  - product: verify-2fa
                    record_count: 96
                    costs: []
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                errors:
                  - code: '10004'
                    title: Invalid date/time interval.
                    detail: >-
                      Start/end combination should be provided,having end date
                      equal or greater than start; and start/end date difference
                      less or equals to 31 days in any chronology units.
                    source:
                      parameter: start_date/end_date
        '500':
          description: Internal Server Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
              example:
                errors:
                  - code: '10007'
                    title: Unexpected error
                    detail: >-
                      The usage summary could not be computed. Please retry
                      later.
      x-codeSamples:
        - lang: JavaScript
          source: |-
            import Telnyx from 'telnyx';

            const client = new Telnyx({
              apiKey: process.env['TELNYX_API_KEY'], // This is the default and can be omitted
            });

            const response = await client.usageReports.retrieveSummary();

            console.log(response.meta);
        - lang: Python
          source: |
            import os
            from telnyx import Telnyx

            client = Telnyx(
                api_key=os.environ.get("TELNYX_API_KEY"),  # This is the default and can be omitted
            )
            response = client.usage_reports.retrieve_summary()
            print(response.meta)
        - lang: Go
          source: "package main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\n\t\"github.com/team-telnyx/telnyx-go\"\n\t\"github.com/team-telnyx/telnyx-go/option\"\n)\n\nfunc main() {\n\tclient := telnyx.NewClient(\n\t\toption.WithAPIKey(\"My API Key\"),\n\t)\n\tresponse, err := client.UsageReports.GetSummary(context.TODO())\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n\tfmt.Printf(\"%+v\\n\", response.Data)\n}\n"
        - lang: Java
          source: |-
            package com.telnyx.sdk.example;

            import com.telnyx.sdk.client.TelnyxClient;
            import com.telnyx.sdk.client.okhttp.TelnyxOkHttpClient;

            public final class Main {
                private Main() {}

                public static void main(String[] args) {
                    TelnyxClient client = TelnyxOkHttpClient.fromEnv();

                    var response = client.usageReports().retrieveSummary();
                }
            }
        - lang: Ruby
          source: |-
            require "telnyx"

            telnyx = Telnyx::Client.new(api_key: "My API Key")

            response = telnyx.usage_reports.retrieve_summary

            puts(response)
        - lang: PHP
          source: >-
            <?php


            require_once dirname(__DIR__) . '/vendor/autoload.php';


            use Telnyx\Client;

            use Telnyx\Core\Exceptions\APIException;


            $client = new Client(apiKey: getenv('TELNYX_API_KEY') ?: 'My API
            Key');


            try {
              $response = $client->usageReports->retrieveSummary();

              var_dump($response);
            } catch (APIException $e) {
              echo $e->getMessage();
            }
        - lang: CLI
          source: |-
            telnyx usage-reports retrieve-summary \
              --api-key 'My API Key'
components:
  schemas:
    UsageReportsSummaryResponse:
      type: object
      properties:
        meta:
          $ref: '#/components/schemas/UsageReportsSummaryMeta'
        data:
          type: array
          items:
            $ref: '#/components/schemas/UsageReportsSummaryRecord'
    ErrorResponse:
      type: object
      properties:
        errors:
          type: array
          items:
            $ref: '#/components/schemas/ErrorRecord'
    UsageReportsSummaryMeta:
      type: object
      description: The time range the summary covers, widened to whole UTC hours
      properties:
        start_time:
          type: string
          description: >-
            Start of the range counted (inclusive). UTC,
            YYYY-MM-DDThh:mm:ss.fffZ
          example: '2024-02-01T00:00:00.000Z'
        end_time:
          type: string
          description: End of the range counted (exclusive). UTC, YYYY-MM-DDThh:mm:ss.fffZ
          example: '2024-03-01T00:00:00.000Z'
    UsageReportsSummaryRecord:
      type: object
      description: Usage of one product in the time range
      properties:
        product:
          type: string
          description: Product name, as accepted by the usage reports endpoint
          example: messaging
        record_count:
          type: integer
          format: int64
          description: Number of usage records
          example: 1520
        costs:
          type: array
          description: Total cost per currency. Empty when the product records no cost
          items:
            $ref: '#/components/schemas/UsageReportsSummaryCost'
    ErrorRecord:
      type: object
      properties:
        code:
          type: string
          description: >-
            an application-specific error code, expressed as a stringified
            5-digit integer
          example: '10003'
        title:
          type: string
          description: >-
            a short, human-readable summary of the problem, with NO punctuation,
            that SHOULD NOT CHANGE from occurrence to occurrence of the problem,
            except for purposes of localization
          example: Metrics invalid values
        detail:
          type: string
          description: >-
            a human-readable explanation specific to this occurrence of the
            problem. Like title, this field’s value can be localized
          example: >-
            Available metrics values for sip-trunking:
            connected,cost,completed,call_sec,attempted,billed_sec.
        source:
          $ref: '#/components/schemas/SourceResponse'
        meta:
          $ref: '#/components/schemas/MetaResponse'
    UsageReportsSummaryCost:
      type: object
      description: Total cost of one product in one currency
      properties:
        currency:
          type: string
          description: ISO 4217 currency code
          example: USD
        amount:
          type: number
          description: Total cost in that currency
          example: 12.345
    SourceResponse:
      type: object
      properties:
        pointer:
          type: string
          description: >-
            A JSON Pointer [RFC6901] to the associated entity in the request
            document
          example: /title
        parameter:
          type: string
          description: a string indicating which URI query parameter caused the error
          example: metrics
    MetaResponse:
      type: object
      properties:
        url:
          type: string
          description: This should likely be a URL to the relevant documentation
          example: https://developers.telnyx.com/docs/overview/errors/10001
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer

````