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

# Get user usage history

> Retrieve historical usage data for the authenticated user.



## OpenAPI

````yaml /api-reference/openapi.yml get /user/usage/history
openapi: 3.0.3
info:
  title: DataLinks
  version: 2.2.3
servers:
  - url: https://api.datalinks.com/api/v1
    description: production server
security:
  - bearerAuth: []
  - openId:
      - implicit
paths:
  /user/usage/history:
    get:
      tags:
        - user
      summary: Get user usage history
      description: Retrieve historical usage data for the authenticated user.
      operationId: getUserUsageHistory
      parameters:
        - name: onOrAfter
          in: query
          description: Return records on or after this timestamp.
          schema:
            type: string
            format: date-time
            example: '2021-01-01T00:00:00.000Z'
        - name: before
          in: query
          description: Return records before this timestamp.
          schema:
            type: string
            format: date-time
            example: '2021-12-31T23:59:59.999Z'
        - name: pageSize
          in: query
          description: Maximum number of results to return.
          schema:
            maximum: 100
            minimum: 1
            type: integer
            default: 25
        - name: pageCursor
          in: query
          description: Cursor for pagination (JSON object).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UserUsageHistoryCursor'
      responses:
        '200':
          description: Returns usage history.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UserUsageHistoryResponse'
        '401':
          $ref: '#/components/responses/Unauthorized'
components:
  schemas:
    UserUsageHistoryCursor:
      required:
        - lastObservationId
        - lastStartTime
      type: object
      properties:
        lastStartTime:
          type: string
          description: The start time of the last observation in the current page.
          format: date-time
          example: '2021-01-01T12:12:12.000Z'
        lastObservationId:
          type: string
          description: The observation ID of the last observation in the current page.
          example: obs_12345
    UserUsageHistoryResponse:
      required:
        - data
        - meta
      type: object
      properties:
        data:
          type: array
          items:
            $ref: '#/components/schemas/UserUsageHistoryItem'
        meta:
          $ref: '#/components/schemas/UserUsageHistoryMeta'
    UserUsageHistoryItem:
      required:
        - costUSD
        - timestamp
        - tokensUsed
      type: object
      properties:
        timestamp:
          type: string
          description: The timestamp of the usage record.
          format: date-time
          example: '2021-01-01T12:12:12.000Z'
        tokensUsed:
          type: integer
          description: Number of tokens used.
          format: int64
          example: 1241
        costUSD:
          type: number
          description: Cost in USD for this usage.
          format: double
          example: 0.0001
    UserUsageHistoryMeta:
      required:
        - pageSize
      type: object
      properties:
        pageCursor:
          $ref: '#/components/schemas/UserUsageHistoryCursor'
        pageSize:
          type: integer
          description: Number of items per page.
          example: 100
    ErrorResponse:
      required:
        - error_code
        - message
      type: object
      properties:
        error_code:
          type: string
          example: UNAUTHORIZED
        error_message:
          type: string
          example: ''
        message:
          type: string
          example: Missing authentication token
        sub_errors:
          type: array
          items:
            required:
              - code
              - message
            type: object
            properties:
              code:
                type: string
              message:
                type: string
  responses:
    Unauthorized:
      description: >-
        Unauthorized. This error occurs if the authentication token is missing
        or invalid.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
  securitySchemes:
    bearerAuth:
      type: http
      description: >
        Use a Bearer token for authentication. Submit the token using the
        `Authorization`

        header: `Authorization: Bearer <token>`.
      scheme: bearer
    openId:
      type: oauth2
      flows:
        implicit:
          authorizationUrl: >-
            https://login.datalinks.com/realms/datalinks-realm/protocol/openid-connect/auth
          scopes:
            openid: openid

````