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

# Get Model APIs usage

> Returns your organization's Model APIs token usage as a series of contiguous time buckets, broken down by the dimensions you pass in group_by. Buckets with no usage are included, so the series has no gaps. Usage is retained for 92 days, so buckets older than that are returned with no results.



## OpenAPI

````yaml get /v1/model_apis/usage
openapi: 3.1.0
info:
  description: REST API for management of Baseten resources
  title: Baseten management API
  version: 1.0.0
servers:
  - url: https://api.baseten.co
security:
  - BearerAuth: []
paths:
  /v1/model_apis/usage:
    get:
      summary: Gets Model APIs token usage in time buckets
      description: >-
        Returns your organization's Model APIs token usage as a series of
        contiguous time buckets, broken down by the dimensions you pass in
        group_by. Buckets with no usage are included, so the series has no gaps.
        Usage is retained for 92 days, so buckets older than that are returned
        with no results.
      parameters:
        - name: start_time
          in: query
          required: true
          description: >-
            Start of the query range (ISO 8601, UTC), inclusive. Snapped down to
            the start of its bucket. Ignored when you pass a cursor.
          schema:
            format: date-time
            title: Start Time
            type: string
        - name: end_time
          in: query
          required: false
          description: >-
            End of the query range (ISO 8601, UTC), exclusive. Defaults to the
            current time.
          schema:
            anyOf:
              - format: date-time
                type: string
              - type: 'null'
            default: null
            title: End Time
        - name: bucket_width
          in: query
          required: false
          description: 'Width of each time bucket: 1m, 1h, or 1d. Defaults to 1d.'
          schema:
            $ref: '#/components/schemas/BucketWidth'
            default: 1d
        - name: group_by
          in: query
          required: false
          description: >-
            Dimensions to break usage down by, repeated once per dimension:
            api_key, model, service_tier. Defaults to api_key.
          schema:
            items:
              $ref: '#/components/schemas/UsageDimension'
            title: Group By
            type: array
        - name: api_keys
          in: query
          required: false
          description: >-
            Return only usage for these API key prefixes, repeated once per
            prefix.
          schema:
            items:
              type: string
            title: Api Keys
            type: array
        - name: models
          in: query
          required: false
          description: Return only usage for these models, repeated once per model.
          schema:
            items:
              type: string
            title: Models
            type: array
        - name: service_tiers
          in: query
          required: false
          description: Return only usage for these service tiers, repeated once per tier.
          schema:
            items:
              type: string
            title: Service Tiers
            type: array
        - name: limit
          in: query
          required: false
          description: >-
            Number of time buckets to return. Defaults and maximums depend on
            bucket_width: 1d defaults to 7 and allows 31, 1h defaults to 24 and
            allows 168, 1m defaults to 60 and allows 1440.
          schema:
            anyOf:
              - type: integer
              - type: 'null'
            default: null
            title: Limit
        - name: cursor
          in: query
          required: false
          description: >-
            Opaque cursor from the pagination.cursor field of a previous
            response. Pass the same query parameters alongside it, apart from
            start_time, which the cursor supplies.
          schema:
            anyOf:
              - type: string
              - type: 'null'
            default: null
            title: Cursor
      responses:
        '200':
          description: ''
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ModelApisUsageResponseV1'
      x-codeSamples:
        - lang: bash
          source: |
            curl --request GET \
            --url https://api.baseten.co/v1/model_apis/usage \
            --header "Authorization: Bearer $BASETEN_API_KEY"
        - lang: python
          source: |-
            import requests
            import os
            API_KEY = os.environ.get("BASETEN_API_KEY", "<YOUR_API_KEY>")
            url = "https://api.baseten.co/v1/model_apis/usage"

            headers = {"Authorization": f"Bearer {API_KEY}"}

            response = requests.request(
                "GET",
                url,
                headers=headers,
                json={}
            )

            print(response.text)
components:
  schemas:
    BucketWidth:
      enum:
        - 1m
        - 1h
        - 1d
      title: BucketWidth
      type: string
    UsageDimension:
      enum:
        - api_key
        - model
        - service_tier
      title: UsageDimension
      type: string
    ModelApisUsageResponseV1:
      description: >-
        A page of Model APIs token usage: contiguous time buckets, ordered
        oldest first.
      properties:
        items:
          description: Items in this page.
          items:
            $ref: '#/components/schemas/ModelApisUsageBucketV1'
          title: Items
          type: array
        pagination:
          $ref: '#/components/schemas/PaginationResponseV1'
          description: Pagination metadata for the page.
      required:
        - items
        - pagination
      title: ModelApisUsageResponseV1
      type: object
    ModelApisUsageBucketV1:
      description: One time bucket and the usage recorded in it.
      properties:
        start_time:
          description: Start of the bucket (inclusive), UTC
          format: date-time
          title: Start Time
          type: string
        end_time:
          description: End of the bucket (exclusive), UTC
          format: date-time
          title: End Time
          type: string
        results:
          description: Usage totals for this bucket, ordered by total tokens descending
          items:
            $ref: '#/components/schemas/ModelApisUsageResultV1'
          title: Results
          type: array
      required:
        - start_time
        - end_time
      title: ModelApisUsageBucketV1
      type: object
    PaginationResponseV1:
      properties:
        has_more:
          description: Whether more items exist after this page.
          title: Has More
          type: boolean
        cursor:
          anyOf:
            - type: string
            - type: 'null'
          default: null
          description: >-
            Opaque cursor to pass into the next request. Null when there is no
            next page.
          title: Cursor
      required:
        - has_more
      title: PaginationResponseV1
      type: object
    ModelApisUsageResultV1:
      description: >-
        Usage totals for one combination of the requested dimensions, within one
        bucket.
      properties:
        api_key_prefix:
          anyOf:
            - type: string
            - type: 'null'
          default: null
          description: >-
            Prefix of the API key the usage is attributed to. Null when not
            grouping by api_key.
          title: Api Key Prefix
        model:
          anyOf:
            - type: string
            - type: 'null'
          default: null
          description: Model that served the usage. Null when not grouping by model.
          title: Model
        service_tier:
          anyOf:
            - type: string
            - type: 'null'
          default: null
          description: >-
            Service tier the usage was served on. Null when not grouping by
            service_tier.
          title: Service Tier
        input_tokens:
          description: Total input tokens, cached and uncached combined.
          title: Input Tokens
          type: integer
        cached_input_tokens:
          description: Input tokens served from the prompt cache.
          title: Cached Input Tokens
          type: integer
        uncached_input_tokens:
          description: Input tokens not served from the prompt cache.
          title: Uncached Input Tokens
          type: integer
        output_tokens:
          description: Total output tokens.
          title: Output Tokens
          type: integer
        request_count:
          description: Total number of requests.
          title: Request Count
          type: integer
      required:
        - input_tokens
        - cached_input_tokens
        - uncached_input_tokens
        - output_tokens
        - request_count
      title: ModelApisUsageResultV1
      type: object
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      description: >-
        Send `Authorization: Bearer <api_key>`. The legacy `Authorization:
        Api-Key <api_key>` scheme is also accepted.

````