> ## Documentation Index
> Fetch the complete documentation index at: https://uiform-codex-generated-frontend-snippets.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Create Workflow Test Run

> Create a workflow-scoped test run.

`workflow_id` is the execution context. Optional `scope` narrows the
run to one saved test or one block; omitted scope runs all workflow tests.

Create a workflow-test run against the current workflow draft. A run can execute
one saved test, every test for one block, or every test in the workflow.

The canonical route is flat: send `workflow_id` in the request body and
optionally narrow execution with `scope`. If `scope` is omitted, every saved
test in the workflow runs.

The response is a run resource. Use its `id` with the run-id-first endpoints:
[Get Workflow Test Run](/api-reference/workflows/tests/runs/get), [List Test
Run Results](/api-reference/workflows/tests/results/list).

The request body has a workflow context and an optional scope:

* **omitted `scope`** - run every saved test in the workflow.
* **`scope.type = "single"`** - run one saved test by `test_id`.
* **`scope.type = "block"`** - run every saved test for one block by `block_id`.

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

  client = Retab()

  run = client.workflows.tests.runs.create(
      workflow_id="wf_abc123xyz",
      scope={
          "type": "single",
          "test_id": "wfnodetest_hsLEQiM61ez9Piv147MWk",
      },
  )

  print(run.id, 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.tests.runs.create("wf_abc123xyz", {
    type: "single",
    testId: "wfnodetest_hsLEQiM61ez9Piv147MWk",
  });

  console.log(run.id, 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.Tests.Runs.Create(ctx, &retab.WorkflowTestRunsCreateParams{
  		WorkflowID: "wf_abc123xyz",
  		Scope: &retab.WorkflowTestRunScope{
  			Type:   retab.WorkflowTestRunScopeTypeSingle,
  			TestID: ptr("wfnodetest_hsLEQiM61ez9Piv147MWk"),
  		},
  	})
  	if err != nil {
  		log.Fatal(err)
  	}

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

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

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

  run = client.workflow_test_runs.create(
    workflow_id: 'wf_abc123xyz',
    scope: {
      type: 'single',
      test_id: 'wfnodetest_hsLEQiM61ez9Piv147MWk',
    },
  )

  puts "#{run.id} #{run.lifecycle.status}"
  ```

  ```rust Rust theme={null}
  use retab::models::{CreateWorkflowTestRunRequest, WorkflowTestRunSingleScope};
  use retab::resources::workflow_test_runs::CreateParams;
  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().tests().runs()
          .create(CreateParams::new(CreateWorkflowTestRunRequest {
              workflow_id: "wf_abc123xyz".into(),
              scope: Some(WorkflowTestRunSingleScope {
                  type_: "single".into(),
                  test_id: "wfnodetest_hsLEQiM61ez9Piv147MWk".into(),
              }.into()),
          }))
          .await?;
      println!("{} {:?}", run.id, 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->workflowTestRuns()->create();
  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.Tests.Runs.CreateAsync(
      new WorkflowTestRunsCreateOptions
      {
          WorkflowId = "wf_abc123xyz",
          Scope = new WorkflowTestRunSingleScope
          {
              TestId = "wfnodetest_hsLEQiM61ez9Piv147MWk",
          },
      }
  );
  Console.WriteLine(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().tests().runs().create("wf_abc123", null);
      System.out.println(result);
    }
  }
  ```

  ```curl cURL theme={null}
  # Single test
  curl -X 'POST' \
    'https://api.retab.com/v1/workflows/tests/runs' \
    -H 'Content-Type: application/json' \
    -H 'Authorization: Bearer <your-api-key>' \
    -d '{
      "workflow_id": "wf_abc123xyz",
      "scope": {
        "type": "single",
        "test_id": "wfnodetest_hsLEQiM61ez9Piv147MWk"
      }
    }'

  # All tests for one block
  curl -X 'POST' \
    'https://api.retab.com/v1/workflows/tests/runs' \
    -H 'Content-Type: application/json' \
    -H 'Authorization: Bearer <your-api-key>' \
    -d '{
      "workflow_id": "wf_abc123xyz",
      "scope": { "type": "block", "block_id": "block_extract_invoice" }
    }'
  ```
</RequestExample>

<ResponseExample>
  ```json 200 theme={null}
  {
    "id": "wftestrun_q1z2",
    "workflow": {
      "workflow_id": "wf_abc123xyz",
      "version_id": "draft_2026_05_18"
    },
    "trigger": { "type": "api" },
    "lifecycle": { "status": "pending" },
    "timing": {
      "created_at": "2026-05-18T10:00:00Z",
      "started_at": null,
      "completed_at": null
    },
    "test_id": "wfnodetest_hsLEQiM61ez9Piv147MWk",
    "target": { "type": "block", "block_id": "block_extract_invoice" },
    "total_tests": 1,
    "counts": {
      "queued": 1,
      "running": 0,
      "passed": 0,
      "failed": 0,
      "blocked": 0,
      "error": 0,
      "cancelled": 0
    }
  }
  ```
</ResponseExample>


## OpenAPI

````yaml POST /v1/workflows/tests/runs
openapi: 3.1.0
info:
  title: FastAPI
  version: 0.1.0
servers:
  - url: https://api.retab.com
security: []
paths:
  /v1/workflows/tests/runs:
    post:
      tags:
        - Workflows
        - Workflow Block Tests
      summary: Create Test Run
      description: >-
        Create a workflow-scoped test run.


        `workflow_id` is the execution context. Optional `scope` narrows the

        run to one saved test or one block; omitted scope runs all workflow
        tests.
      operationId: create_test_run
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateWorkflowTestRunRequest'
        required: true
      responses:
        '202':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/WorkflowTestRun'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - HTTPBearer: []
components:
  schemas:
    CreateWorkflowTestRunRequest:
      properties:
        workflow_id:
          type: string
          title: Workflow Id
        scope:
          anyOf:
            - oneOf:
                - $ref: '#/components/schemas/WorkflowTestRunSingleScope'
                - $ref: '#/components/schemas/WorkflowTestRunWorkflowScope'
                - $ref: '#/components/schemas/WorkflowTestRunBlockScope'
              discriminator:
                propertyName: type
                mapping:
                  block:
                    $ref: '#/components/schemas/WorkflowTestRunBlockScope'
                  single:
                    $ref: '#/components/schemas/WorkflowTestRunSingleScope'
                  workflow:
                    $ref: '#/components/schemas/WorkflowTestRunWorkflowScope'
            - type: 'null'
          title: Scope
          description: >-
            Optional execution scope. Omit (or pass null) to run every saved
            test in the workflow.
      additionalProperties: false
      type: object
      required:
        - workflow_id
      title: CreateWorkflowTestRunRequest
      description: >-
        Create a workflow test run. Provide a `workflow_id`, and optionally
        narrow execution with `scope` to a single test or one block. Omit
        `scope` to run every saved workflow test.
    WorkflowTestRun:
      properties:
        id:
          type: string
          title: Id
        workflow_id:
          type: string
          title: Workflow Id
        workflow_version_id:
          type: string
          title: Workflow Version Id
        trigger:
          $ref: '#/components/schemas/TriggerInfo'
        lifecycle:
          oneOf:
            - $ref: '#/components/schemas/PendingWorkflowTestRun'
            - $ref: '#/components/schemas/QueuedWorkflowTestRun'
            - $ref: '#/components/schemas/RunningWorkflowTestRun'
            - $ref: '#/components/schemas/CompletedWorkflowTestRun'
            - $ref: '#/components/schemas/ErrorWorkflowTestRun'
            - $ref: '#/components/schemas/CancelledWorkflowTestRun'
          title: Lifecycle
          discriminator:
            propertyName: status
            mapping:
              cancelled:
                $ref: '#/components/schemas/CancelledWorkflowTestRun'
              completed:
                $ref: '#/components/schemas/CompletedWorkflowTestRun'
              error:
                $ref: '#/components/schemas/ErrorWorkflowTestRun'
              pending:
                $ref: '#/components/schemas/PendingWorkflowTestRun'
              queued:
                $ref: '#/components/schemas/QueuedWorkflowTestRun'
              running:
                $ref: '#/components/schemas/RunningWorkflowTestRun'
        timing:
          $ref: '#/components/schemas/WorkflowTestRunTiming'
        target:
          anyOf:
            - $ref: '#/components/schemas/WorkflowTestBlockTarget'
            - type: 'null'
        test_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Test Id
        total_tests:
          type: integer
          title: Total Tests
        counts:
          $ref: '#/components/schemas/BlockTestBatchExecutionCounts'
          default:
            lifecycle_counts:
              cancelled: 0
              completed: 0
              error: 0
              pending: 0
              queued: 0
              running: 0
            outcome:
              blocked: 0
              failed: 0
              passed: 0
        freshness:
          $ref: '#/components/schemas/ArtifactFreshness'
      type: object
      required:
        - id
        - lifecycle
        - timing
        - total_tests
        - trigger
        - workflow_id
        - workflow_version_id
      title: WorkflowTestRun
      description: >-
        A batch execution of a workflow's tests, with overall `lifecycle`,
        `timing`, and pass/fail `counts`.
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
          default: []
      type: object
      title: HTTPValidationError
    WorkflowTestRunSingleScope:
      properties:
        type:
          type: string
          const: single
          title: Type
        test_id:
          type: string
          title: Test Id
      type: object
      required:
        - test_id
        - type
      title: WorkflowTestRunSingleScope
      description: Run one saved workflow test in the workflow.
    WorkflowTestRunWorkflowScope:
      properties:
        type:
          type: string
          const: workflow
          title: Type
      type: object
      required:
        - type
      title: WorkflowTestRunWorkflowScope
      description: Run every saved test in the workflow.
    WorkflowTestRunBlockScope:
      properties:
        type:
          type: string
          const: block
          title: Type
        block_id:
          type: string
          title: Block Id
      type: object
      required:
        - block_id
        - type
      title: WorkflowTestRunBlockScope
      description: Run every workflow test for one block in the workflow.
    TriggerInfo:
      properties:
        type:
          type: string
          enum:
            - manual
            - api
            - schedule
            - webhook
            - email
            - custom
            - restart
          title: Type
          description: What started this run
      type: object
      required:
        - type
      title: TriggerInfo
      description: |-
        Public summary of what started a run: just the trigger category.

        The full per-variant detail (schedule_id, parent_run_id, sender, ...) is
        kept internally on `StoredWorkflowRun.trigger` but intentionally not
        exposed in the public API surface.
    PendingWorkflowTestRun:
      properties:
        status:
          type: string
          const: pending
          title: Status
          default: pending
      type: object
      title: PendingWorkflowTestRun
      description: The test run has been created but execution has not started.
    QueuedWorkflowTestRun:
      properties:
        status:
          type: string
          const: queued
          title: Status
          default: queued
      type: object
      title: QueuedWorkflowTestRun
      description: The test run is enqueued and waiting for a worker.
    RunningWorkflowTestRun:
      properties:
        status:
          type: string
          const: running
          title: Status
          default: running
      type: object
      title: RunningWorkflowTestRun
      description: The test run is executing assertions.
    CompletedWorkflowTestRun:
      properties:
        status:
          type: string
          const: completed
          title: Status
          default: completed
      type: object
      title: CompletedWorkflowTestRun
      description: The test run finished. Per-test verdicts live on each result row.
    ErrorWorkflowTestRun:
      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: ErrorWorkflowTestRun
      description: |-
        The test run failed. The error message lives on this variant.

        Carries the same structured `details` envelope as workflow runs so
        consumers can branch on `error_code` / `stage` rather than parsing
        a free-text message.
    CancelledWorkflowTestRun:
      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: CancelledWorkflowTestRun
      description: The test run was cancelled before reaching a natural terminal state.
    WorkflowTestRunTiming:
      properties:
        created_at:
          type: string
          format: date-time
          title: Created At
          description: When the workflow-test run was created.
        started_at:
          anyOf:
            - type: string
              format: date-time
            - type: 'null'
          title: Started At
        completed_at:
          anyOf:
            - type: string
              format: date-time
            - type: 'null'
          title: Completed At
        duration_ms:
          anyOf:
            - type: integer
            - type: 'null'
          title: Duration Ms
      type: object
      title: WorkflowTestRunTiming
    WorkflowTestBlockTarget:
      properties:
        type:
          type: string
          const: block
          title: Type
          default: block
        block_id:
          type: string
          title: Block Id
      type: object
      required:
        - block_id
      title: WorkflowTestBlockTarget
      description: >-
        Public workflow-test target.


        The storage layer remains block-scoped today, but the API shape names
        the

        tested entity explicitly so workflow-level targets can be added later.
    BlockTestBatchExecutionCounts:
      properties:
        lifecycle_counts:
          $ref: '#/components/schemas/BlockTestLifecycleCounts'
          default:
            pending: 0
            queued: 0
            running: 0
            completed: 0
            error: 0
            cancelled: 0
        outcome:
          $ref: '#/components/schemas/BlockTestOutcomeCounts'
          default:
            passed: 0
            failed: 0
            blocked: 0
      type: object
      title: BlockTestBatchExecutionCounts
      description: |-
        Aggregate counts for a batch of block-test runs.

        Each individual run contributes to exactly one `lifecycle_counts`
        bucket, and additionally to one `outcome` bucket when
        `lifecycle_counts.completed` is incremented.
    ArtifactFreshness:
      properties:
        status:
          type: string
          enum:
            - fresh
            - stale
            - unknown
          title: Status
          default: unknown
        reasons:
          items:
            type: string
            enum:
              - validity_changed
              - inputs_changed
              - engine_changed
              - metrics_engine_changed
              - no_baseline
          type: array
          title: Reasons
          default: []
        validity_fingerprint:
          anyOf:
            - type: string
            - type: 'null'
          title: Validity Fingerprint
        input_fingerprint:
          anyOf:
            - type: string
            - type: 'null'
          title: Input Fingerprint
        baseline_run_id:
          anyOf:
            - type: string
            - type: 'null'
          title: Baseline Run Id
      type: object
      title: ArtifactFreshness
    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.
    BlockTestLifecycleCounts:
      properties:
        pending:
          type: integer
          title: Pending
          default: 0
        queued:
          type: integer
          title: Queued
          default: 0
        running:
          type: integer
          title: Running
          default: 0
        completed:
          type: integer
          title: Completed
          default: 0
        error:
          type: integer
          title: Error
          default: 0
        cancelled:
          type: integer
          title: Cancelled
          default: 0
      type: object
      title: BlockTestLifecycleCounts
      description: Per-lifecycle counts for a batch of block-test runs.
    BlockTestOutcomeCounts:
      properties:
        passed:
          type: integer
          title: Passed
          default: 0
        failed:
          type: integer
          title: Failed
          default: 0
        blocked:
          type: integer
          title: Blocked
          default: 0
      type: object
      title: BlockTestOutcomeCounts
      description: Per-outcome counts. Only completed runs contribute to these buckets.
  securitySchemes:
    HTTPBearer:
      type: http
      scheme: bearer

````