> ## 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.

# Hard stop many sessions at once

> Hard-stops many sessions in one call and returns one result per session. Each session is stopped as managedAgentsCancelSessionV2 stops one, with what managedAgentsCancelSessionV2 says stops under it, but on a shorter budget: at most 20 seconds each. A session whose stop has not reached its own row by then reads failed where a single cancel might have finished; cancel that one on its own. Name the sessions in sessionIds (at most 100), or select them the way the session list does with agentId and status, or set all to true to stop every live session the session list shows you. A selection reads the rows managedAgentsListSessionsV2 returns -- the sessions the console shows -- in a live status (active or awaiting_human), so a delegated session is never selected on its own; it stops when the session that owns it is cancelled, and evaluation runs and session analyst conversations, which the list leaves out, are never selected. A teammate or sub-agent still working or waiting under a session that has already finished stops when that session is cancelled by id. At most 100 sessions are stopped per call: when hasMore is true, call again until it is false. With a selection, send the same body; when a call answers cancelledCount 0 with at least one result failed, stop repeating it: the sessions it reached are failing to stop and come first in the selection, so a repeat would spend its time on them again. A call whose results are all not_attempted may not have reached any session and is repeated, but after three such calls in a row stop and try again later: the platform is not starting stops within a call. Retry the failing ones later, and reach any other matching session by listing it with managedAgentsListSessionsV2 and naming it in sessionIds. With sessionIds, send only the ids answered not_attempted. A call with sessionIds that times out without an answer is repeated with the same body: the call answers within 75 seconds, and a stopped session stays stopped. A selection is not idempotent: it is read again on every call, so a repeat also stops sessions that started matching since the first. Repeat a timed-out selection only when stopping those newer sessions is intended; an automation that must stop exactly what it chose lists the sessions with managedAgentsListSessionsV2 and names them in sessionIds, which it can repeat. Results follow sessionIds' order, or the selection's. outcome cancelled means the session is stopped, whether now or earlier, even when stopping something under it failed and is retried by the platform; not_found means it does not exist or you may not change it; failed carries the error its cancel returned, with its code; not_attempted means the call ran out of time before it reached the session or finished stopping it, and a repeat stops it. A failed or not-attempted session leaves the others stopped. Repeating a call with sessionIds is safe: a stopped session stays stopped.



## OpenAPI

````yaml /recursion/openapi.yaml post /managed-agents/v2/sessions/bulk-cancel
openapi: 3.1.0
info:
  title: Managed Agents API
  version: 0.18.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/v2/sessions/bulk-cancel:
    post:
      tags:
        - Sessions
      summary: Hard stop many sessions at once
      description: >-
        Hard-stops many sessions in one call and returns one result per session.
        Each session is stopped as managedAgentsCancelSessionV2 stops one, with
        what managedAgentsCancelSessionV2 says stops under it, but on a shorter
        budget: at most 20 seconds each. A session whose stop has not reached
        its own row by then reads failed where a single cancel might have
        finished; cancel that one on its own. Name the sessions in sessionIds
        (at most 100), or select them the way the session list does with agentId
        and status, or set all to true to stop every live session the session
        list shows you. A selection reads the rows managedAgentsListSessionsV2
        returns -- the sessions the console shows -- in a live status (active or
        awaiting_human), so a delegated session is never selected on its own; it
        stops when the session that owns it is cancelled, and evaluation runs
        and session analyst conversations, which the list leaves out, are never
        selected. A teammate or sub-agent still working or waiting under a
        session that has already finished stops when that session is cancelled
        by id. At most 100 sessions are stopped per call: when hasMore is true,
        call again until it is false. With a selection, send the same body; when
        a call answers cancelledCount 0 with at least one result failed, stop
        repeating it: the sessions it reached are failing to stop and come first
        in the selection, so a repeat would spend its time on them again. A call
        whose results are all not_attempted may not have reached any session and
        is repeated, but after three such calls in a row stop and try again
        later: the platform is not starting stops within a call. Retry the
        failing ones later, and reach any other matching session by listing it
        with managedAgentsListSessionsV2 and naming it in sessionIds. With
        sessionIds, send only the ids answered not_attempted. A call with
        sessionIds that times out without an answer is repeated with the same
        body: the call answers within 75 seconds, and a stopped session stays
        stopped. A selection is not idempotent: it is read again on every call,
        so a repeat also stops sessions that started matching since the first.
        Repeat a timed-out selection only when stopping those newer sessions is
        intended; an automation that must stop exactly what it chose lists the
        sessions with managedAgentsListSessionsV2 and names them in sessionIds,
        which it can repeat. Results follow sessionIds' order, or the
        selection's. outcome cancelled means the session is stopped, whether now
        or earlier, even when stopping something under it failed and is retried
        by the platform; not_found means it does not exist or you may not change
        it; failed carries the error its cancel returned, with its code;
        not_attempted means the call ran out of time before it reached the
        session or finished stopping it, and a repeat stops it. A failed or
        not-attempted session leaves the others stopped. Repeating a call with
        sessionIds is safe: a stopped session stays stopped.
      operationId: managedAgentsCancelSessionsV2
      parameters:
        - $ref: '#/components/parameters/RecursionTenantId'
        - $ref: '#/components/parameters/RecursionOrganizationId'
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CancelSessionsRequest'
        required: true
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CancelSessionsResponse'
          description: Per-session results of a bulk cancel.
          headers:
            recursion-organization-id:
              $ref: '#/components/headers/RecursionOrganizationId'
            recursion-tenant-id:
              $ref: '#/components/headers/RecursionTenantId'
        '400':
          description: Bad Request.
          content:
            application/json:
              schema:
                oneOf:
                  - $ref: '#/components/schemas/ManagedAgentsApiErrorInvalidJson'
                  - $ref: '#/components/schemas/ManagedAgentsApiErrorInvalidRequest'
                discriminator:
                  propertyName: code
                  mapping:
                    invalid_json: '#/components/schemas/ManagedAgentsApiErrorInvalidJson'
                    invalid_request: '#/components/schemas/ManagedAgentsApiErrorInvalidRequest'
                x-recursion-error-codes:
                  - invalid_json
                  - invalid_request
          headers:
            recursion-organization-id:
              $ref: '#/components/headers/RecursionOrganizationId'
            recursion-tenant-id:
              $ref: '#/components/headers/RecursionTenantId'
        '401':
          description: Unauthorized.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ManagedAgentsApiErrorUnauthorized'
                x-recursion-error-codes:
                  - unauthorized
          headers:
            recursion-organization-id:
              $ref: '#/components/headers/RecursionOrganizationId'
            recursion-tenant-id:
              $ref: '#/components/headers/RecursionTenantId'
        '403':
          description: Forbidden.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ManagedAgentsApiErrorForbidden'
                x-recursion-error-codes:
                  - forbidden
          headers:
            recursion-organization-id:
              $ref: '#/components/headers/RecursionOrganizationId'
            recursion-tenant-id:
              $ref: '#/components/headers/RecursionTenantId'
        '404':
          description: Not Found.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ManagedAgentsApiErrorNotFound'
                x-recursion-error-codes:
                  - not_found
          headers:
            recursion-organization-id:
              $ref: '#/components/headers/RecursionOrganizationId'
            recursion-tenant-id:
              $ref: '#/components/headers/RecursionTenantId'
        '413':
          description: Payload Too Large.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ManagedAgentsApiErrorPayloadTooLarge'
                x-recursion-error-codes:
                  - payload_too_large
          headers:
            recursion-organization-id:
              $ref: '#/components/headers/RecursionOrganizationId'
            recursion-tenant-id:
              $ref: '#/components/headers/RecursionTenantId'
        '415':
          description: Unsupported Media Type.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ManagedAgentsApiErrorUnsupportedMediaType'
                x-recursion-error-codes:
                  - unsupported_media_type
          headers:
            recursion-organization-id:
              $ref: '#/components/headers/RecursionOrganizationId'
            recursion-tenant-id:
              $ref: '#/components/headers/RecursionTenantId'
        '429':
          headers:
            Retry-After:
              description: When to retry, as delay seconds or an HTTP date.
              schema:
                type: string
            recursion-organization-id:
              $ref: '#/components/headers/RecursionOrganizationId'
            recursion-tenant-id:
              $ref: '#/components/headers/RecursionTenantId'
          description: Too Many Requests.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ManagedAgentsApiErrorRateLimitExceeded'
                x-recursion-error-codes:
                  - rate_limit_exceeded
        '500':
          description: Internal Server Error.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ManagedAgentsApiErrorInternalError'
                x-recursion-error-codes:
                  - internal_error
          headers:
            recursion-organization-id:
              $ref: '#/components/headers/RecursionOrganizationId'
            recursion-tenant-id:
              $ref: '#/components/headers/RecursionTenantId'
        '502':
          description: A dependent service returned an invalid response.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ManagedAgentsApiErrorDependencyFailure'
                x-recursion-error-codes:
                  - bad_gateway
          headers:
            recursion-organization-id:
              $ref: '#/components/headers/RecursionOrganizationId'
            recursion-tenant-id:
              $ref: '#/components/headers/RecursionTenantId'
        '503':
          headers:
            Retry-After:
              description: When to retry, as delay seconds or an HTTP date.
              schema:
                type: string
            recursion-organization-id:
              $ref: '#/components/headers/RecursionOrganizationId'
            recursion-tenant-id:
              $ref: '#/components/headers/RecursionTenantId'
          description: Service Unavailable.
          content:
            application/json:
              schema:
                oneOf:
                  - $ref: >-
                      #/components/schemas/ManagedAgentsApiErrorManagedAgentsUnavailable
                  - $ref: >-
                      #/components/schemas/ManagedAgentsApiErrorServiceUnavailable
                discriminator:
                  propertyName: code
                  mapping:
                    managed_agents_unavailable: >-
                      #/components/schemas/ManagedAgentsApiErrorManagedAgentsUnavailable
                    service_unavailable: >-
                      #/components/schemas/ManagedAgentsApiErrorServiceUnavailable
                x-recursion-error-codes:
                  - managed_agents_unavailable
                  - service_unavailable
        '504':
          headers:
            Retry-After:
              description: When to retry, as delay seconds or an HTTP date.
              schema:
                type: string
            recursion-organization-id:
              $ref: '#/components/headers/RecursionOrganizationId'
            recursion-tenant-id:
              $ref: '#/components/headers/RecursionTenantId'
          description: A dependent service timed out.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ManagedAgentsApiErrorDependencyTimeout'
                x-recursion-error-codes:
                  - gateway_timeout
components:
  parameters:
    RecursionTenantId:
      name: x-tenant-id
      in: header
      required: false
      description: >-
        Optional tenant consistency check. When present, it must name the tenant
        bound to the API key, including when x-organization-id is `default`.
      schema:
        minLength: 1
        type: string
    RecursionOrganizationId:
      name: x-organization-id
      in: header
      required: false
      description: >-
        Organization in which to act. Required for a tenant-scoped API key.
        Optional for an organization-scoped key, where it must name that same
        organization. The value may be an organization id or `default`.
      schema:
        minLength: 1
        type: string
  schemas:
    CancelSessionsRequest:
      additionalProperties: false
      description: >-
        Which sessions to stop: sessionIds, or a selection by agentId and
        status, or all.
      properties:
        agentId:
          description: >-
            Select the live sessions of this agent that the session list shows.
            Omit for every agent.
          format: uuid
          type: string
          x-recursion-omission:
            strategy: absent
        all:
          default: false
          description: >-
            Select every live session the session list shows you: evaluation
            runs and session analyst conversations are not among them. Required
            when neither sessionIds, agentId nor status is set, so an empty body
            never stops a fleet by accident; not allowed together with them.
          type: boolean
        sessionIds:
          description: >-
            Sessions to stop, at most 100 distinct session ids as lowercase
            canonical UUIDs, as the API returns them. Any session you can see is
            accepted; each stops as managedAgentsCancelSessionV2 describes. Omit
            to select sessions with agentId, status or all instead.
          items:
            format: uuid
            pattern: ^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$
            type: string
          maxItems: 100
          minItems: 1
          type: array
          uniqueItems: true
          x-recursion-omission:
            strategy: absent
        status:
          description: >-
            Select only sessions in this live status. Omit for both active and
            awaiting_human.
          enum:
            - active
            - awaiting_human
          type: string
          x-recursion-omission:
            strategy: absent
      type: object
    CancelSessionsResponse:
      description: Per-session results of a bulk cancel.
      properties:
        cancelledCount:
          description: How many results are cancelled.
          minimum: 0
          type: integer
          maximum: 9007199254740991
        hasMore:
          description: >-
            True when sessions remain for another call: the selection matched
            more live sessions than one call stops, or some sessions were not
            attempted. The operation's description says how to repeat the call
            and when to stop.
          type: boolean
        results:
          description: >-
            One result per session, in the order of sessionIds or of the
            selection. Empty when a selection matched no live session.
          items:
            $ref: '#/components/schemas/CancelSessionsResult'
          type: array
      required:
        - results
        - cancelledCount
        - hasMore
      type: object
      additionalProperties: false
    ManagedAgentsApiErrorInvalidJson:
      type: object
      properties:
        code:
          type: string
          minLength: 1
          description: Stable machine-readable error code.
          enum:
            - invalid_json
        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.
    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.
    ManagedAgentsApiErrorNotFound:
      type: object
      properties:
        code:
          type: string
          minLength: 1
          description: Stable machine-readable error code.
          enum:
            - not_found
        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.
    ManagedAgentsApiErrorPayloadTooLarge:
      type: object
      properties:
        code:
          type: string
          minLength: 1
          description: Stable machine-readable error code.
          enum:
            - payload_too_large
        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.
    ManagedAgentsApiErrorUnsupportedMediaType:
      type: object
      properties:
        code:
          type: string
          minLength: 1
          description: Stable machine-readable error code.
          enum:
            - unsupported_media_type
        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.
    ManagedAgentsApiErrorDependencyFailure:
      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.
    ManagedAgentsApiErrorDependencyTimeout:
      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.
    CancelSessionsResult:
      properties:
        error:
          $ref: '#/components/schemas/CancelSessionsResultError'
          description: Present only when outcome is failed.
        outcome:
          description: >-
            cancelled: the session is stopped, now or earlier. not_found: it
            does not exist or you may not change it. failed: see error.
            not_attempted: the call ran out of time before it reached or
            finished this session; call again.
          enum:
            - cancelled
            - not_found
            - failed
            - not_attempted
          type: string
        sessionId:
          description: The session this result is for.
          format: uuid
          type: string
      required:
        - sessionId
        - outcome
      type: object
      additionalProperties: false
    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:
        $ref: '#/components/schemas/PlatformSafeJsonValue'
      description: >-
        Optional structured error details. Reserved transport fields are typed;
        code-specific fields remain forward compatible.
    CancelSessionsResultError:
      properties:
        code:
          description: >-
            The stable error code of the error this session's cancel returned:
            evaluation_cancellation_pending while an evaluation's cleanup
            finishes (retryable), invalid_request when the session cannot be
            cancelled as asked, such as an evaluation session after evaluations
            were turned off (not retryable), or internal_error for any other
            failure, including a conflict or a cancel the call's time cut short
            (retryable).
          enum:
            - evaluation_cancellation_pending
            - invalid_request
            - internal_error
          type: string
        message:
          description: Human-readable explanation.
          type: string
        retryable:
          description: Whether repeating the call can succeed for this session.
          type: boolean
      required:
        - code
        - message
        - retryable
      type: object
      additionalProperties: false
    PlatformSafeJsonValue:
      description: >-
        A JSON value whose integer members stay within the exact ECMAScript
        safe-integer range at every nesting level.
      oneOf:
        - type: 'null'
        - type: boolean
        - type: string
        - type: integer
          minimum: -9007199254740991
          maximum: 9007199254740991
        - type: number
          not:
            type: integer
        - type: array
          items:
            $ref: '#/components/schemas/PlatformSafeJsonValue'
        - additionalProperties:
            $ref: '#/components/schemas/PlatformSafeJsonValue'
          type: object
  headers:
    RecursionOrganizationId:
      description: Organization id resolved for this request.
      schema:
        minLength: 1
        type: string
    RecursionTenantId:
      description: Tenant id resolved for this request.
      schema:
        minLength: 1
        type: string
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: A Recursion API key, created in the console under API keys.

````