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

# Usage

> Usage, cost, credit balance, API keys and spend caps for the organization that owns the API key.

Your organization's token usage and cost over a time window, along with its credit balance, API keys and spend caps. Any API key in the organization can call it, and the report always covers the whole organization behind that key.

```bash theme={null}
curl "https://models.relace.ai/v1/usage?bucket=week&group_by=model,api_key" \
  -H "Authorization: Bearer $RELACE_API_KEY"
```

## Time window

`start` and `end` take RFC 3339 timestamps with a time zone, such as `2026-11-01T00:00:00Z`. Both are rounded down to the hour, so usage is reported in whole hours and the current hour appears once it ends.

* With neither set, the report covers the last 7 days.
* `start` can go back at most 90 days.
* `end` cannot be in the future.

The `usage.start` and `usage.end` fields in the response show the window after defaults and rounding.

## Buckets

`bucket` splits the window into `day`, `week` or `month` buckets, all in UTC. Weeks start on Monday and months start on the 1st. The first and last buckets are cut to the window, so a window from Wednesday to the following Wednesday returns two week buckets: Wednesday to Monday, then Monday to Wednesday.

Every bucket in the window is returned, including buckets with no usage, which have an empty `results` list.

## Grouping

`group_by` sets what each bucket's `results` are split by:

| `group_by` | One result per |
| - | - |
| `model` (default) | model |
| `api_key` | API key |
| `model,api_key` | model and API key pair |
| empty (`group_by=`) | bucket |

> [!WARNING]
>
> Per-key usage is only available from December 2, 2026 onward. Usage before that date is not attributed to any key: with `group_by=api_key` or `group_by=model,api_key`, it appears under `api_key_id: null`. To see usage per key, set `start` to `2026-12-02T00:00:00Z` or later.

`api_key_id` matches an entry in `keys`, so you can look up a key's name. It is `null` for usage before December 2, 2026, and for usage from the Relace console.

`totals` covers the whole window and is the same whatever `bucket` and `group_by` you choose.

## Tokens and cost

* `input_tokens` counts all input tokens, cached ones included. `cached_input_tokens` is the part served from the prefix cache.
* Money fields are US dollars as decimal strings with 9 decimal places, such as `"0.710000000"`. Parse them as decimals, not floats, to avoid rounding errors.
* Each result is rounded down to 9 decimal places on its own, so `totals.cost_usd` can be slightly higher than the sum of the results shown, by less than \$0.000000001 per result.

## Credits, keys and spend caps

* `credits.remaining_usd` is the prepaid credit balance. `credits` is `null` for accounts billed by invoice.
* `keys` lists every API key in the organization, newest first, including revoked keys with their `revoked_at` time.
* `spend_caps` lists the organization's daily, weekly and monthly spend caps with the current period's spend. `capped_until` is set while a cap is blocking requests.

This endpoint keeps working when the organization is out of credits or over a spend cap, so you can always check where you stand.

## Rate limits

Usage calls have their own budget of 60 requests per minute per organization, shared by all of the organization's keys. They do not count against your model request rate limit. Over the limit, you'll receive a `429` with a `Retry-After` header.

If the usage service is briefly unavailable, you'll receive a `503` with a `Retry-After` header and can retry after that interval. A report is never returned partially.


## OpenAPI

````yaml GET /v1/usage
openapi: 3.0.1
info:
  title: Relace API
  description: API for accessing Relace code generation models.
  version: 1.0.0
  license:
    name: MIT
servers:
  - url: https://models.relace.ai
    description: Server for model API endpoints
security:
  - bearerAuth: []
paths:
  /v1/usage:
    get:
      description: >-
        Usage, cost, credit balance, API keys and spend caps for the
        organization that owns the API key.
      parameters:
        - name: start
          in: query
          required: false
          schema:
            type: string
            format: date-time
          description: >-
            Start of the window, as an RFC 3339 timestamp with a time zone.
            Rounded down to the hour. Must be within the last 90 days. Defaults
            to 7 days before `end`.
          example: '2026-11-01T00:00:00Z'
        - name: end
          in: query
          required: false
          schema:
            type: string
            format: date-time
          description: >-
            End of the window, as an RFC 3339 timestamp with a time zone.
            Rounded down to the hour. Must not be in the future. Defaults to
            now.
          example: '2026-12-01T00:00:00Z'
        - name: bucket
          in: query
          required: false
          schema:
            type: string
            enum:
              - day
              - week
              - month
            default: day
          description: >-
            Bucket size. Weeks start Monday 00:00 UTC. Months start on the 1st
            at 00:00 UTC.
        - name: group_by
          in: query
          required: false
          schema:
            type: string
            default: model
          description: >-
            Comma-separated list of `model` and `api_key`. Pass an empty value
            (`group_by=`) for one result per bucket.
          example: model,api_key
      responses:
        '200':
          description: The usage report
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/UsageResponse'
        '400':
          description: Invalid query parameters
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    description: Error message
                    example: >-
                      Invalid usage query: `start` must be within the last 90
                      days.
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error401'
        '429':
          description: Rate limit exceeded
          headers:
            Retry-After:
              schema:
                type: string
              description: Seconds to wait before retrying
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error429'
        '503':
          description: Usage is temporarily unavailable
          headers:
            Retry-After:
              schema:
                type: string
              description: Seconds to wait before retrying
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                    description: Error message
                    example: Usage is unavailable; retry shortly.
      servers:
        - url: https://models.relace.ai
components:
  schemas:
    UsageResponse:
      type: object
      properties:
        billing_mode:
          type: string
          enum:
            - credit
            - invoice
          description: '`credit` for prepaid credits, `invoice` for monthly invoicing.'
        credits:
          type: object
          nullable: true
          description: Remaining prepaid credits. `null` for invoice accounts.
          properties:
            remaining_usd:
              type: string
              description: Remaining credit balance in US dollars.
              example: '12.345678901'
        usage:
          type: object
          properties:
            start:
              type: string
              format: date-time
              description: Start of the window, after defaults and rounding.
              example: '2026-11-26T00:00:00.000Z'
            end:
              type: string
              format: date-time
              description: End of the window, after defaults and rounding.
              example: '2026-12-03T00:00:00.000Z'
            bucket:
              type: string
              enum:
                - day
                - week
                - month
            group_by:
              type: array
              items:
                type: string
                enum:
                  - model
                  - api_key
              description: The grouping applied. Empty when results are not grouped.
              example:
                - model
                - api_key
            totals:
              $ref: '#/components/schemas/UsageAmounts'
            buckets:
              type: array
              items:
                $ref: '#/components/schemas/UsageBucket'
        keys:
          type: array
          description: >-
            Every API key of the organization, revoked keys included, newest
            first.
          items:
            $ref: '#/components/schemas/UsageKey'
        spend_caps:
          type: array
          description: The organization's spend caps, daily first. Empty when none are set.
          items:
            $ref: '#/components/schemas/UsageSpendCap'
        as_of:
          type: string
          format: date-time
          description: When this report was built.
          example: '2026-12-03T00:51:12.000Z'
    Error401:
      type: object
      properties:
        error:
          type: string
          description: Error message
          example: >-
            Invalid API key. Check the key, or create one at
            https://app.relace.ai.
    Error429:
      type: object
      properties:
        error:
          type: string
          description: Error message
          example: >-
            Rate limit exceeded. Retry after the Retry-After interval, or
            contact support to raise your limits.
    UsageAmounts:
      type: object
      description: Tokens and cost.
      properties:
        input_tokens:
          type: integer
          description: Input tokens, cached input tokens included.
          example: 50000
        cached_input_tokens:
          type: integer
          description: The part of `input_tokens` served from the prefix cache.
          example: 1000
        output_tokens:
          type: integer
          description: Output tokens.
          example: 4000
        cost_usd:
          type: string
          description: US dollars as a decimal string with 9 decimal places, rounded down.
          example: '0.710000000'
    UsageBucket:
      type: object
      properties:
        start:
          type: string
          format: date-time
          description: Start of the bucket, inclusive.
          example: '2026-11-26T00:00:00.000Z'
        end:
          type: string
          format: date-time
          description: End of the bucket, exclusive.
          example: '2026-11-27T00:00:00.000Z'
        results:
          type: array
          description: >-
            One entry per group with usage in the bucket, sorted by model and
            then by key id. Empty when the bucket has no usage.
          items:
            $ref: '#/components/schemas/UsageResult'
    UsageKey:
      type: object
      properties:
        id:
          type: integer
          example: 42
        name:
          type: string
          nullable: true
          example: ci
        redacted_key:
          type: string
          nullable: true
          description: The first 6 and last 4 characters of the key.
          example: rlc-ab...wxyz
        is_service:
          type: boolean
          description: '`true` for an organization service key, `false` for a personal key.'
          example: false
        created_at:
          type: string
          format: date-time
          example: '2026-10-14T18:22:05.000Z'
        last_used:
          type: string
          format: date-time
          nullable: true
          example: '2026-12-02T23:58:41.000Z'
        revoked_at:
          type: string
          format: date-time
          nullable: true
          description: When the key was revoked. `null` for an active key.
          example: null
    UsageSpendCap:
      type: object
      properties:
        period:
          type: string
          enum:
            - daily
            - weekly
            - monthly
        limit_usd:
          type: string
          description: The cap, in US dollars.
          example: '50.000000000'
        spent_usd:
          type: string
          description: Spend in the current period, in US dollars.
          example: '3.200000000'
        resets_at:
          type: string
          format: date-time
          description: When the current period ends and spend resets.
          example: '2026-12-04T00:00:00.000Z'
        capped_until:
          type: string
          format: date-time
          nullable: true
          description: >-
            Set while the organization is blocked by this cap. Requests are
            refused until this time. `null` otherwise.
          example: null
    UsageResult:
      type: object
      description: Tokens and cost for one group in one bucket.
      properties:
        model:
          type: string
          description: The model. Present only when `group_by` includes `model`.
          example: relace-apply-3
        api_key_id:
          type: integer
          nullable: true
          description: >-
            The API key's id, matching `keys[].id`. Present only when `group_by`
            includes `api_key`. `null` for usage before December 2, 2026, when
            per-key reporting began, and for usage from the Relace console.
          example: 42
        input_tokens:
          type: integer
          description: Input tokens, cached input tokens included.
          example: 50000
        cached_input_tokens:
          type: integer
          description: The part of `input_tokens` served from the prefix cache.
          example: 1000
        output_tokens:
          type: integer
          description: Output tokens.
          example: 4000
        cost_usd:
          type: string
          description: US dollars as a decimal string with 9 decimal places, rounded down.
          example: '0.710000000'
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: Relace API key Authorization header using the Bearer scheme.

````

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