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

# Get Subscription Usage History

> Retrieve the complete usage history for a subscription with usage-based billing.



## OpenAPI

````yaml get /subscriptions/{subscription_id}/usage-history
openapi: 3.1.0
info:
  title: public
  description: ''
  license:
    name: Apache 2.0
    url: https://www.apache.org/licenses/LICENSE-2.0
  version: 1.102.0
servers:
  - url: https://test.dodopayments.com/
    description: Test Mode Server Host
  - url: https://live.dodopayments.com/
    description: Live Mode Server Host
security: []
tags:
  - name: Products
  - name: Payments
  - name: Subscriptions
  - name: Addons
  - name: Customers
  - name: Refunds
  - name: Disputes
  - name: Events
  - name: License Keys
  - name: Entitlements
  - name: Licenses
  - name: Discounts
  - name: Meters
  - name: Credit Entitlements
  - name: Credit Entitlement Balances
  - name: Outgoing Webhooks
  - name: Checkout
  - name: Webhook Events
paths:
  /subscriptions/{subscription_id}/usage-history:
    get:
      tags:
        - Subscriptions
      summary: Retrieve usage-based billing history for a subscription
      description: >-
        Get detailed usage history for a subscription that includes usage-based
        billing (metered components).

        This endpoint provides insights into customer usage patterns and billing
        calculations over time.


        ## What You'll Get:

        - **Billing periods**: Each item represents a billing cycle with start
        and end dates

        - **Meter usage**: Detailed breakdown of usage for each meter configured
        on the subscription

        - **Usage calculations**: Total units consumed, free threshold units,
        and chargeable units

        - **Historical tracking**: Complete audit trail of usage-based charges


        ## Use Cases:

        - **Customer support**: Investigate billing questions and usage
        discrepancies

        - **Usage analytics**: Analyze customer consumption patterns over time

        - **Billing transparency**: Provide customers with detailed usage
        breakdowns

        - **Revenue optimization**: Identify usage trends to optimize pricing
        strategies


        ## Filtering Options:

        - **Date range filtering**: Get usage history for specific time periods

        - **Meter-specific filtering**: Focus on usage for a particular meter

        - **Pagination**: Navigate through large usage histories efficiently


        ## Important Notes:

        - Only returns data for subscriptions with usage-based (metered)
        components

        - Usage history is organized by billing periods (subscription cycles)

        - Free threshold units are calculated and displayed separately from
        chargeable units

        - Historical data is preserved even if meter configurations change


        ## Example Query Patterns:

        - Get last 3 months:
        `?start_date=2024-01-01T00:00:00Z&end_date=2024-03-31T23:59:59Z`

        - Filter by meter: `?meter_id=mtr_api_requests`

        - Paginate results: `?page_size=20&page_number=1`

        - Recent usage: `?start_date=2024-03-01T00:00:00Z` (from March 1st to
        now)
      operationId: list_usage_history_handler
      parameters:
        - name: subscription_id
          in: path
          description: Unique subscription identifier
          required: true
          schema:
            type: string
        - name: start_date
          in: query
          description: Filter by start date (inclusive)
          required: false
          schema:
            type:
              - string
              - 'null'
            format: date-time
        - name: end_date
          in: query
          description: Filter by end date (inclusive)
          required: false
          schema:
            type:
              - string
              - 'null'
            format: date-time
        - name: meter_id
          in: query
          description: Filter by specific meter ID
          required: false
          schema:
            type:
              - string
              - 'null'
        - name: page_size
          in: query
          description: 'Page size (default: 10, max: 100)'
          required: false
          schema:
            type:
              - integer
              - 'null'
            format: int32
            minimum: 0
        - name: page_number
          in: query
          description: 'Page number (default: 0)'
          required: false
          schema:
            type:
              - integer
              - 'null'
            format: int32
            minimum: 0
      responses:
        '200':
          description: Usage history retrieved successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ListUsageHistoryResponse'
        '400':
          description: Invalid request - malformed parameters or validation errors
        '401':
          description: Unauthorized - invalid or missing API key
        '404':
          description: >-
            Subscription not found - no subscription exists with the specified
            ID
        '422':
          description: Unprocessable entity - invalid query parameter values or date ranges
        '500':
          description: Internal server error - please contact support if this persists
      security:
        - API_KEY: []
      x-codeSamples:
        - lang: JavaScript
          source: >-
            import DodoPayments from 'dodopayments';


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


            // Automatically fetches more pages as needed.

            for await (const subscriptionRetrieveUsageHistoryResponse of
            client.subscriptions.retrieveUsageHistory(
              'subscription_id',
            )) {
              console.log(subscriptionRetrieveUsageHistoryResponse.end_date);
            }
        - lang: Python
          source: |-
            import os
            from dodopayments import DodoPayments

            client = DodoPayments(
                bearer_token=os.environ.get("DODO_PAYMENTS_API_KEY"),  # This is the default and can be omitted
            )
            page = client.subscriptions.retrieve_usage_history(
                subscription_id="subscription_id",
            )
            page = page.items[0]
            print(page.end_date)
        - lang: Go
          source: "package main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\n\t\"github.com/dodopayments/dodopayments-go\"\n\t\"github.com/dodopayments/dodopayments-go/option\"\n)\n\nfunc main() {\n\tclient := dodopayments.NewClient(\n\t\toption.WithBearerToken(\"My Bearer Token\"),\n\t)\n\tpage, err := client.Subscriptions.GetUsageHistory(\n\t\tcontext.TODO(),\n\t\t\"subscription_id\",\n\t\tdodopayments.SubscriptionGetUsageHistoryParams{},\n\t)\n\tif err != nil {\n\t\tpanic(err.Error())\n\t}\n\tfmt.Printf(\"%+v\\n\", page)\n}\n"
        - lang: Java
          source: >-
            package com.dodopayments.api.example;


            import com.dodopayments.api.client.DodoPaymentsClient;

            import com.dodopayments.api.client.okhttp.DodoPaymentsOkHttpClient;

            import
            com.dodopayments.api.models.subscriptions.SubscriptionRetrieveUsageHistoryPage;

            import
            com.dodopayments.api.models.subscriptions.SubscriptionRetrieveUsageHistoryParams;


            public final class Main {
                private Main() {}

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

                    SubscriptionRetrieveUsageHistoryPage page = client.subscriptions().retrieveUsageHistory("subscription_id");
                }
            }
        - lang: Kotlin
          source: >-
            package com.dodopayments.api.example


            import com.dodopayments.api.client.DodoPaymentsClient

            import com.dodopayments.api.client.okhttp.DodoPaymentsOkHttpClient

            import
            com.dodopayments.api.models.subscriptions.SubscriptionRetrieveUsageHistoryPage

            import
            com.dodopayments.api.models.subscriptions.SubscriptionRetrieveUsageHistoryParams


            fun main() {
                val client: DodoPaymentsClient = DodoPaymentsOkHttpClient.fromEnv()

                val page: SubscriptionRetrieveUsageHistoryPage = client.subscriptions().retrieveUsageHistory("subscription_id")
            }
        - lang: Ruby
          source: >-
            require "dodopayments"


            dodo_payments = Dodopayments::Client.new(
              bearer_token: "My Bearer Token",
              environment: "test_mode" # defaults to "live_mode"
            )


            page =
            dodo_payments.subscriptions.retrieve_usage_history("subscription_id")


            puts(page)
        - lang: PHP
          source: |-
            <?php

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

            use Dodopayments\Client;
            use Dodopayments\Core\Exceptions\APIException;

            $client = new Client(
              bearerToken: getenv('DODO_PAYMENTS_API_KEY') ?: 'My Bearer Token',
              environment: 'test_mode',
            );

            try {
              $page = $client->subscriptions->retrieveUsageHistory(
                'subscription_id',
                endDate: new \DateTimeImmutable('2019-12-27T18:11:19.117Z'),
                meterID: 'meter_id',
                pageNumber: 0,
                pageSize: 0,
                startDate: new \DateTimeImmutable('2019-12-27T18:11:19.117Z'),
              );

              var_dump($page);
            } catch (APIException $e) {
              echo $e->getMessage();
            }
        - lang: C#
          source: >-
            using System;

            using DodoPayments.Client;

            using DodoPayments.Client.Models.Subscriptions;


            DodoPaymentsClient client = new();


            SubscriptionRetrieveUsageHistoryParams parameters = new()

            {
                SubscriptionID = "subscription_id"
            };


            var page = await
            client.Subscriptions.RetrieveUsageHistory(parameters);

            await foreach (var item in page.Paginate())

            {
                Console.WriteLine(item);
            }
components:
  schemas:
    ListUsageHistoryResponse:
      type: object
      required:
        - items
      properties:
        items:
          type: array
          items:
            $ref: '#/components/schemas/UsageHistoryItem'
          description: List of usage history items
    UsageHistoryItem:
      type: object
      required:
        - start_date
        - end_date
        - meters
      properties:
        end_date:
          type: string
          format: date-time
          description: End date of the billing period
        meters:
          type: array
          items:
            $ref: '#/components/schemas/MeterUsageItem'
          description: List of meters and their usage for this billing period
        start_date:
          type: string
          format: date-time
          description: Start date of the billing period
    MeterUsageItem:
      type: object
      required:
        - id
        - name
        - free_threshold
        - price_per_unit
        - currency
        - total_price
        - consumed_units
        - chargeable_units
      properties:
        chargeable_units:
          type: string
          description: Chargeable units (after free threshold) as string for precision
        consumed_units:
          type: string
          description: Total units consumed as string for precision
        currency:
          $ref: '#/components/schemas/Currency'
          description: Currency for the price per unit
        free_threshold:
          type: integer
          format: int64
          description: Free threshold units for this meter
        id:
          type: string
          description: Meter identifier
        name:
          type: string
          description: Meter name
        price_per_unit:
          type: string
          description: Price per unit in string format for precision
        total_price:
          type: integer
          format: int32
          description: Total price charged for this meter in smallest currency unit (cents)
    Currency:
      type: string
      enum:
        - AED
        - ALL
        - AMD
        - ANG
        - AOA
        - ARS
        - AUD
        - AWG
        - AZN
        - BAM
        - BBD
        - BDT
        - BGN
        - BHD
        - BIF
        - BMD
        - BND
        - BOB
        - BRL
        - BSD
        - BWP
        - BYN
        - BZD
        - CAD
        - CHF
        - CLP
        - CNY
        - COP
        - CRC
        - CUP
        - CVE
        - CZK
        - DJF
        - DKK
        - DOP
        - DZD
        - EGP
        - ETB
        - EUR
        - FJD
        - FKP
        - GBP
        - GEL
        - GHS
        - GIP
        - GMD
        - GNF
        - GTQ
        - GYD
        - HKD
        - HNL
        - HRK
        - HTG
        - HUF
        - IDR
        - ILS
        - INR
        - IQD
        - JMD
        - JOD
        - JPY
        - KES
        - KGS
        - KHR
        - KMF
        - KRW
        - KWD
        - KYD
        - KZT
        - LAK
        - LBP
        - LKR
        - LRD
        - LSL
        - LYD
        - MAD
        - MDL
        - MGA
        - MKD
        - MMK
        - MNT
        - MOP
        - MRU
        - MUR
        - MVR
        - MWK
        - MXN
        - MYR
        - MZN
        - NAD
        - NGN
        - NIO
        - NOK
        - NPR
        - NZD
        - OMR
        - PAB
        - PEN
        - PGK
        - PHP
        - PKR
        - PLN
        - PYG
        - QAR
        - RON
        - RSD
        - RUB
        - RWF
        - SAR
        - SBD
        - SCR
        - SEK
        - SGD
        - SHP
        - SLE
        - SLL
        - SOS
        - SRD
        - SSP
        - STN
        - SVC
        - SZL
        - THB
        - TND
        - TOP
        - TRY
        - TTD
        - TWD
        - TZS
        - UAH
        - UGX
        - USD
        - UYU
        - UZS
        - VES
        - VND
        - VUV
        - WST
        - XAF
        - XCD
        - XOF
        - XPF
        - YER
        - ZAR
        - ZMW
  securitySchemes:
    API_KEY:
      type: http
      scheme: bearer

````