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

# Cancel Experiment Run

> Cancel an experiment run.

Identified by `run_id`. Cancels the run and any of its pending or
in-flight results, returning the run's new `cancelled` lifecycle. Returns
404 if the run does not exist or is not in a cancellable (pending, queued,
or running) state.

Cancel one pending or running experiment run by `run_id`. Cancellation is
run-specific; it no longer targets "the latest run" for an experiment.

<RequestExample>
  ```python Python theme={null}
  from retab import Retab

  client = Retab()

  run = client.workflows.experiments.runs.cancel("exprun_2")
  print(run.lifecycle.status)
  ```

  ```typescript TypeScript theme={null}
  import { Retab } from "@retab/node";

  const client = new Retab({ apiKey: process.env.RETAB_API_KEY });

  const run = await client.workflows.experiments.runs.cancel("exprun_2");
  console.log(run.lifecycle.status);
  ```

  ```go Go theme={null}
  package main

  import (
  	"context"
  	"fmt"
  	"log"

  	retab "github.com/retab-dev/retab/clients/go"
  )

  func ptr[T any](v T) *T { return &v }

  func main() {
  	ctx := context.Background()

  	client, err := retab.NewClient("")
  	if err != nil {
  		log.Fatal(err)
  	}

  	run, err := client.Workflows.Experiments.Runs.Cancel(ctx, "exprun_2")
  	if err != nil {
  		log.Fatal(err)
  	}

  	fmt.Println(run.Lifecycle.Status())
  }
  ```

  ```rust Rust theme={null}
  use retab::Retab;

  #[tokio::main]
  async fn main() -> Result<(), Box<dyn std::error::Error>> {
      let client = Retab::new(std::env::var("RETAB_API_KEY")?);

      let run = client.workflows().experiments().runs().cancel("exprun_2").await?;
      println!("{:?}", run.lifecycle);
      Ok(())
  }
  ```

  ```php PHP theme={null}
  <?php
  require 'vendor/autoload.php';

  use Retab\Client;

  $client = new Client(apiKey: getenv('RETAB_API_KEY'));

  $result = $client->workflows()->experiments()->runs()->cancel(
      runId: 'run_abc123',
  );
  print_r($result);
  ```

  ```csharp C# theme={null}
  using Retab;
  using RetabClient = Retab.Retab;

  var apiKey = Environment.GetEnvironmentVariable("RETAB_API_KEY")!;
  var client = new RetabClient(apiKey);

  var result = await client.Workflows.Experiments.Runs.CancelAsync("run_abc123");
  Console.WriteLine(result);
  ```

  ```ruby Ruby theme={null}
  require 'retab'

  client = Retab::Client.new(api_key: ENV['RETAB_API_KEY'])

  result = client.workflows.experiments.runs.cancel(run_id: 'run_abc123')
  puts result
  ```

  ```java Java theme={null}
  import com.retab.RetabClient;

  public final class Example {
    public static void main(String[] args) throws Exception {
      RetabClient client = new RetabClient(System.getenv("RETAB_API_KEY"));

      var result = client.workflows().experiments().runs().cancel("run_abc123");
      System.out.println(result);
    }
  }
  ```

  ```curl cURL theme={null}
  curl -X 'POST' \
    'https://api.retab.com/v1/workflows/experiments/runs/exprun_2/cancel' \
    -H 'Authorization: Bearer <your-api-key>'
  ```
</RequestExample>

<ResponseExample>
  ```json 200 theme={null}
  {
    "id": "exprun_2",
    "lifecycle": { "status": "cancelled" },
    "timing": {
      "created_at": "2026-05-18T10:00:00Z",
      "started_at": "2026-05-18T10:00:01Z",
      "completed_at": "2026-05-18T10:00:04Z"
    }
  }
  ```
</ResponseExample>


## OpenAPI

````yaml POST /v1/workflows/experiments/runs/{run_id}/cancel
openapi: 3.1.0
info:
  title: FastAPI
  version: 0.1.0
servers:
  - url: https://api.retab.com
security: []
paths:
  /v1/workflows/experiments/runs/{run_id}/cancel:
    post:
      tags:
        - Workflows
        - Workflow Experiments
      summary: Cancel Experiment Run
      description: >-
        Cancel an experiment run.


        Identified by `run_id`. Cancels the run and any of its pending or

        in-flight results, returning the run's new `cancelled` lifecycle.
        Returns

        404 if the run does not exist or is not in a cancellable (pending,
        queued,

        or running) state.
      operationId: cancel_experiment_run
      parameters:
        - in: path
          name: run_id
          required: true
          schema:
            type: string
            title: Run Id
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CancelWorkflowExperimentRunResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - HTTPBearer: []
components:
  schemas:
    CancelWorkflowExperimentRunResponse:
      properties:
        id:
          type: string
          title: Id
        lifecycle:
          oneOf:
            - $ref: '#/components/schemas/PendingWorkflowExperimentRun'
            - $ref: '#/components/schemas/QueuedWorkflowExperimentRun'
            - $ref: '#/components/schemas/RunningWorkflowExperimentRun'
            - $ref: '#/components/schemas/CompletedWorkflowExperimentRun'
            - $ref: '#/components/schemas/ErrorWorkflowExperimentRun'
            - $ref: '#/components/schemas/CancelledWorkflowExperimentRun'
          title: Lifecycle
          discriminator:
            propertyName: status
            mapping:
              cancelled:
                $ref: '#/components/schemas/CancelledWorkflowExperimentRun'
              completed:
                $ref: '#/components/schemas/CompletedWorkflowExperimentRun'
              error:
                $ref: '#/components/schemas/ErrorWorkflowExperimentRun'
              pending:
                $ref: '#/components/schemas/PendingWorkflowExperimentRun'
              queued:
                $ref: '#/components/schemas/QueuedWorkflowExperimentRun'
              running:
                $ref: '#/components/schemas/RunningWorkflowExperimentRun'
      type: object
      required:
        - id
        - lifecycle
      title: CancelWorkflowExperimentRunResponse
      description: >-
        Result of cancelling an experiment run: the run `id` and its resulting
        `lifecycle` state.
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
          default: []
      type: object
      title: HTTPValidationError
    PendingWorkflowExperimentRun:
      properties:
        status:
          type: string
          const: pending
          title: Status
          default: pending
      type: object
      title: PendingWorkflowExperimentRun
      description: The experiment run has been created but execution has not started.
    QueuedWorkflowExperimentRun:
      properties:
        status:
          type: string
          const: queued
          title: Status
          default: queued
      type: object
      title: QueuedWorkflowExperimentRun
      description: The experiment run is enqueued and waiting for a worker.
    RunningWorkflowExperimentRun:
      properties:
        status:
          type: string
          const: running
          title: Status
          default: running
      type: object
      title: RunningWorkflowExperimentRun
      description: The experiment run is executing.
    CompletedWorkflowExperimentRun:
      properties:
        status:
          type: string
          const: completed
          title: Status
          default: completed
      type: object
      title: CompletedWorkflowExperimentRun
      description: The experiment run finished successfully.
    ErrorWorkflowExperimentRun:
      properties:
        status:
          type: string
          const: error
          title: Status
          default: error
        message:
          type: string
          title: Message
          description: Human-readable error message
          default: (no message)
        details:
          anyOf:
            - $ref: '#/components/schemas/ErrorDetails'
            - type: 'null'
          description: Structured error context including stack trace
      type: object
      title: ErrorWorkflowExperimentRun
      description: |-
        The experiment run failed.

        Carries a human-readable `message` and a structured `details` envelope
        consumers can branch on instead of parsing free text.
    CancelledWorkflowExperimentRun:
      properties:
        status:
          type: string
          const: cancelled
          title: Status
          default: cancelled
        reason:
          anyOf:
            - type: string
            - type: 'null'
          title: Reason
          description: Human-readable reason, when known
      type: object
      title: CancelledWorkflowExperimentRun
      description: >-
        The experiment run was cancelled before reaching a natural terminal
        state.
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
        input:
          title: Input
          default: null
        ctx:
          type: object
          title: Context
          default: {}
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
    ErrorDetails:
      properties:
        message:
          anyOf:
            - type: string
            - type: 'null'
          title: Message
          description: >-
            Human-readable error message. Free-text; the structured fields below
            are the machine-readable counterpart.
        stack_trace:
          anyOf:
            - type: string
            - type: 'null'
          title: Stack Trace
          description: Full stack trace
        block_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Block Id
          description: ID of the block that failed
        block_name:
          anyOf:
            - type: string
            - type: 'null'
          title: Block Name
          description: Name/label of the block that failed
        error_code:
          anyOf:
            - type: string
            - type: 'null'
          title: Error Code
          description: Error code if available
        context:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Context
          description: Additional context about the error
      type: object
      title: ErrorDetails
      description: |-
        Detailed error information for debugging.

        Captures stack traces and context about where and why an error occurred.
  securitySchemes:
    HTTPBearer:
      type: http
      scheme: bearer

````