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

# Get usage and cost

> Message credits and tokens per agent, per UTC day or per model, for the agents the key can access, plus the team's credit balance for the current billing period (only for keys that cover all agents). `costUsd` (what the AI providers charged, in USD) is only included when the key has the opt-in billing:read scope. Default range: the last 30 days.



## OpenAPI

````yaml /api-reference/openapi.json get /v1/usage
openapi: 3.0.0
info:
  title: Totebot Public API
  description: >-
    Manage your agents (settings, instructions, widget, skills, actions, MCP
    connections, integrations), their knowledge, test questions, the help desk,
    customers and your team from code, read conversations and analytics, and
    analyse which knowledge each answer used.


    Authenticate with a Bearer token: a team API key (`tb_live_…`, created by a
    team owner in Team settings → API keys) or a legacy per-agent key.

    New keys can only read. Write access is opt-in per area (`agents:write`,
    `plugins:write`, `knowledge:write`, `conversations:write`, `helpdesk:write`,
    `team:write`, `members:write`, `chat:write`, `customers:delete`,
    `quality:write`, `experiments:write`, `sales:write`). Provider cost in USD
    needs the opt-in `billing:read` scope. A key may also be limited to some
    agents.

    Routes that act on one agent take it from the `agentId` path parameter or,
    on the older `/v1/<resource>` routes, from the `X-Agent-Id` header.

    Write routes accept an `Idempotency-Key` header. Over the rate limit you get
    429 with `Retry-After`. Errors share one shape: `{ status: "error", error: {
    code, message, details } }`.

    Not available through the API, on purpose: billing and plan changes,
    deleting the team, creating or changing API keys, and OAuth connect flows.


    This spec is public at https://api.totebot.ai/v1/openapi.json (and .yaml).
  version: '2.0'
  contact: {}
servers:
  - url: https://api.totebot.ai
security: []
tags: []
paths:
  /v1/usage:
    get:
      tags:
        - Analytics
      summary: Get usage and cost
      description: >-
        Message credits and tokens per agent, per UTC day or per model, for the
        agents the key can access, plus the team's credit balance for the
        current billing period (only for keys that cover all agents). `costUsd`
        (what the AI providers charged, in USD) is only included when the key
        has the opt-in billing:read scope. Default range: the last 30 days.
      operationId: PublicApiUsageController_get
      parameters:
        - name: from
          required: false
          in: query
          description: Start date (ISO 8601)
          schema:
            format: date-time
            example: '2024-01-01T00:00:00.000Z'
            type: string
        - name: to
          required: false
          in: query
          description: End date (ISO 8601)
          schema:
            format: date-time
            example: '2024-12-31T23:59:59.999Z'
            type: string
        - name: groupBy
          required: false
          in: query
          description: >-
            agent and day come from the daily usage records (days in UTC). model
            comes from per-conversation usage, by the day the conversation
            started.
          schema:
            default: agent
            type: string
            enum:
              - agent
              - day
              - model
        - name: agentIds
          required: false
          in: query
          description: 'Comma-separated agent ids. Default: every agent the key can access.'
          schema:
            example: clx1agent,clx2agent
            type: string
      responses:
        '200':
          description: ''
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UsageResponseDto'
        '400':
          description: Invalid request, or rate limit exceeded.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiErrorDto'
        '401':
          description: Missing, invalid, revoked or expired API key.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiErrorDto'
        '403':
          description: >-
            The plan lacks the feature, or the key lacks a scope
            (`error.details.missingScopes`).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiErrorDto'
        '404':
          description: Not found, or not an agent this key can access.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiErrorDto'
      security:
        - api-key: []
components:
  schemas:
    UsageResponseDto:
      type: object
      properties:
        from:
          type: string
          format: date-time
        to:
          type: string
          format: date-time
        groupBy:
          type: string
          enum:
            - agent
            - day
            - model
        costIncluded:
          type: boolean
          description: Whether `costUsd` is included (the key has billing:read).
        credits:
          description: >-
            The team's credit balance for the current billing period. Only for
            keys that cover all agents.
          allOf:
            - $ref: '#/components/schemas/CreditBalanceDto'
        total:
          $ref: '#/components/schemas/UsageTotalsDto'
        rows:
          type: array
          items:
            $ref: '#/components/schemas/UsageRowDto'
      required:
        - from
        - to
        - groupBy
        - costIncluded
        - total
        - rows
    ApiErrorDto:
      type: object
      properties:
        status:
          type: string
          example: error
        error:
          $ref: '#/components/schemas/ApiErrorBodyDto'
        path:
          type: string
          example: /v1/agents/clx123
        timestamp:
          type: string
          example: '2026-11-24T10:00:00.000Z'
      required:
        - status
        - error
        - path
        - timestamp
    CreditBalanceDto:
      type: object
      properties:
        used:
          type: number
          description: Message credits used in the current billing period.
        limit:
          type: number
          description: Credits the plan includes per period. -1 means unlimited.
        topUpRemaining:
          type: number
          description: Credits left from bought message packs.
        periodStartedAt:
          type: string
          format: date-time
          nullable: true
          description: When the current period started.
      required:
        - used
        - limit
        - topUpRemaining
        - periodStartedAt
    UsageTotalsDto:
      type: object
      properties:
        credits:
          type: number
          description: >-
            Message credits used: each customer message costs the model credit
            multiplier. Estimated from customer messages when grouped by model.
        inputTokens:
          type: number
        outputTokens:
          type: number
        totalTokens:
          type: number
        whatsappMessagesSent:
          type: number
          description: WhatsApp messages sent. Not available grouped by model.
        conversations:
          type: number
          description: Conversations. Only when grouped by model.
        costUsd:
          type: number
          description: >-
            What the AI providers charged for this usage, in USD. Only with the
            billing:read scope.
      required:
        - credits
        - inputTokens
        - outputTokens
        - totalTokens
    UsageRowDto:
      type: object
      properties:
        credits:
          type: number
          description: >-
            Message credits used: each customer message costs the model credit
            multiplier. Estimated from customer messages when grouped by model.
        inputTokens:
          type: number
        outputTokens:
          type: number
        totalTokens:
          type: number
        whatsappMessagesSent:
          type: number
          description: WhatsApp messages sent. Not available grouped by model.
        conversations:
          type: number
          description: Conversations. Only when grouped by model.
        costUsd:
          type: number
          description: >-
            What the AI providers charged for this usage, in USD. Only with the
            billing:read scope.
        key:
          type: string
          description: The agent id, the UTC day (YYYY-MM-DD) or the model value.
        agentId:
          type: string
        agentName:
          type: string
        date:
          type: string
          example: '2026-11-24'
        model:
          type: string
          example: gpt-5-mini
        modelName:
          type: string
      required:
        - credits
        - inputTokens
        - outputTokens
        - totalTokens
        - key
    ApiErrorBodyDto:
      type: object
      properties:
        code:
          type: string
          example: NotFoundException
        message:
          type: string
          example: Agent not found
        details:
          type: object
          description: >-
            Extra fields, e.g. `missingScopes` on 403 or `secondsRemaining` on a
            training cooldown.
          additionalProperties: true
      required:
        - code
        - message
  securitySchemes:
    api-key:
      scheme: bearer
      bearerFormat: JWT
      type: http

````

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