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

# Trigger a test run

> Triggers a new end-to-end test run for the scoped project, optionally with a saved environment, resolving the branch/build and dispatching the run.



## OpenAPI

````yaml /api-reference/openapi.generated.json put /api/test-runs
openapi: 3.1.0
info:
  title: Empirical API
  version: 1.0.0
  description: Programmatic access to Empirical test runs, snoozes, and more.
  contact:
    name: Empirical
    url: https://empirical.run
servers:
  - url: https://api.empirical.run
security:
  - Bearer: []
tags:
  - name: Test Runs
    description: Trigger, list, and inspect end-to-end test runs.
  - name: Test Cases
    description: >-
      Browse the Playwright test cases synced from a project's repository and
      manage their tags.
  - name: Environments
    description: >-
      Named deployment targets (slug + Playwright project filters) a project's
      tests run against.
  - name: Snoozes
    description: Temporarily suppress known test failures for specific Playwright tests.
  - name: KV
    description: >-
      Project-scoped key-value store shared by test runs, shards and agent
      sessions. Every entry expires; conditional writes make it safe for locks.
  - name: Analytics
    description: Aggregated test-run, test-count and test-case analytics for a project.
  - name: Allowed recipients
    description: >-
      Domains and addresses a project's inboxes may send email to, besides
      @empiricalrun.email addresses and people who emailed the inbox. Each one
      is verified in one of two ways. **Email from it**: send an email from the
      domain (any mailbox on it) or from the exact address to the verification
      address, with the verification code in the subject. It must pass DMARC.
      **Emailed code**, for addresses that can't send (e.g.
      `support@acme.zendesk.com`): we email the address a 6-digit code, and you
      enter it from wherever that address delivers. A domain covers exactly that
      domain, not its subdomains; add a subdomain such as `inbound.acme.com` on
      its own, and an email from `@acme.com` verifies it. Public mail providers
      (gmail.com, outlook.com and similar) can't be added as domains; add the
      exact address instead. An address also covers its plus-variants. Domains
      reserved for examples and tests (example.com, example.net, example.org,
      and anything under .test, .example, .invalid or .localhost) can't receive
      email, so codes are never emailed to them.
  - name: Badges
    description: Public README status badge images (SVG) for project environments.
  - name: Files
    description: >-
      Upload files of any type and get a link to use in tasks, sessions and
      messages. Agents should use the `upload_file` tool, which returns a
      project-wide `file@<id>` handle (`<id>` is the file `id` below).
  - name: Inboxes
    description: >-
      Test email addresses on @empiricalrun.email that a project claims. Only
      the claiming project can read an inbox, and only mail received after the
      claim. Typical flow: claim an address, sign up or log in to your app with
      it, then list the inbox's messages. Inboxes can also send mail, e.g. to
      test an app that processes inbound email: to @empiricalrun.email
      addresses, to anyone who emailed the inbox, and to the project's allowed
      recipients. Replies land back in the sending inbox.
  - name: Infra
    description: >-
      Infrastructure details customers configure against, such as static egress
      IPs.
  - name: Reporter Configuration
    description: Reporters a project can use in environment and run reporter configs.
  - name: Webhook Captures
    description: >-
      Throwaway URLs that record every request sent to them, for testing
      webhooks your app sends.
paths:
  /api/test-runs:
    put:
      tags:
        - Test Runs
      summary: Trigger a test run
      description: >-
        Triggers a new end-to-end test run for the scoped project, optionally
        with a saved environment, resolving the branch/build and dispatching the
        run.
      operationId: createTestRun
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/TriggerTestRunRequest'
      responses:
        '200':
          description: The triggered test run.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CreateTestRunResponse'
        '400':
          description: >-
            Invalid request, unknown environment, or the project could not be
            resolved.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '402':
          description: >-
            Billing blocked: an overdue invoice, a failed renewal, no active
            plan, or the spend limit reached.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '404':
          description: Project not found or not accessible.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
components:
  schemas:
    TriggerTestRunRequest:
      type: object
      properties:
        environment:
          type: string
          description: >-
            Slug of a saved environment to run with (e.g., `production`,
            `staging`). Optional: without it the run uses only the project's
            variables and the config sent on this request.
        build:
          type: object
          properties:
            branch:
              type: string
              description: Git branch name of the build.
            commit:
              type: string
              description: Git commit SHA of the build.
            repo:
              type: string
              pattern: ^[^\s/]+\/[^\s/]+$
              description: Source repository in owner/name format (e.g., acme/web).
          description: Build information to associate with the test run.
        metadata:
          type: object
          additionalProperties:
            anyOf:
              - type: string
              - type: number
          description: >-
            Custom key-value pairs to associate with the test run. Values must
            be strings or numbers.
        environment_variables_overrides:
          type: array
          items:
            type: object
            properties:
              name:
                type: string
                description: Name of the environment variable.
              value:
                type: string
                description: Value of the environment variable.
            required:
              - name
              - value
          description: Environment variables to override for this test run.
        playwright_projects_match:
          type: array
          items:
            type: string
            pattern: ^[^!]
          description: >-
            Glob patterns of the Playwright projects to run (e.g. `chromium*`).
            Empty means every project. Omit to use the environment's
            `playwright_projects_match`; send `[]` for none.
        playwright_projects_ignore:
          type: array
          items:
            type: string
            pattern: ^[^!]
          description: >-
            Glob patterns of the Playwright projects to skip, applied after
            `playwright_projects_match`. Omit to use the environment's
            `playwright_projects_ignore`; send `[]` for none.
        tags:
          type: array
          items:
            type: string
          description: >-
            Tags selecting the tests to run (e.g. `@smoke`); a missing `@` is
            added. A test runs when one of its tags contains any of them, so
            `smoke` also selects `@smoke-nightly`. A test title is not a tag:
            `checkout flow` matches no test. To run specific tests, use
            `test_case_ids`. Omit to use the environment's `tags`; send `[]` for
            none.
        exclude_tags:
          type: array
          items:
            type: string
          description: >-
            Tags whose tests are skipped (e.g. `@slow`). Applied after every
            other selection, so it can only remove tests: with `tags` it runs
            tests matching `tags` but not `exclude_tags`; alone it runs every
            test except the excluded ones. Omit to use the environment's
            `exclude_tags`; send `[]` for none.
        test_case_ids:
          type: array
          items:
            type: string
            pattern: ^[0-9a-f]{20}-[0-9a-f]{20}
          description: >-
            Specific test case ids (Playwright per-project `test.id`, e.g.
            `1bd02eced4141fc31282-084163cf0ce372bd31e7`) to run. Only these
            tests will be executed.
        branch:
          type: string
          description: >-
            Existing test-repository branch to run. A missing explicit branch
            creates an errored run; Empirical never creates it. May be supplied
            alongside `build`, which describes the application code under test.
        trigger:
          type: object
          properties:
            event:
              type: string
              enum:
                - pull_request
              description: Event that produced the run.
            pull_request:
              type: object
              properties:
                number:
                  type: integer
                  minimum: 1
                  description: Pull request number in the application repository.
                head:
                  type: string
                  minLength: 1
                  description: Head branch.
                base:
                  type: string
                  minLength: 1
                  description: Base branch.
              required:
                - head
                - base
              additionalProperties: false
              description: Pull request under test.
          required:
            - event
            - pull_request
          additionalProperties: false
          description: >-
            The application pull request under test, for pre-merge runs. The run
            uses the test-repository branch named `pull_request.head`, merged
            into the project default branch. If no such branch exists, it uses
            the default branch. An explicit `branch` takes precedence.
        concurrency:
          type: object
          nullable: true
          properties:
            group:
              type: string
              minLength: 1
              maxLength: 512
              description: >-
                Free-form group key, scoped to the project, e.g. `production`,
                `staging/acme/web@feat-x`, or a build URL.
            on_conflict:
              type: string
              enum:
                - cancel
                - wait
              description: >-
                `cancel`: cancel the group's in-progress and waiting runs, then
                start. `wait`: queue behind the in-progress run; a newer waiting
                run replaces this one.
          required:
            - group
            - on_conflict
          description: >-
            Concurrency group and policy for this run. Runs in the same group
            (within the project) are limited to one in progress; `on_conflict`
            says what this run does when the group already has an active run:
            `cancel` cancels it and starts now, `wait` queues behind it (a newer
            waiting run replaces an older one). Omit to use the project's legacy
            concurrency setting; `null` for no limit.
        reporters:
          type: array
          items:
            oneOf:
              - type: object
                properties:
                  reporter_type:
                    type: string
                    enum:
                      - slack_run_status
                    description: Posts run status updates to Slack channels.
                  slack_channels:
                    type: array
                    items:
                      type: string
                      minLength: 1
                    minItems: 1
                    description: >-
                      Slack channel ids (`C…`), as shown in Slack's channel
                      details. Shared (Slack Connect) channels have the same id
                      in every workspace. Each must be a registered, unarchived
                      channel of the project's organization.
                  slack_channel_ids:
                    type: array
                    items:
                      type: integer
                      minimum: 1
                    minItems: 1
                    description: >-
                      Registered Slack channel ids from `GET
                      /api/v2/slack/channels` (the numeric `id`). Can be
                      combined with `slack_channels`.
                required:
                  - reporter_type
                additionalProperties: false
              - type: object
                properties:
                  reporter_type:
                    type: string
                    enum:
                      - github_check
                    description: >-
                      Posts a GitHub check run on the build commit. Needs
                      `build` with a repository the GitHub Reporter app is
                      installed on.
                required:
                  - reporter_type
                additionalProperties: false
              - type: object
                properties:
                  reporter_type:
                    type: string
                    enum:
                      - github_pr_comment
                    description: >-
                      Posts (and updates) a comment on the pull request for the
                      build branch. Needs `build` with a repository the GitHub
                      Reporter app is installed on.
                required:
                  - reporter_type
                additionalProperties: false
              - type: object
                properties:
                  reporter_type:
                    type: string
                    enum:
                      - github_linked_changes
                    description: >-
                      Tracks the test branch named after the head branch of the
                      app pull request the run was triggered for
                      (`trigger.event` `pull_request`), and keeps the `Empirical
                      linked test changes` check on that pull request up to
                      date: it passes when the test branch has nothing left to
                      merge and fails while it has unmerged commits. The pull
                      request's latest run decides whether it is tracked. Does
                      nothing for runs not triggered by a pull request. Needs
                      `build` with a repository the GitHub Reporter app is
                      installed on.
                required:
                  - reporter_type
                additionalProperties: false
              - type: object
                properties:
                  reporter_type:
                    type: string
                    enum:
                      - email_run_report
                    description: >-
                      Emails a report when the run ends to every user whose
                      email domain is one of the organization's email domains.
                required:
                  - reporter_type
                additionalProperties: false
              - type: object
                properties:
                  reporter_type:
                    type: string
                    enum:
                      - slack_creator_dm
                    description: >-
                      Sends a Slack DM to whoever started the run (from the
                      dashboard, the CLI or an agent session) when it ends, if
                      their Slack account is linked. Runs triggered with a
                      project API key have no one to DM.
                required:
                  - reporter_type
                additionalProperties: false
          description: >-
            Reporters for this run, saved on the run when it is created; at most
            one entry per `reporter_type`. Omit to use the environment's
            `reporter_config` (a run without an environment then gets none). A
            list replaces those defaults: reporters not listed do not fire, and
            `[]` turns them all off. Without `reporters`, a run started by a
            person (dashboard, CLI or agent session) also gets
            `slack_creator_dm`; a list sends the DM only if it names
            `slack_creator_dm`. Invalid entries (unknown Slack channels,
            duplicate types) reject the request without creating a run.
        rerun_source_id:
          type: integer
          minimum: 1
          description: ID of the test run this run is a rerun of.
        rerun_only_failed:
          type: boolean
          description: When rerunning, only re-execute the previously failed tests.
      additionalProperties: false
    CreateTestRunResponse:
      type: object
      properties:
        data:
          type: object
          properties:
            trigger:
              type: object
              properties:
                success:
                  type: boolean
                  description: Whether the test run was triggered successfully.
              required:
                - success
            test_run:
              type: object
              properties:
                id:
                  type: number
                  description: Unique identifier for the test run.
                state:
                  type: string
                  description: Current state of the test run.
                error_code:
                  type: string
                  nullable: true
                  description: >-
                    Normalized error code when branch resolution or execution
                    failed.
                test_run_branch:
                  type: string
                  description: Git branch being tested.
                created_at:
                  type: string
                  description: ISO 8601 timestamp when the run was created.
                concurrency:
                  type: object
                  nullable: true
                  properties:
                    group:
                      type: string
                      description: >-
                        Concurrency group the run was scoped to. Runs in the
                        same group are limited to one in progress at a time.
                    on_conflict:
                      type: string
                      enum:
                        - cancel
                        - wait
                      description: >-
                        What this run did when the group already had an active
                        run: `cancel` cancelled it, `wait` held this run in
                        `pending` until the group was free.
                  required:
                    - group
                    - on_conflict
                  description: >-
                    Concurrency group and policy the run was created with, or
                    null when no limit applied.
                test_code:
                  type: object
                  nullable: true
                  properties:
                    requested:
                      type: object
                      properties:
                        branch:
                          type: string
                        source:
                          type: string
                          enum:
                            - explicit
                            - build
                            - project_default
                            - legacy
                        if_missing:
                          type: string
                          enum:
                            - error
                            - use_default
                            - create
                      required:
                        - branch
                        - source
                        - if_missing
                    resolved:
                      type: object
                      properties:
                        branch:
                          type: string
                          nullable: true
                        sha:
                          type: string
                          nullable: true
                        fallback_reason:
                          type: string
                          nullable: true
                          enum:
                            - requested_branch_missing
                      required:
                        - branch
                        - sha
                        - fallback_reason
                    execution:
                      type: object
                      properties:
                        ref:
                          type: string
                          nullable: true
                        sha:
                          type: string
                          nullable: true
                        ref_kind:
                          type: string
                          nullable: true
                          enum:
                            - branch
                            - temporary_merge
                      required:
                        - ref
                        - sha
                        - ref_kind
                    merge_base:
                      type: object
                      nullable: true
                      properties:
                        branch:
                          type: string
                        sha:
                          type: string
                          nullable: true
                      required:
                        - branch
                        - sha
                    resolution_status:
                      type: string
                      enum:
                        - pending
                        - resolved
                        - branch_missing
                        - merge_conflict
                        - provider_error
                    resolution_error_code:
                      type: string
                      nullable: true
                  required:
                    - requested
                    - resolved
                    - execution
                    - merge_base
                    - resolution_status
                    - resolution_error_code
                  description: Requested, resolved, and executed test-repository code.
                trigger:
                  type: object
                  nullable: true
                  properties:
                    event:
                      type: string
                      enum:
                        - pull_request
                      description: Event that produced the run.
                    pull_request:
                      type: object
                      properties:
                        number:
                          type: integer
                          minimum: 1
                          description: Pull request number in the application repository.
                        head:
                          type: string
                          minLength: 1
                          description: Head branch.
                        base:
                          type: string
                          minLength: 1
                          description: Base branch.
                      required:
                        - head
                        - base
                      additionalProperties: false
                      description: Pull request under test.
                  required:
                    - event
                    - pull_request
                  additionalProperties: false
                  description: >-
                    The `trigger` the run was created with, or null when none
                    was sent.
              required:
                - id
                - state
                - error_code
                - test_run_branch
                - created_at
                - concurrency
                - test_code
                - trigger
          required:
            - trigger
            - test_run
      required:
        - data
    ErrorResponse:
      type: object
      properties:
        data:
          nullable: true
          description: Always null for error responses.
        error:
          type: object
          properties:
            message:
              type: string
              description: Human-readable error message.
          required:
            - message
          description: Error details.
      required:
        - data
        - error
  securitySchemes:
    Bearer:
      type: http
      scheme: bearer

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.