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

# Cancel a run

> Durably requests cancellation of a run. The response remains `cancelling` until the owning worker acknowledges the signal or its execution lease expires. Repeating the request is idempotent. Closing a client connection does not cancel a run, and cancellation does not roll back external effects that already completed. Only the API key that started the run may cancel it.



## OpenAPI

````yaml /openapi/public-api.yaml post /v1/public/runs/{runId}/cancel
openapi: 3.1.0
info:
  title: Erstan Public Agent API
  version: 1.2.0
  description: >-
    Start published Erstan agents from external systems and poll for results.
    API keys carry scopes (`agents:list`, `agents:read`, `agents:write`,
    `agents:run`, `runs:read`, `tasks:execute`, `documents:read`,
    `documents:write`, `files:read`, `files:write`). Agent access follows the
    key creator's current workspace and team permissions. Project and team
    allowlists (`allowedProjectIds`, `allowedTeamIds`) further restrict task and
    document and file access. Agent draft authoring and task/document/file tools
    are exposed through the MCP server at `/v1/mcp` rather than REST routes.
servers:
  - url: https://api.erstan.com
    description: Public endpoint
security:
  - PublicApiKey: []
tags:
  - name: Agents
    description: >-
      Discover and run published agents available to the key creator under their
      current permissions.
  - name: Runs
    description: Read run status and results.
  - name: MCP
    description: >-
      Model Context Protocol server for external clients. Agent Builder tools
      use `agents:read`, `agents:write`, or both, plus the key creator's live
      Erstan permissions. Task and content tools also apply project/team
      allowlists.
paths:
  /v1/public/runs/{runId}/cancel:
    post:
      tags:
        - Runs
      summary: Cancel a run
      description: >-
        Durably requests cancellation of a run. The response remains
        `cancelling` until the owning worker acknowledges the signal or its
        execution lease expires. Repeating the request is idempotent. Closing a
        client connection does not cancel a run, and cancellation does not roll
        back external effects that already completed. Only the API key that
        started the run may cancel it.
      operationId: cancelPublicRun
      parameters:
        - name: runId
          in: path
          required: true
          description: Run ID returned by `POST /v1/public/agents/{agentId}/runs`.
          schema:
            type: string
            format: uuid
      responses:
        '200':
          description: >-
            Cancellation state, including idempotency and acknowledgement
            timestamps.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RunCancellationResponse'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
      security:
        - PublicApiKey: []
components:
  schemas:
    RunCancellationResponse:
      type: object
      additionalProperties: false
      required:
        - runId
        - agentId
        - status
        - alreadyTerminal
        - alreadyRequested
        - cancelRequestedAt
        - cancelledAt
      properties:
        runId:
          type: string
          format: uuid
        agentId:
          type: string
        status:
          type: string
          enum:
            - cancelling
            - cancelled
            - completed
            - failed
        alreadyTerminal:
          type: boolean
        alreadyRequested:
          type: boolean
        cancelRequestedAt:
          type:
            - string
            - 'null'
          format: date-time
        cancelledAt:
          type:
            - string
            - 'null'
          format: date-time
    ErrorResponse:
      type: object
      required:
        - error
      properties:
        error:
          type: object
          required:
            - code
            - message
          properties:
            code:
              type: string
            message:
              type: string
            details:
              type: array
              items:
                $ref: '#/components/schemas/ErrorDetail'
            requestId:
              type: string
    ErrorDetail:
      type: object
      required:
        - code
        - message
      properties:
        field:
          type: string
        code:
          type: string
        message:
          type: string
  responses:
    Unauthorized:
      description: Missing, invalid, expired, revoked, or inactive API key.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    Forbidden:
      description: >-
        The API key lacks scope or the creator lacks current permission for the
        requested operation.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    NotFound:
      description: The requested agent or run was not found.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
  securitySchemes:
    PublicApiKey:
      type: http
      scheme: bearer
      bearerFormat: ers_live API key
      description: >-
        Workspace API key created in Erstan Settings. Keys carry scopes
        (`agents:list`, `agents:read`, `agents:write`, `agents:run`,
        `runs:read`, `tasks:execute`, `documents:read`, `documents:write`,
        `files:read`, `files:write`). Agent access follows the key creator's
        current workspace, team, and agent permissions. Agent draft creation
        requires `agents:write`; update, validation, and publishing require both
        `agents:read` and `agents:write`; draft testing also requires
        `agents:run`. Keys with `tasks:execute` must include at least one
        allowed project or team (`allowedProjectIds` / `allowedTeamIds`); keys
        with document or file scopes must include at least one allowed team.
        Empty allowlists mean no access — the API fails closed.

````