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

# Roll up token and cost totals for a batch of sessions

> Rolls up token counts and cost for the sessions named in session_ids and returns one row per session. Ids that do not exist in this organization are omitted rather than erroring, so compare the row count against what you asked for. The request is rejected if it names more ids than the per-request maximum.



## OpenAPI

````yaml /managed-agents/openapi.yaml get /managed-agents/v1/sessions/usage
openapi: 3.1.0
info:
  title: Managed Agents API
  version: 0.14.0
  description: >-
    The Recursion Managed Agents REST API. Authenticate with a Recursion API key
    as a bearer token. An organization-scoped key acts in its own organization
    and needs nothing else; a tenant-scoped key must also send
    `x-organization-id` with an organization id or `default`. Field names follow
    each operation's published schema.
servers:
  - url: https://api.recursion.labelbox.com
security:
  - bearerAuth: []
paths:
  /managed-agents/v1/sessions/usage:
    get:
      tags:
        - Sessions
      summary: Roll up token and cost totals for a batch of sessions
      description: >-
        Rolls up token counts and cost for the sessions named in session_ids and
        returns one row per session. Ids that do not exist in this organization
        are omitted rather than erroring, so compare the row count against what
        you asked for. The request is rejected if it names more ids than the
        per-request maximum.
      operationId: managedAgentsListSessionUsage
      parameters:
        - description: >-
            Comma-separated session ids to roll up, matching the ids returned by
            GET /v1/sessions. Ids that do not exist in this organization or are
            outside the caller's access policy are omitted from the response
            rather than erroring.
          in: query
          name: session_ids
          required: true
          schema:
            description: >-
              Comma-separated session ids to roll up, matching the ids returned
              by GET /v1/sessions. Ids that do not exist in this organization or
              are outside the caller's access policy are omitted from the
              response rather than erroring.
            type: string
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ManagedAgentsSessionUsageListResponse'
          description: >-
            Response body of GET /v1/sessions/usage: token and cost totals for
            an explicit batch of session ids, so a list view can show a cost per
            row without reading every session's events. session_ids is required
            and bounded; too many ids is rejected outright rather than
            truncated, because a silently short answer is indistinguishable from
            idle sessions.
        '400':
          description: The request was rejected by schema or semantic validation.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ManagedAgentsApiErrorInvalidRequest'
        '401':
          description: The caller is unauthenticated.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ManagedAgentsApiErrorUnauthorized'
        '403':
          description: The caller lacks a required permission or capability.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ManagedAgentsApiErrorForbidden'
        '409':
          description: >-
            The request conflicts with the resource state, or with an in-flight
            idempotent replay.
          content:
            application/json:
              schema:
                $ref: >-
                  #/components/schemas/ManagedAgentsApiErrorIosClientUpdateRequired
        '429':
          headers:
            Retry-After:
              description: When to retry, as delay seconds or an HTTP date.
              schema:
                type: string
          description: A rate limit is exhausted. Honor `Retry-After`.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ManagedAgentsApiErrorRateLimitExceeded'
        '500':
          description: An unexpected server-side failure.
          content:
            application/json:
              schema:
                oneOf:
                  - $ref: '#/components/schemas/ManagedAgentsApiErrorInternalError'
                  - $ref: >-
                      #/components/schemas/ManagedAgentsApiErrorInvariantViolation
                discriminator:
                  propertyName: code
                  mapping:
                    internal_error:
                      $ref: '#/components/schemas/ManagedAgentsApiErrorInternalError'
                    invariant_violation:
                      $ref: >-
                        #/components/schemas/ManagedAgentsApiErrorInvariantViolation
        '502':
          description: The service returned an invalid response.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ManagedAgentsApiErrorBadGateway'
        '503':
          description: >-
            A dependency is unavailable. Consult details.retryable and
            Retry-After when present before retrying.
          content:
            application/json:
              schema:
                oneOf:
                  - $ref: >-
                      #/components/schemas/ManagedAgentsApiErrorManagedAgentsUnavailable
                  - $ref: >-
                      #/components/schemas/ManagedAgentsApiErrorServiceUnavailable
                discriminator:
                  propertyName: code
                  mapping:
                    managed_agents_unavailable:
                      $ref: >-
                        #/components/schemas/ManagedAgentsApiErrorManagedAgentsUnavailable
                    service_unavailable:
                      $ref: >-
                        #/components/schemas/ManagedAgentsApiErrorServiceUnavailable
        '504':
          description: The service did not respond before the timeout.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ManagedAgentsApiErrorGatewayTimeout'
components:
  schemas:
    ManagedAgentsSessionUsageListResponse:
      description: >-
        Response body of GET /v1/sessions/usage: token and cost totals for an
        explicit batch of session ids, so a list view can show a cost per row
        without reading every session's events. session_ids is required and
        bounded; too many ids is rejected outright rather than truncated,
        because a silently short answer is indistinguishable from idle sessions.
      properties:
        session_usage:
          description: >-
            One roll-up row per requested session id that the caller can see.
            Null rather than an empty array when none of the requested ids
            resolved. Ids naming nothing visible are omitted, so the result may
            be shorter than session_ids and the order should not be assumed to
            match.
          items:
            $ref: '#/components/schemas/ManagedAgentsSessionUsage'
          type:
            - array
            - 'null'
      required:
        - session_usage
      type: object
      example:
        session_usage:
          - cache_read_tokens: 1
            cache_write_tokens: 1
            cost_micros: 1
            event_count: 1
            input_tokens: 1
            output_tokens: 1
            session_id: 9f8b1c2d-3e4f-5a6b-7c8d-9e0f1a2b3c4d
    ManagedAgentsApiErrorInvalidRequest:
      type: object
      properties:
        code:
          type: string
          minLength: 1
          description: Stable machine-readable error code.
          enum:
            - invalid_request
        message:
          type: string
          minLength: 1
          description: Human-readable error message.
        details:
          $ref: '#/components/schemas/ManagedAgentsApiErrorDetails'
          description: >-
            Optional structured error details. Reserved transport fields are
            typed; code-specific fields remain forward compatible.
      required:
        - code
        - message
      additionalProperties: false
      description: Standard flat error response.
    ManagedAgentsApiErrorUnauthorized:
      type: object
      properties:
        code:
          type: string
          minLength: 1
          description: Stable machine-readable error code.
          enum:
            - unauthorized
        message:
          type: string
          minLength: 1
          description: Human-readable error message.
        details:
          $ref: '#/components/schemas/ManagedAgentsApiErrorDetails'
          description: >-
            Optional structured error details. Reserved transport fields are
            typed; code-specific fields remain forward compatible.
      required:
        - code
        - message
      additionalProperties: false
      description: Standard flat error response.
    ManagedAgentsApiErrorForbidden:
      type: object
      properties:
        code:
          type: string
          minLength: 1
          description: Stable machine-readable error code.
          enum:
            - forbidden
        message:
          type: string
          minLength: 1
          description: Human-readable error message.
        details:
          $ref: '#/components/schemas/ManagedAgentsApiErrorDetails'
          description: >-
            Optional structured error details. Reserved transport fields are
            typed; code-specific fields remain forward compatible.
      required:
        - code
        - message
      additionalProperties: false
      description: Standard flat error response.
    ManagedAgentsApiErrorIosClientUpdateRequired:
      type: object
      properties:
        code:
          type: string
          minLength: 1
          description: Stable machine-readable error code.
          enum:
            - ios_client_update_required
        message:
          type: string
          minLength: 1
          description: Human-readable error message.
        details:
          $ref: '#/components/schemas/ManagedAgentsApiErrorDetails'
          description: >-
            Optional structured error details. Reserved transport fields are
            typed; code-specific fields remain forward compatible.
      required:
        - code
        - message
      additionalProperties: false
      description: Standard flat error response.
    ManagedAgentsApiErrorRateLimitExceeded:
      type: object
      properties:
        code:
          type: string
          minLength: 1
          description: Stable machine-readable error code.
          enum:
            - rate_limit_exceeded
        message:
          type: string
          minLength: 1
          description: Human-readable error message.
        details:
          $ref: '#/components/schemas/ManagedAgentsApiErrorDetails'
          description: >-
            Optional structured error details. Reserved transport fields are
            typed; code-specific fields remain forward compatible.
      required:
        - code
        - message
      additionalProperties: false
      description: Standard flat error response.
    ManagedAgentsApiErrorInternalError:
      type: object
      properties:
        code:
          type: string
          minLength: 1
          description: Stable machine-readable error code.
          enum:
            - internal_error
        message:
          type: string
          minLength: 1
          description: Human-readable error message.
        details:
          $ref: '#/components/schemas/ManagedAgentsApiErrorDetails'
          description: >-
            Optional structured error details. Reserved transport fields are
            typed; code-specific fields remain forward compatible.
      required:
        - code
        - message
      additionalProperties: false
      description: Standard flat error response.
    ManagedAgentsApiErrorInvariantViolation:
      type: object
      properties:
        code:
          type: string
          minLength: 1
          description: Stable machine-readable error code.
          enum:
            - invariant_violation
        message:
          type: string
          minLength: 1
          description: Human-readable error message.
        details:
          $ref: '#/components/schemas/ManagedAgentsApiErrorDetails'
          description: >-
            Optional structured error details. Reserved transport fields are
            typed; code-specific fields remain forward compatible.
      required:
        - code
        - message
      additionalProperties: false
      description: Standard flat error response.
    ManagedAgentsApiErrorBadGateway:
      type: object
      properties:
        code:
          type: string
          minLength: 1
          description: Stable machine-readable error code.
          enum:
            - bad_gateway
        message:
          type: string
          minLength: 1
          description: Human-readable error message.
        details:
          $ref: '#/components/schemas/ManagedAgentsApiErrorDetails'
          description: >-
            Optional structured error details. Reserved transport fields are
            typed; code-specific fields remain forward compatible.
      required:
        - code
        - message
      additionalProperties: false
      description: Standard flat error response.
    ManagedAgentsApiErrorManagedAgentsUnavailable:
      type: object
      properties:
        code:
          type: string
          minLength: 1
          description: Stable machine-readable error code.
          enum:
            - managed_agents_unavailable
        message:
          type: string
          minLength: 1
          description: Human-readable error message.
        details:
          $ref: '#/components/schemas/ManagedAgentsApiErrorDetails'
          description: >-
            Optional structured error details. Reserved transport fields are
            typed; code-specific fields remain forward compatible.
      required:
        - code
        - message
      additionalProperties: false
      description: Standard flat error response.
    ManagedAgentsApiErrorServiceUnavailable:
      type: object
      properties:
        code:
          type: string
          minLength: 1
          description: Stable machine-readable error code.
          enum:
            - service_unavailable
        message:
          type: string
          minLength: 1
          description: Human-readable error message.
        details:
          $ref: '#/components/schemas/ManagedAgentsApiErrorDetails'
          description: >-
            Optional structured error details. Reserved transport fields are
            typed; code-specific fields remain forward compatible.
      required:
        - code
        - message
      additionalProperties: false
      description: Standard flat error response.
    ManagedAgentsApiErrorGatewayTimeout:
      type: object
      properties:
        code:
          type: string
          minLength: 1
          description: Stable machine-readable error code.
          enum:
            - gateway_timeout
        message:
          type: string
          minLength: 1
          description: Human-readable error message.
        details:
          $ref: '#/components/schemas/ManagedAgentsApiErrorDetails'
          description: >-
            Optional structured error details. Reserved transport fields are
            typed; code-specific fields remain forward compatible.
      required:
        - code
        - message
      additionalProperties: false
      description: Standard flat error response.
    ManagedAgentsSessionUsage:
      description: >-
        Token and cost totals for one session, summed over that session's own
        events. Scoped to the session's own timeline and not its subtree, so a
        delegating session's totals exclude its children.
      properties:
        cache_read_tokens:
          description: >-
            Prompt tokens served from the provider's prompt cache, billed at the
            cached rate.
          format: int64
          type: integer
        cache_write_tokens:
          description: Prompt tokens written into the provider's prompt cache.
          format: int64
          type: integer
        cost_micros:
          description: >-
            Accrued cost in micro-USD (1,000,000 = 1 USD). Integer to avoid
            float rounding across many small charges.
          format: int64
          type: integer
        event_count:
          description: >-
            How many of the session's own events were summed to produce these
            totals.
          format: int64
          type: integer
        input_tokens:
          description: Prompt tokens billed for this unit of work.
          format: int64
          type: integer
        output_tokens:
          description: Completion tokens billed for this unit of work.
          format: int64
          type: integer
        session_id:
          description: Session these totals cover (UUID).
          type: string
      required:
        - session_id
        - event_count
        - input_tokens
        - output_tokens
        - cache_read_tokens
        - cache_write_tokens
        - cost_micros
      type: object
      example:
        cache_read_tokens: 1
        cache_write_tokens: 1
        cost_micros: 1
        event_count: 1
        input_tokens: 1
        output_tokens: 1
        session_id: 9f8b1c2d-3e4f-5a6b-7c8d-9e0f1a2b3c4d
    ManagedAgentsApiErrorDetails:
      type: object
      properties:
        field:
          description: >-
            Request field or header responsible for the error, when one can be
            identified.
          type: string
        issues:
          description: >-
            Boundary-validation failures as path-prefixed human-readable
            messages.
          type: array
          items:
            type: string
        requestId:
          description: Request correlation identifier for support and log lookup.
          type: string
        retryable:
          description: >-
            Server advice about failure transience. `true` means transient,
            `false` means non-transient, and absence gives no advice. Automatic
            replay is allowed only when this field is not `false` and the
            operation-specific retry and idempotency contract permits replay.
          type: boolean
      additionalProperties: {}
      description: >-
        Optional structured error details. Reserved transport fields are typed;
        code-specific fields remain forward compatible.
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: A Recursion API key, created in the console under API keys.

````