> ## 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 aggregated by day

> Retrieve usage data aggregated by day for the authenticated user, with timezone support.



## OpenAPI

````yaml /api-reference/openapi.yml get /user/usage/by-day
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/by-day:
    get:
      tags:
        - user
      summary: Get user usage aggregated by day
      description: >-
        Retrieve usage data aggregated by day for the authenticated user, with
        timezone support.
      operationId: getUserUsageByDay
      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: timeZoneForAggregation
          in: query
          description: >-
            Timezone for date aggregation (e.g., "America/New_York",
            "Europe/London"). Defaults to UTC.
          schema:
            type: string
            example: America/New_York
            default: UTC
      responses:
        '200':
          description: Returns usage aggregated by day.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UserUsageByDayResponse'
        '401':
          $ref: '#/components/responses/Unauthorized'
components:
  schemas:
    UserUsageByDayResponse:
      required:
        - data
        - meta
      type: object
      properties:
        data:
          type: array
          items:
            $ref: '#/components/schemas/UserUsageByDayItem'
        meta:
          $ref: '#/components/schemas/UserUsageByDayMeta'
    UserUsageByDayItem:
      required:
        - costUSD
        - date
        - tokensUsed
      type: object
      properties:
        date:
          type: string
          description: The day of the aggregated usage.
          format: date
          example: '2021-01-21T00:00:00.000Z'
        tokensUsed:
          type: integer
          description: Total number of tokens used in this day.
          format: int64
          example: 125000
        costUSD:
          type: number
          description: Total cost in USD for this day.
          format: double
          example: 12.5
    UserUsageByDayMeta:
      required:
        - timeZoneForAggregation
      type: object
      properties:
        timeZoneForAggregation:
          type: string
          description: The timezone used for date aggregation.
          example: America/New_York
    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

````