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

# Limits and remaining credit for the calling key

> Returns the calling key's configured limits and credit state: rate
limits (RPM/TPM), cumulative spend, budget ceiling, and remaining
budget — so a client can distinguish "the model is unhealthy" from
"I'm rate-limited / out of credits" without admin access. The key in
the `Authorization` header sees only itself.

This endpoint is **budget-exempt**: it keeps answering when the key is
out of credits (that is exactly when you need it). Inference endpoints
remain fully budget-gated.

`remaining_budget_usd` is the same value the gateway's 402
`insufficient_balance` check enforces, floored at 0. `rate_limit`
reports the key's *configured* limits — the same values the
`x-ratelimit-*` headers on inference responses advertise; for live
headroom in the current window, read `x-ratelimit-remaining-*` from
those headers.




## OpenAPI

````yaml /inference-api/openapi.yaml get /v1/flex/key
openapi: 3.1.0
info:
  title: FlexAI Inference API
  version: 1.0.0
  description: |
    OpenAI-compatible inference API for text, code, reasoning, vision, and
    embedding models hosted by FlexAI. Use any OpenAI SDK by pointing the
    `base_url` at this service.
  contact:
    name: FlexAI Support
    email: support@flex.ai
    url: https://docs.flex.ai/inference-api/overview
servers:
  - url: https://tokens.flex.ai
    description: Production
security:
  - bearerAuth: []
tags:
  - name: Chat
    description: Chat completions (streaming, tool use, vision).
  - name: Completions
    description: Legacy text completions.
  - name: Embeddings
    description: Generate vector embeddings for text.
  - name: Models
    description: Discover available models.
  - name: Usage
    description: Programmatic spend and quota for the calling key.
paths:
  /v1/flex/key:
    get:
      tags:
        - Usage
      summary: Limits and remaining credit for the calling key
      description: |
        Returns the calling key's configured limits and credit state: rate
        limits (RPM/TPM), cumulative spend, budget ceiling, and remaining
        budget — so a client can distinguish "the model is unhealthy" from
        "I'm rate-limited / out of credits" without admin access. The key in
        the `Authorization` header sees only itself.

        This endpoint is **budget-exempt**: it keeps answering when the key is
        out of credits (that is exactly when you need it). Inference endpoints
        remain fully budget-gated.

        `remaining_budget_usd` is the same value the gateway's 402
        `insufficient_balance` check enforces, floored at 0. `rate_limit`
        reports the key's *configured* limits — the same values the
        `x-ratelimit-*` headers on inference responses advertise; for live
        headroom in the current window, read `x-ratelimit-remaining-*` from
        those headers.
      operationId: getKey
      responses:
        '200':
          description: Successful response
          content:
            application/json:
              schema:
                type: object
                required:
                  - object
                  - currency
                  - key_name
                  - spend_usd
                  - max_budget_usd
                  - remaining_budget_usd
                  - rate_limit
                  - expires_at
                  - generated_at
                properties:
                  object:
                    type: string
                    enum:
                      - key
                  currency:
                    type: string
                    enum:
                      - USD
                  key_name:
                    type: string
                    nullable: true
                    description: Masked display name ("sk-...abcd"); never the full key.
                  spend_usd:
                    type: number
                  max_budget_usd:
                    type: number
                    nullable: true
                    description: >-
                      Budget ceiling for this key; null when no per-key ceiling
                      is configured.
                  remaining_budget_usd:
                    type: number
                    nullable: true
                    description: >-
                      max_budget_usd - spend_usd, floored at 0; null when
                      max_budget_usd is null.
                  rate_limit:
                    type: object
                    required:
                      - rpm
                      - tpm
                    properties:
                      rpm:
                        type: integer
                        nullable: true
                        description: >-
                          Requests per minute; null when no per-key limit is
                          configured.
                      tpm:
                        type: integer
                        nullable: true
                        description: >-
                          Tokens per minute; null when no per-key limit is
                          configured.
                  expires_at:
                    type: string
                    format: date-time
                    nullable: true
                    description: When this key expires; null means it never expires.
                  generated_at:
                    type: string
                    format: date-time
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          description: The key is blocked.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '429':
          $ref: '#/components/responses/RateLimited'
        '502':
          description: Upstream authentication service unavailable. Retry shortly.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
components:
  responses:
    Unauthorized:
      description: Missing or invalid API key.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    RateLimited:
      description: |
        Per-key RPM exceeded. Response includes `Retry-After` and
        `x-ratelimit-*` headers.
      headers:
        Retry-After:
          schema:
            type: integer
          description: Seconds until the next window.
        x-ratelimit-limit-requests:
          schema:
            type: integer
        x-ratelimit-remaining-requests:
          schema:
            type: integer
        x-ratelimit-reset-requests:
          schema:
            type: integer
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
  schemas:
    Error:
      type: object
      required:
        - error
      properties:
        error:
          type: object
          required:
            - message
            - type
          properties:
            message:
              type: string
            type:
              type: string
              example: invalid_request_error
            code:
              type: string
              description: |
                Stable machine-readable code for the failure. Present on
                most error paths; OMITTED on FastAPI default-validation
                bodies. Do not assume always present.
            doc_url:
              type: string
              format: uri
              description: |
                FlexAI extension. Link to the relevant dashboard / docs
                page for the failure mode (e.g. invalid key → /dashboard/keys).
                Present on auth and quota errors.
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: sk-xxxx
      description: |
        Virtual API key. Create one from the
        [FlexAI dashboard](https://tokens.flex.ai/dashboard/keys). Pass as
        `Authorization: Bearer sk-xxxx`.

````