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

# Read a virtual key's spend

> Aggregate spend and request count for one key over a window given in epoch milliseconds (default: current UTC calendar month). Reads the cost path (`trace_summaries`), the same source the dashboard's key list and Usage tab read, so this number, the UI column, and the Usage page agree by construction. Returns 412 `spend_source_unavailable` on deploys without a ClickHouse spend source rather than a $0.00 that cannot be told apart from a zero-spend key.



## OpenAPI

````yaml GET /api/gateway/v1/virtual-keys/{id}/spend
openapi: 3.1.0
info:
  title: LangWatch API
  version: 1.0.0
  description: LangWatch openapi spec
servers:
  - url: https://app.langwatch.ai
security:
  - project_api_key: []
paths:
  /api/gateway/v1/virtual-keys/{id}/spend:
    get:
      tags:
        - Virtual Keys
      summary: Read a virtual key's spend
      description: >-
        Aggregate spend and request count for one key over a window given in
        epoch milliseconds (default: current UTC calendar month). Reads the cost
        path (`trace_summaries`), the same source the dashboard's key list and
        Usage tab read, so this number, the UI column, and the Usage page agree
        by construction. Returns 412 `spend_source_unavailable` on deploys
        without a ClickHouse spend source rather than a $0.00 that cannot be
        told apart from a zero-spend key.
      operationId: getApiGatewayV1Virtual-keysByIdSpend
      parameters:
        - in: query
          name: from
          schema:
            type: integer
            minimum: -9007199254740991
            maximum: 9007199254740991
        - in: query
          name: to
          schema:
            type: integer
            minimum: -9007199254740991
            maximum: 9007199254740991
        - schema:
            type: string
          in: path
          name: id
          required: true
      responses:
        '200':
          description: Spend summary for the key
          content:
            application/json:
              schema:
                type: object
                properties:
                  virtual_key_id:
                    type: string
                  spent_usd:
                    type: string
                    description: >-
                      Spend over the window, summed from the cost path. Decimal
                      string, up to 9 fractional digits, trailing zeros trimmed,
                      never exponent notation.
                  requests:
                    type: integer
                  window:
                    type: object
                    properties:
                      from:
                        type: integer
                      to:
                        type: integer
                    required:
                      - from
                      - to
                required:
                  - virtual_key_id
                  - spent_usd
                  - requests
                  - window
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      type:
                        type: string
                      code:
                        type: string
                      message:
                        type: string
                      meta:
                        type: object
                        additionalProperties: {}
                      trace_id:
                        type: string
                      span_id:
                        type: string
                    required:
                      - type
                      - code
                      - message
                required:
                  - error
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      type:
                        type: string
                      code:
                        type: string
                      message:
                        type: string
                      meta:
                        type: object
                        additionalProperties: {}
                      trace_id:
                        type: string
                      span_id:
                        type: string
                    required:
                      - type
                      - code
                      - message
                required:
                  - error
        '403':
          description: Forbidden
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      type:
                        type: string
                      code:
                        type: string
                      message:
                        type: string
                      meta:
                        type: object
                        additionalProperties: {}
                      trace_id:
                        type: string
                      span_id:
                        type: string
                    required:
                      - type
                      - code
                      - message
                required:
                  - error
        '404':
          description: Not found
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      type:
                        type: string
                      code:
                        type: string
                      message:
                        type: string
                      meta:
                        type: object
                        additionalProperties: {}
                      trace_id:
                        type: string
                      span_id:
                        type: string
                    required:
                      - type
                      - code
                      - message
                required:
                  - error
        '412':
          description: No spend source on this deployment
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      type:
                        type: string
                      code:
                        type: string
                      message:
                        type: string
                      meta:
                        type: object
                        additionalProperties: {}
                      trace_id:
                        type: string
                      span_id:
                        type: string
                    required:
                      - type
                      - code
                      - message
                required:
                  - error
        '500':
          description: Internal Server Error
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: object
                    properties:
                      type:
                        type: string
                      code:
                        type: string
                      message:
                        type: string
                      meta:
                        type: object
                        additionalProperties: {}
                      trace_id:
                        type: string
                      span_id:
                        type: string
                    required:
                      - type
                      - code
                      - message
                required:
                  - error
components:
  securitySchemes:
    project_api_key:
      type: apiKey
      in: header
      name: X-Auth-Token
      description: >-
        Project API key for sending traces and accessing project-scoped
        resources. Format: sk-lw-... (no underscore). Obtain one by creating a
        project via the Admin API or the LangWatch UI.

````