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

# Get usage

> Read the organization's API usage, grouped by action or day.

Aggregates your organization's API-attributed credit transactions into usage
buckets. Returns `total_credits`, `total_requests`, and a list of `buckets`
(`key`, `credits`, `requests`). Narrow the window with `from`/`to`, choose the
grouping with `group_by` (by action or by day), and scope to a single key with
`api_key_id`. Requires the `usage.read` scope.


## OpenAPI

````yaml api-reference/openapi.json GET /usage
openapi: 3.1.0
info:
  title: Samsa API
  description: >-
    The Samsa public REST API. Authenticate with an organization API key as a
    bearer token (`Authorization: Bearer samsa_sk_...`). Errors follow a single
    envelope shape; every response carries an `X-Request-ID`.
  version: 1.0.0
servers:
  - url: https://api.samsa.ai/public/v1
security:
  - BearerAuth: []
paths:
  /usage:
    get:
      tags:
        - Usage
      summary: Read the organization's API usage, grouped by action or day
      description: >-
        Aggregate the org's API-attributed credit transactions into usage
        buckets.
      operationId: read_usage_usage_get
      parameters:
        - name: from
          in: query
          required: false
          schema:
            anyOf:
              - type: string
              - type: 'null'
            description: >-
              ISO-8601 date or datetime lower bound (inclusive). Defaults to the
              current billing period's start when both bounds are omitted.
            examples:
              - '2026-07-01'
            title: From
          description: >-
            ISO-8601 date or datetime lower bound (inclusive). Defaults to the
            current billing period's start when both bounds are omitted.
        - name: to
          in: query
          required: false
          schema:
            anyOf:
              - type: string
              - type: 'null'
            description: >-
              ISO-8601 date or datetime upper bound (inclusive; a bare date
              covers the whole day). Defaults to the current billing period's
              end when both bounds are omitted.
            examples:
              - '2026-07-31'
            title: To
          description: >-
            ISO-8601 date or datetime upper bound (inclusive; a bare date covers
            the whole day). Defaults to the current billing period's end when
            both bounds are omitted.
        - name: group_by
          in: query
          required: false
          schema:
            enum:
              - action
              - day
            type: string
            description: 'Bucket dimension: `action` (action type) or `day` (calendar date).'
            default: day
            title: Group By
          description: 'Bucket dimension: `action` (action type) or `day` (calendar date).'
        - name: api_key_id
          in: query
          required: false
          schema:
            anyOf:
              - type: string
                format: uuid
              - type: 'null'
            description: Restrict to one of the organization's API keys (404 if not yours).
            title: Api Key Id
          description: Restrict to one of the organization's API keys (404 if not yours).
        - name: authorization
          in: header
          required: false
          schema:
            anyOf:
              - type: string
              - type: 'null'
            title: Authorization
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PublicUsageResponse'
        '401':
          description: Missing, invalid, expired, or revoked API key.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
        '402':
          description: Insufficient credits or inactive subscription.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
        '403':
          description: The API key lacks the required scope.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
        '404':
          description: Resource not found.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
        '422':
          description: Request validation failed.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
        '429':
          description: Rate limit exceeded.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
        '500':
          description: Internal server error.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorEnvelope'
components:
  schemas:
    PublicUsageResponse:
      properties:
        total_credits:
          type: integer
          title: Total Credits
          description: Net credits across all buckets.
          examples:
            - 45
        total_requests:
          type: integer
          title: Total Requests
          description: Billed requests across all buckets.
          examples:
            - 9
        buckets:
          items:
            $ref: '#/components/schemas/PublicUsageBucket'
          type: array
          title: Buckets
      type: object
      required:
        - total_credits
        - total_requests
        - buckets
      title: PublicUsageResponse
      description: '``GET /usage`` body — org usage over API-attributed transactions.'
    ErrorEnvelope:
      properties:
        error:
          $ref: '#/components/schemas/ErrorDetail'
      type: object
      required:
        - error
      title: ErrorEnvelope
      description: The complete public error body — an ``error`` object wrapper (ADR §5).
    PublicUsageBucket:
      properties:
        key:
          type: string
          title: Key
          description: >-
            Bucket key — an action type for `group_by=action`, or a calendar
            date (`YYYY-MM-DD`) for `group_by=day`.
          examples:
            - IMAGE_GENERATION
        credits:
          type: integer
          title: Credits
          description: Net credits spent in this bucket (refunds subtracted).
          examples:
            - 25
        requests:
          type: integer
          title: Requests
          description: Billed requests in this bucket (refunds are not requests).
          examples:
            - 5
      type: object
      required:
        - key
        - credits
        - requests
      title: PublicUsageBucket
      description: One aggregation bucket of ``GET /usage``.
    ErrorDetail:
      properties:
        type:
          type: string
          title: Type
          examples:
            - authentication_error
        code:
          type: string
          title: Code
          examples:
            - invalid_api_key
        message:
          type: string
          title: Message
          examples:
            - The provided API key is invalid, expired, or revoked.
        request_id:
          type: string
          title: Request Id
          examples:
            - 8f14e45fceea167a5a36dedd4bea2543
        param:
          anyOf:
            - type: string
            - type: 'null'
          title: Param
          description: Present on validation errors — names the offending field.
          examples:
            - aspect_ratio
      type: object
      required:
        - type
        - code
        - message
        - request_id
      title: ErrorDetail
      description: The ``error`` object of the public envelope (ADR §5).
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      description: >-
        Organization API key as a bearer token: `Authorization: Bearer
        samsa_sk_...`.

````