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

# Query revenue analytics

> Aggregates revenue_facts by the requested dimensions at day/period/total granularity. allocation_policy places whole-period charges on their booked day (billed) or spreads them across the period (amortized); include_adjustments breaks out true-up/overage/revert amounts as labeled rows. Requires the tenant's revenue analytics setting.



## OpenAPI

````yaml /api-reference/openapi.json post /analytics/revenue
openapi: 3.0.1
info:
  title: Tirdad API
  description: Tirdad API Service
  contact:
    name: API Support
  version: '1.0'
servers:
  - url: https://api.tirdad.ai/v1
    description: Tirdad API
security: []
paths:
  /analytics/revenue:
    post:
      tags:
        - Analytics
      summary: Query revenue analytics
      description: >-
        Aggregates revenue_facts by the requested dimensions at day/period/total
        granularity. allocation_policy places whole-period charges on their
        booked day (billed) or spreads them across the period (amortized);
        include_adjustments breaks out true-up/overage/revert amounts as labeled
        rows. Requires the tenant's revenue analytics setting.
      operationId: getRevenueAnalytics
      requestBody:
        description: Revenue analytics request
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/RevenueAnalyticsRequest'
        required: true
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RevenueAnalyticsResponse'
        '400':
          description: Invalid request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/errors.ErrorResponse'
        '403':
          description: Revenue analytics not enabled
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/errors.ErrorResponse'
        '500':
          description: Server error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/errors.ErrorResponse'
      security:
        - ApiKeyAuth: []
      x-codeSamples:
        - lang: go
          label: Go
          source: "package main\n\nimport(\n\t\"context\"\n\ttirdad \"github.com/tirdad-billing/go-sdk/v2\"\n\t\"github.com/tirdad-billing/go-sdk/v2/types\"\n\t\"github.com/tirdad-billing/go-sdk/v2/models/types\"\n\t\"log\"\n)\n\nfunc main() {\n    ctx := context.Background()\n\n    s := tirdad.New(\n        tirdad.WithSecurity(\"<YOUR_API_KEY_HERE>\"),\n    )\n\n    res, err := s.Analytics.GetRevenueAnalytics(ctx, types.RevenueAnalyticsRequest{\n        StartTime: types.MustTimeFromString(\"2026-09-19T08:36:56.747Z\"),\n    })\n    if err != nil {\n        log.Fatal(err)\n    }\n    if res.RevenueAnalyticsResponse != nil {\n        // handle response\n    }\n}"
        - lang: python
          label: Python
          source: |-
            from tirdad_sdk import Tirdad
            from tirdad_sdk.utils import parse_datetime


            with Tirdad(
                api_key_auth="<YOUR_API_KEY_HERE>",
            ) as f_client:

                res = f_client.analytics.get_revenue_analytics(start_time=parse_datetime("2026-09-19T08:36:56.747Z"))

                # Handle response
                print(res)
        - lang: typescript
          label: TypeScript
          source: |-
            import { Tirdad } from "@tirdad/sdk";

            const tirdad = new Tirdad({
              apiKeyAuth: "<YOUR_API_KEY_HERE>",
            });

            async function run() {
              const result = await tirdad.analytics.getRevenueAnalytics({
                startTime: new Date("2026-09-19T08:36:56.747Z"),
              });

              console.log(result);
            }

            run();
components:
  schemas:
    RevenueAnalyticsRequest:
      required:
        - start_time
      type: object
      properties:
        allocation_policy:
          $ref: '#/components/schemas/types.RevenueAllocationPolicy'
        currency:
          type: string
        customer_ids:
          type: array
          description: Filters restrict the rows before aggregation.
          items:
            type: string
        end_time:
          type: string
          format: date-time
        granularity:
          $ref: '#/components/schemas/types.RevenueGranularity'
        group_by:
          type: array
          description: >-
            GroupBy dimensions: revenue_source, source (the event source
            recorded in

            meter_usage; requires customer_ids or subscription_ids),
            customer_id,

            subscription_id, price_id, meter_id, currency. revenue_source is
            always

            applied — every row says what kind of revenue it is — and requested

            dimensions are added on top.
          items:
            type: string
        include_adjustments:
          type: boolean
          description: |-
            IncludeAdjustments breaks the non-obvious components — commitment
            true-ups, overage and revert (contra) rows — out as their own rows,
            each labeled with its kind in adjustment_type. Off, they fold into
            their parent buckets (true-up/overage into usage, reverts into their
            own source) so visible rows read as plain usage/fixed. Totals are
            identical either way.
        meter_ids:
          type: array
          items:
            type: string
        price_ids:
          type: array
          items:
            type: string
        start_time:
          type: string
          description: >-
            StartTime/EndTime bound the day range (inclusive days derived in
            UTC).

            EndTime is optional and defaults to now.
          format: date-time
        status:
          $ref: '#/components/schemas/types.FactStatus'
        subscription_ids:
          type: array
          items:
            type: string
    RevenueAnalyticsResponse:
      type: object
      properties:
        contains_allocated:
          type: boolean
          description: >-
            ContainsAllocated is true when any bucket includes whole-period
            amounts

            spread across days (amortized) or booked on a single day (billed) —

            i.e. the day view carries period-shaped charges, not only true daily

            accruals.
        query:
          $ref: '#/components/schemas/RevenueAnalyticsRequest'
        rows:
          type: array
          items:
            $ref: '#/components/schemas/RevenueAnalyticsRow'
    errors.ErrorResponse:
      type: object
      properties:
        code:
          $ref: '#/components/schemas/errors.ErrorCode'
        http_status_code:
          type: integer
        message:
          type: string
      x-speakeasy-name-override: ErrorResponse
    types.RevenueAllocationPolicy:
      type: string
      enum:
        - billed
        - amortized
      x-enum-varnames:
        - RevenueAllocationBilled
        - RevenueAllocationAmortized
      x-speakeasy-name-override: RevenueAllocationPolicy
    types.RevenueGranularity:
      type: string
      enum:
        - day
        - period
        - total
      x-enum-varnames:
        - RevenueGranularityDay
        - RevenueGranularityPeriod
        - RevenueGranularityTotal
      x-speakeasy-name-override: RevenueGranularity
    types.FactStatus:
      type: string
      enum:
        - PROVISIONAL
        - FINAL
      x-enum-varnames:
        - FactProvisional
        - FactFinal
      x-speakeasy-name-override: FactStatus
    RevenueAnalyticsRow:
      type: object
      properties:
        adjustment_type:
          type: string
          description: |-
            AdjustmentType labels rows broken out by include_adjustments:
            "commitment_trueup", "overage" or "revert". Empty for plain rows.
        billable_qty:
          type: number
        day:
          type: string
          description: Day is set for day granularity; PeriodStart/PeriodEnd for period.
        entitlement_amount:
          type: number
        entitlement_qty:
          type: number
        group:
          type: object
          additionalProperties:
            type: string
          description: >-
            Group holds the requested dimensions and their values for this
            bucket.
        invoice_discount:
          type: number
        line_discount:
          type: number
        net_amount:
          type: number
        period_end:
          type: string
          format: date-time
        period_start:
          type: string
          format: date-time
        status:
          $ref: '#/components/schemas/types.FactStatus'
        tier_delta:
          type: number
        usage_at_list_rate:
          type: number
    errors.ErrorCode:
      type: string
      enum:
        - http_client_error
        - system_error
        - internal_error
        - not_found
        - already_exists
        - version_conflict
        - validation_error
        - invalid_operation
        - permission_denied
        - database_error
        - service_unavailable
        - too_many_requests
        - not_implemented
      x-enum-varnames:
        - ErrCodeHTTPClient
        - ErrCodeSystemError
        - ErrCodeInternalError
        - ErrCodeNotFound
        - ErrCodeAlreadyExists
        - ErrCodeVersionConflict
        - ErrCodeValidation
        - ErrCodeInvalidOperation
        - ErrCodePermissionDenied
        - ErrCodeDatabase
        - ErrCodeServiceUnavailable
        - ErrCodeTooManyRequests
        - ErrCodeNotImplemented
      x-speakeasy-name-override: ErrorCode
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      description: Enter your API key in the format *x-api-key &lt;api-key&gt;**
      name: x-api-key
      in: header

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.