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

# Get usage

> Returns token usage and cost, in total and by key and model. Covers all time unless time, start or end is set.



## OpenAPI

````yaml https://api.tinfoil.sh/openapi.yaml get /api/billing/usage
openapi: 3.2.0
info:
  title: Tinfoil Controlplane API
  version: 0.1.0
  description: >-
    Manage inference API keys, read usage and invoices, and manage Tinfoil
    confidential containers, their configuration, and the organization resources
    they use. Authenticate with an admin API key sent as a bearer token.
servers:
  - url: https://api.tinfoil.sh
security:
  - apiKey: []
tags:
  - name: Account
    description: >-
      The identity and organization behind the API key, and the token usage and
      invoices of the personal account or organization.
  - name: API keys
    parent: Account
    description: Inference API keys of the personal account or organization.
  - name: Containers
    description: Create, deploy, and stop confidential containers.
  - name: Container updates
    description: >-
      Move a container to a new release, and promote or cancel an update that is
      held for review.
  - name: Projects
    description: Groups of containers deployed from the same config source.
  - name: Volumes
    description: Encrypted persistent volumes that attach to containers.
  - name: Secrets
    description: >-
      Organization secrets available to containers, and secrets scoped to a
      single GitHub repository.
  - name: Access
    description: >-
      SSH public keys for attested SSH access to containers, custom domains that
      route to containers, and credentials for pulling images from private
      registries. An organization can store one ecr and one custom registry
      connection, each identified by its hostname.
  - name: GitHub & models
    description: >-
      Repository config and image builds through the Tinfoil GitHub app, and
      packaging Hugging Face models for use in containers. Packaging models
      requires a GPU entitlement or model access for the organization.
  - name: Config registry
    description: >-
      Publish tinfoil-config.yml revisions, read published configs, and resolve
      the endorsements that let clients verify them.
  - name: Bunkers
    description: Bunker owner keys and owner attestation.
paths:
  /api/billing/usage:
    get:
      tags:
        - Account
      summary: Get usage
      description: >-
        Returns token usage and cost, in total and by key and model. Covers all
        time unless time, start or end is set.
      operationId: getUsage
      parameters:
        - $ref: '#/components/parameters/UsageTime'
        - $ref: '#/components/parameters/UsageStart'
        - $ref: '#/components/parameters/UsageEnd'
        - $ref: '#/components/parameters/UsageKeyID'
      responses:
        '200':
          description: Usage
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Usage'
        '400':
          $ref: '#/components/responses/Error'
          description: Invalid request
        '401':
          $ref: '#/components/responses/Error'
          description: Missing or invalid credentials
        '403':
          $ref: '#/components/responses/Error'
          description: Not permitted
        '500':
          $ref: '#/components/responses/Error'
          description: Server error
components:
  parameters:
    UsageTime:
      name: time
      in: query
      required: false
      description: >-
        Time window. period is the account's current token billing period.
        Ignored when start and end are set.
      schema:
        type: string
        enum:
          - 5m
          - 15m
          - 30m
          - 1h
          - 24h
          - today
          - 7d
          - 30d
          - 60d
          - 90d
          - 180d
          - 365d
          - 3mo
          - 6mo
          - 12mo
          - all
          - period
    UsageStart:
      name: start
      in: query
      required: false
      description: Start of an explicit range. Send it with end.
      schema:
        type: string
        format: date-time
    UsageEnd:
      name: end
      in: query
      required: false
      description: >-
        End of an explicit range. Send it with start. A future value is clamped
        to now, and the range cannot exceed two years.
      schema:
        type: string
        format: date-time
    UsageKeyID:
      name: key_id
      in: query
      required: false
      description: Only count usage of the inference key with this public_id.
      schema:
        type: string
        pattern: ^[0-9a-f]{64}$
  schemas:
    Usage:
      allOf:
        - $ref: '#/components/schemas/UsageTotals'
        - type: object
          required:
            - cost
            - keys
          properties:
            cost:
              type: number
              description: Cost in US dollars.
            keys:
              type: object
              description: Usage by API key name.
              additionalProperties:
                type: object
                required:
                  - total_tokens
                  - total_input_tokens
                  - total_cached_input_tokens
                  - total_output_tokens
                  - total_requests
                  - cost
                  - models
                properties:
                  total_tokens:
                    type: integer
                    format: int64
                  total_input_tokens:
                    type: integer
                    format: int64
                  total_cached_input_tokens:
                    type: integer
                    format: int64
                  total_output_tokens:
                    type: integer
                    format: int64
                  total_requests:
                    type: integer
                    format: int64
                  cost:
                    type: number
                    description: Cost in US dollars.
                  models:
                    type: object
                    description: Usage by model ID.
                    additionalProperties:
                      $ref: '#/components/schemas/ModelUsage'
            container_usage:
              $ref: '#/components/schemas/ContainerUsage'
            billing:
              $ref: '#/components/schemas/BillingInfo'
            time_series:
              $ref: '#/components/schemas/UsageTimeSeries'
    UsageTotals:
      type: object
      required:
        - tokens
        - input_tokens
        - cached_input_tokens
        - output_tokens
        - requests
      properties:
        tokens:
          type: integer
          format: int64
        input_tokens:
          type: integer
          format: int64
          description: Prompt tokens, including those served from the prompt cache.
        cached_input_tokens:
          type: integer
          format: int64
          description: The part of input_tokens served from the prompt cache.
        output_tokens:
          type: integer
          format: int64
          description: Generated tokens, including reasoning tokens.
        requests:
          type: integer
          format: int64
    ModelUsage:
      allOf:
        - $ref: '#/components/schemas/UsageTotals'
        - type: object
          required:
            - cost
          properties:
            cost:
              type: number
              description: Cost in US dollars.
            usage_metric:
              type: string
              enum:
                - tokens
                - requests
              description: >-
                What the model is billed by. Omitted for a model without a
                price.
    ContainerUsage:
      type: object
      description: Container, Bunker and volume usage in the current billing period.
      required:
        - sandboxes
        - sandbox_cost
        - containers
        - volumes
        - compute_cost
        - storage_cost
        - total_cost
      properties:
        sandboxes:
          type: array
          description: Bunkers.
          items:
            $ref: '#/components/schemas/ContainerUsageItem'
        sandbox_cost:
          type: number
          description: Bunker cost in US dollars.
        containers:
          type: array
          items:
            $ref: '#/components/schemas/ContainerUsageItem'
        volumes:
          type: array
          items:
            $ref: '#/components/schemas/VolumeUsageItem'
        compute_cost:
          type: number
          description: Container cost in US dollars.
        storage_cost:
          type: number
          description: Volume cost in US dollars.
        total_cost:
          type: number
          description: Cost of everything in the period in US dollars.
    BillingInfo:
      type: object
      required:
        - containers_billing_exempt
        - tokens_billing_exempt
      properties:
        referral:
          type: object
          description: The referral code applied to the account, if any.
          required:
            - code
            - discount_percent
            - active
          properties:
            code:
              type: string
            discount_percent:
              type: integer
            active:
              type: boolean
        containers_billing_exempt:
          type: boolean
        tokens_billing_exempt:
          type: boolean
        container_billing_period:
          $ref: '#/components/schemas/BillingPeriod'
        previous_container_billing_period:
          $ref: '#/components/schemas/BillingPeriod'
    UsageTimeSeries:
      type: object
      required:
        - data_points
        - interval
      properties:
        data_points:
          type: array
          description: >-
            One point per bucket, oldest first. Empty buckets are included with
            zero values.
          items:
            allOf:
              - $ref: '#/components/schemas/UsageTotals'
              - type: object
                required:
                  - time
                  - models
                properties:
                  time:
                    type: string
                    format: date-time
                    description: Start of the bucket.
                  models:
                    type: object
                    description: Usage in the bucket by model ID.
                    additionalProperties:
                      allOf:
                        - $ref: '#/components/schemas/ModelUsage'
                        - type: object
                          required:
                            - cache_savings
                            - cache_discount_available
                          properties:
                            cache_savings:
                              type:
                                - number
                                - 'null'
                              description: >-
                                Estimated US dollars saved by serving input
                                tokens from the prompt cache, or null for a
                                model without a price.
                            cache_discount_available:
                              type: boolean
                              description: >-
                                Whether the model bills cached input tokens at a
                                discount.
        interval:
          type: string
          description: Bucket width, for example 15m0s.
    Error:
      type: object
      required:
        - error
      properties:
        error:
          type: string
          description: Human-readable error message.
        code:
          type: string
          description: Stable machine-readable error code.
      additionalProperties: true
    ContainerUsageItem:
      type: object
      required:
        - name
        - uptime_hours
        - cpu_hours
        - memory_gb
        - cost
      properties:
        name:
          type: string
        uptime_hours:
          type: number
        cpu_hours:
          type: number
        memory_gb:
          type: number
          description: Memory GB-hours, counting a GB as 1,024 MB.
        cost:
          type: number
          description: Cost in US dollars.
    VolumeUsageItem:
      type: object
      required:
        - id
        - name
        - size_bytes
        - gb_hours
        - cost
        - metered_from
        - metered_until
      properties:
        id:
          type: string
        name:
          type: string
        size_bytes:
          type: integer
          format: int64
        gb_hours:
          type: number
          description: Storage GB-hours.
        cost:
          type: number
          description: Cost in US dollars.
        metered_from:
          type:
            - string
            - 'null'
          format: date-time
        metered_until:
          type:
            - string
            - 'null'
          format: date-time
    BillingPeriod:
      type: object
      required:
        - start
        - end
      properties:
        start:
          type: string
          format: date-time
        end:
          type: string
          format: date-time
  responses:
    Error:
      description: The request failed.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
  securitySchemes:
    apiKey:
      type: http
      scheme: bearer
      description: >-
        An admin API key. Personal admin keys reach the API key, billing and
        Account endpoints for the creator's personal account; the other
        endpoints need an organization admin key. Security requirement entries
        list the permission a scoped key needs for the operation.

````

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