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

# Get the usage

> Returns the capacity-unit seconds and the cost of each minute, hour, or day in a window, and the credit and the balance of the workspace. Only running time that is not degraded costs money. Needs the `billing:read` scope.



## OpenAPI

````yaml /api-reference/openapi.json get /v1/usage
openapi: 3.1.0
info:
  title: VMS API
  version: 1.0.0
  description: >-
    The public API of a VMS workspace. Each request needs an API key of the
    workspace in the Authorization header.
servers:
  - url: https://vms.dev/api
    description: The VMS API
security:
  - apiKey: []
paths:
  /v1/usage:
    get:
      tags:
        - Billing
      summary: Get the usage
      description: >-
        Returns the capacity-unit seconds and the cost of each minute, hour, or
        day in a window, and the credit and the balance of the workspace. Only
        running time that is not degraded costs money. Needs the `billing:read`
        scope.
      operationId: getUsage
      parameters:
        - in: query
          name: from
          schema:
            description: The start of the window. The default is 24 hours before the end.
            type: string
            format: date-time
            pattern: >-
              ^(?:(?:\d\d[2468][048]|\d\d[13579][26]|\d\d0[48]|[02468][048]00|[13579][26]00)-02-29|\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\d|30)|(?:02)-(?:0[1-9]|1\d|2[0-8])))T(?:(?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d(?:\.\d+)?(?:Z|([+-](?:[01]\d|2[0-3]):[0-5]\d)))$
          description: The start of the window. The default is 24 hours before the end.
        - in: query
          name: to
          schema:
            description: The end of the window. The default is now.
            type: string
            format: date-time
            pattern: >-
              ^(?:(?:\d\d[2468][048]|\d\d[13579][26]|\d\d0[48]|[02468][048]00|[13579][26]00)-02-29|\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\d|30)|(?:02)-(?:0[1-9]|1\d|2[0-8])))T(?:(?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d(?:\.\d+)?(?:Z|([+-](?:[01]\d|2[0-3]):[0-5]\d)))$
          description: The end of the window. The default is now.
        - in: query
          name: granularity
          schema:
            default: minute
            description: The length of each point. A window can have 10080 points or fewer.
            type: string
            enum:
              - minute
              - hour
              - day
          description: The length of each point. A window can have 10080 points or fewer.
        - in: query
          name: label
          schema:
            description: >-
              Count only sandboxes with this label, as key:value. Send the
              parameter more than one time to give more labels. A sandbox must
              have each label.
            example:
              - env:prod
            type: array
            items:
              type: string
              pattern: >-
                ^([A-Za-z0-9](?:[A-Za-z0-9._/-]{0,61}[A-Za-z0-9])?):([\s\S]{0,255})$
          description: >-
            Count only sandboxes with this label, as key:value. Send the
            parameter more than one time to give more labels. A sandbox must
            have each label.
        - in: query
          name: groupByLabel
          schema:
            description: >-
              A label key. The answer then has groups: the usage and the cost of
              each value of this label.
            example: customer
            type: string
            pattern: ^[A-Za-z0-9](?:[A-Za-z0-9._/-]{0,61}[A-Za-z0-9])?$
          description: >-
            A label key. The answer then has groups: the usage and the cost of
            each value of this label.
      responses:
        '200':
          description: The usage and the funds.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Usage'
        '400':
          description: The window is not valid or has too many points.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          description: The API key is missing, not correct, revoked, or expired.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '403':
          description: The API key does not have the scope of the endpoint.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '429':
          description: The API key sent more than 1,200 requests in one minute.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
components:
  schemas:
    Usage:
      type: object
      properties:
        from:
          type: string
          format: date-time
          pattern: >-
            ^(?:(?:\d\d[2468][048]|\d\d[13579][26]|\d\d0[48]|[02468][048]00|[13579][26]00)-02-29|\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\d|30)|(?:02)-(?:0[1-9]|1\d|2[0-8])))T(?:(?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d(?:\.\d+)?(?:Z))$
        to:
          type: string
          format: date-time
          pattern: >-
            ^(?:(?:\d\d[2468][048]|\d\d[13579][26]|\d\d0[48]|[02468][048]00|[13579][26]00)-02-29|\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\d|30)|(?:02)-(?:0[1-9]|1\d|2[0-8])))T(?:(?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d(?:\.\d+)?(?:Z))$
        granularity:
          type: string
          enum:
            - minute
            - hour
            - day
        unitSeconds:
          type: integer
          minimum: 0
          maximum: 9007199254740991
        costMicros:
          type: integer
          minimum: -9007199254740991
          maximum: 9007199254740991
          description: 'The cost of the window. In micro-dollars: 1,000,000 is $1.'
        points:
          type: array
          items:
            $ref: '#/components/schemas/UsagePoint'
        groups:
          description: Only with groupByLabel. The values with the highest cost come first.
          type: array
          items:
            $ref: '#/components/schemas/UsageGroup'
        funds:
          $ref: '#/components/schemas/Funds'
      required:
        - from
        - to
        - granularity
        - unitSeconds
        - costMicros
        - points
        - funds
      additionalProperties: false
    Error:
      type: object
      properties:
        error:
          type: object
          properties:
            code:
              type: string
              example: no_capacity
            message:
              type: string
            requestId:
              type:
                - string
                - 'null'
            retryAfterSeconds:
              type: integer
              minimum: 0
              maximum: 9007199254740991
            sandboxId:
              description: The sandbox that the error is about.
              type: string
          required:
            - code
            - message
            - requestId
          additionalProperties: false
      required:
        - error
      additionalProperties: false
    UsagePoint:
      type: object
      properties:
        at:
          type: string
          format: date-time
          pattern: >-
            ^(?:(?:\d\d[2468][048]|\d\d[13579][26]|\d\d0[48]|[02468][048]00|[13579][26]00)-02-29|\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\d|30)|(?:02)-(?:0[1-9]|1\d|2[0-8])))T(?:(?:[01]\d|2[0-3]):[0-5]\d:[0-5]\d(?:\.\d+)?(?:Z))$
          description: The start of the point.
        unitSeconds:
          type: integer
          minimum: 0
          maximum: 9007199254740991
          description: The capacity-unit seconds of running sandboxes.
        costMicros:
          type: integer
          minimum: -9007199254740991
          maximum: 9007199254740991
          description: 'The cost of the point. In micro-dollars: 1,000,000 is $1.'
      required:
        - at
        - unitSeconds
        - costMicros
      additionalProperties: false
    UsageGroup:
      type: object
      properties:
        value:
          description: The value of the label. Null for the sandboxes without the label.
          type:
            - string
            - 'null'
        unitSeconds:
          type: integer
          minimum: 0
          maximum: 9007199254740991
        costMicros:
          type: integer
          minimum: -9007199254740991
          maximum: 9007199254740991
          description: >-
            The cost of the sandboxes with this value. In micro-dollars:
            1,000,000 is $1.
      required:
        - value
        - unitSeconds
        - costMicros
      additionalProperties: false
    Funds:
      type: object
      properties:
        creditMicros:
          type: integer
          minimum: -9007199254740991
          maximum: 9007199254740991
          description: 'The plan credit that is left. In micro-dollars: 1,000,000 is $1.'
        balanceMicros:
          type: integer
          minimum: -9007199254740991
          maximum: 9007199254740991
          description: >-
            The prepaid balance. It is negative when the workspace has debt. In
            micro-dollars: 1,000,000 is $1.
        totalMicros:
          type: integer
          minimum: -9007199254740991
          maximum: 9007199254740991
          description: >-
            The credit and the balance together. In micro-dollars: 1,000,000 is
            $1.
      required:
        - creditMicros
        - balanceMicros
        - totalMicros
      additionalProperties: false
  securitySchemes:
    apiKey:
      type: http
      scheme: bearer
      description: An API key that starts with vms_. Make one in Settings > API keys.

````

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