Anthropic Usage API

Token usage and consumption reporting

OpenAPI Specification

anthropic-usage-api-openapi.yml Raw ↑
openapi: 3.1.0
info:
  title: Anthropic Admin Agents Usage API
  description: Manage administrative functions for Anthropic organizations, workspaces, users, invites, and API keys.
  version: 1.0.0
  contact:
    name: Anthropic
    url: https://www.anthropic.com
    email: support@anthropic.com
  license:
    name: Anthropic API License
    url: https://www.anthropic.com/terms
servers:
- url: https://api.anthropic.com/v1
  description: Production Server
security:
- AdminApiKeyAuth: []
tags:
- name: Usage
  description: Token usage and consumption reporting
paths:
  /v1/organizations/usage_report/messages:
    get:
      summary: Anthropic Get Messages Usage Report
      description: 'Aggregated token usage for Messages API requests, broken down by day, model, workspace, and service tier.

        '
      operationId: getMessagesUsageReport
      tags:
      - Usage
      parameters:
      - $ref: '#/components/parameters/AnthropicVersion'
      - $ref: '#/components/parameters/StartingAt'
      - $ref: '#/components/parameters/EndingAt'
      - $ref: '#/components/parameters/Bucket'
      - $ref: '#/components/parameters/GroupBy'
      - $ref: '#/components/parameters/Models'
      - $ref: '#/components/parameters/WorkspaceIds'
      - $ref: '#/components/parameters/Limit'
      - $ref: '#/components/parameters/Page'
      responses:
        '200':
          description: Usage report.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UsageReport'
        4XX:
          $ref: '#/components/responses/ErrorResponse'
components:
  responses:
    ErrorResponse:
      description: Error response.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
  parameters:
    AnthropicVersion:
      name: anthropic-version
      in: header
      required: true
      schema:
        type: string
        default: '2023-06-01'
    Models:
      name: models
      in: query
      required: false
      explode: true
      schema:
        type: array
        items:
          type: string
    GroupBy:
      name: group_by
      in: query
      required: false
      description: Dimensions to group the report by.
      explode: true
      schema:
        type: array
        items:
          type: string
          enum:
          - workspace_id
          - api_key_id
          - model
          - service_tier
          - context_window
    Page:
      name: page
      in: query
      required: false
      schema:
        type: string
    Limit:
      name: limit
      in: query
      required: false
      schema:
        type: integer
        minimum: 1
        maximum: 1000
        default: 20
    Bucket:
      name: bucket_width
      in: query
      required: false
      description: Aggregation bucket size.
      schema:
        type: string
        enum:
        - 1h
        - 1d
        default: 1d
    StartingAt:
      name: starting_at
      in: query
      required: true
      description: RFC3339 inclusive lower bound for the report window.
      schema:
        type: string
        format: date-time
    EndingAt:
      name: ending_at
      in: query
      required: false
      description: RFC3339 exclusive upper bound for the report window.
      schema:
        type: string
        format: date-time
    WorkspaceIds:
      name: workspace_ids
      in: query
      required: false
      explode: true
      schema:
        type: array
        items:
          type: string
  schemas:
    Error:
      type: object
      properties:
        type:
          type: string
        error:
          type: object
          properties:
            type:
              type: string
            message:
              type: string
    UsageReport:
      type: object
      properties:
        data:
          type: array
          items:
            type: object
            properties:
              starting_at:
                type: string
                format: date-time
              ending_at:
                type: string
                format: date-time
              results:
                type: array
                items:
                  type: object
                  properties:
                    workspace_id:
                      type: string
                      nullable: true
                    api_key_id:
                      type: string
                      nullable: true
                    model:
                      type: string
                      nullable: true
                    service_tier:
                      type: string
                      nullable: true
                    context_window:
                      type: string
                      nullable: true
                    uncached_input_tokens:
                      type: integer
                    cache_read_input_tokens:
                      type: integer
                    cache_creation_5m_input_tokens:
                      type: integer
                    cache_creation_1h_input_tokens:
                      type: integer
                    output_tokens:
                      type: integer
                    server_tool_use:
                      type: object
        has_more:
          type: boolean
        next_page:
          type: string
          nullable: true
  securitySchemes:
    AdminApiKeyAuth:
      type: apiKey
      in: header
      name: x-api-key
      description: Your Admin API key for authentication (starts with sk-ant-admin...).