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

# Start a preview of a work item's pull request

> Starts a running copy of the item's open pull request, at its head commit, in a managed sandbox. A runner takes the preview, runs the repository's setup and seed commands and reports it ready. An item that has a running preview gets that preview with `joined: true`, and no second sandbox starts. A ready preview that runs an older commit than the pull request head is stopped, and a new preview starts at the head. The repository declares its preview in the `preview` block of its proofs file. `preview_not_offered` (409, with `reason`: `no_pull_request`, `pull_request_from_fork`, `no_preview_declared`, `no_matching_file` or `proofs_invalid`) means the item gets none. `preview_needs_managed_sandboxes` (409) means the gateway provides no managed sandboxes. A preview counts against the managed build-hours of the organization, as a build does: `billing_read_only` (402) for an organization that is read-only, and `managed_build_held` (409, with `reason`: `trial_hours_used`, `spending_cap_reached`, `at_limit` or `unavailable`) for a hold. A hold is recorded as a failed preview, so the item page shows the reason.



## OpenAPI

````yaml /openapi.yaml post /v1/work-items/{workItemId}/preview
openapi: 3.0.3
info:
  contact:
    email: hello@outerlayer.ai
    url: https://www.outerlayer.ai
  description: >-
    The OuterLayer Gateway API lets you ingest coding-agent sessions and record
    evidence of work programmatically.


    Most teams reach it through the `outerlayer` CLI, which calls it for them.

    Call it directly to build your own integration or to automate what the
    dashboard does.


    Versioning: every endpoint is prefixed with `/v1/`. Breaking changes ship
    under a new version prefix (`/v2/`, etc.) with a 90-day-minimum deprecation
    window; anything additive lands on the current prefix.


    Vocabulary: the dashboard calls this API's `app` a **factory** — the unit
    that owns a set of repositories, the agent sessions worked on them, and the
    evidence they produce. They are the same entity. The API keeps `app` in its
    paths, headers, and field names because those are a published contract; only
    the product surface was renamed.
  title: OuterLayer Gateway API
  version: '1.0'
servers:
  - description: Production (OuterLayer Cloud)
    url: https://api.outerlayer.ai
  - description: Local dev server (self-hosted gateway)
    url: http://localhost:9418
security:
  - AppId: []
    BearerAuth: []
tags:
  - description: >-
      What a CLI login token can read about its owner without naming a factory,
      such as the factories they can use.
    name: Account
  - description: >-
      Coding-agent session ingest (outerlayer sync) and content-addressed
      session images.
    name: Agents
  - description: >-
      Evidence artifacts (screenshots, recordings, reports, logs) emitted as
      proof of a change and anchored to pull requests.
    name: Artifacts
  - description: >-
      Pass or fail results of a judge or a code review, which a runner records
      on a work item.
    name: Emitted Results
  - description: >-
      What a build of a child item leaves for the other children of its plan:
      what it changed, what they must follow and where it differed from the
      spec.
    name: Plan notes
  - description: >-
      The acceptance criteria of a work item, recorded as one list. The Criteria
      tab, its count and the item status read that list.
    name: Criteria
  - description: >-
      What any agent found wrong about a change under review or about a rule it
      ran on, recorded on a work item.
    name: Findings
  - description: >-
      Find, file and edit the issue a spec lives in, through OuterLayer, with no
      tracker credential on the caller's side.
    name: Specs
  - description: >-
      Add or remove a source's statement that it is working on an issue or pull
      request, and read what is currently live.
    name: Work Items
  - description: >-
      What the factory's GitHub App installation lets builds do on each
      connected repository, and whether each default branch requires a pull
      request.
    name: Repositories
  - description: >-
      The runs of a schedule automation: a runner claims a run, asks for its
      read token and ends it, and the run's agent reports each issue it found or
      that it found nothing.
    name: Schedule runs
  - description: >-
      A runner host's heartbeat — its CLI version, slots and last request for
      work — and the factory's list of hosts with a derived status.
    name: Hosts
  - description: Query server feature availability.
    name: Capabilities
  - description: Per-model LLM pricing data. Public, unauthenticated.
    name: Pricing
  - description: >-
      Create, list, and revoke factory API keys. Plaintext returned exactly once
      at creation.
    name: API Keys
  - description: >-
      Factory CRUD — a factory is owned by an organization and is the unit every
      other resource hangs off. Lets a headless agent provision one without the
      dashboard.
    name: Apps
  - description: >-
      Agent-coding session list and full transcript reads, with actor-privacy
      controls for machine keys.
    name: Sessions
  - description: >-
      Per-model token spend and fleet-wide agent behavior tiles, including
      two-window comparisons.
    name: Metrics
  - description: Synced-commit history of the app's `.outerlayer/` context tree.
    name: Context
  - description: >-
      Session→PR attribution: which agent sessions produced which pull requests,
      and what each attributed PR cost.
    name: PRs
  - description: Service health checks.
    name: Health
  - description: >-
      Org member and role administration, authenticated with an org-scoped
      management API key (`olk_…`) minted in the dashboard's settings.
    name: Org Management
  - description: OAuth 2.1 discovery metadata for MCP connector clients.
    name: OAuth
paths:
  /v1/work-items/{workItemId}/preview:
    post:
      tags:
        - Work Items
      summary: Start a preview of a work item's pull request
      description: >-
        Starts a running copy of the item's open pull request, at its head
        commit, in a managed sandbox. A runner takes the preview, runs the
        repository's setup and seed commands and reports it ready. An item that
        has a running preview gets that preview with `joined: true`, and no
        second sandbox starts. A ready preview that runs an older commit than
        the pull request head is stopped, and a new preview starts at the head.
        The repository declares its preview in the `preview` block of its proofs
        file. `preview_not_offered` (409, with `reason`: `no_pull_request`,
        `pull_request_from_fork`, `no_preview_declared`, `no_matching_file` or
        `proofs_invalid`) means the item gets none.
        `preview_needs_managed_sandboxes` (409) means the gateway provides no
        managed sandboxes. A preview counts against the managed build-hours of
        the organization, as a build does: `billing_read_only` (402) for an
        organization that is read-only, and `managed_build_held` (409, with
        `reason`: `trial_hours_used`, `spending_cap_reached`, `at_limit` or
        `unavailable`) for a hold. A hold is recorded as a failed preview, so
        the item page shows the reason.
      operationId: start-work-item-preview
      parameters:
        - in: path
          name: workItemId
          required: true
          schema:
            type: string
      responses:
        '200':
          content:
            application/json:
              schema:
                properties:
                  data:
                    properties:
                      joined:
                        description: >-
                          `true` when the item had a running preview and the
                          caller joined it.
                        type: boolean
                      preview:
                        properties:
                          endReason:
                            enum:
                              - stopped
                              - idle
                              - time_limit
                              - failed
                              - billing
                              - runner_lost
                              - pull_request_closed
                              - null
                            nullable: true
                            type: string
                            x-extensible-enum:
                              - stopped
                              - idle
                              - time_limit
                              - failed
                              - billing
                              - runner_lost
                              - pull_request_closed
                          endedAt:
                            nullable: true
                            type: string
                          failedCommand:
                            description: The setup or seed command that failed.
                            nullable: true
                            type: string
                          failedOutput:
                            description: The last 50 lines of the failed command's output.
                            nullable: true
                            type: string
                          headSha:
                            description: The commit the preview runs.
                            type: string
                          id:
                            description: >-
                              The preview. The preview hosts of its ports start
                              with it.
                            type: string
                          openPort:
                            description: The port that the new tab opens.
                            type: integer
                          outOfDate:
                            description: >-
                              The preview is ready and the pull request head has
                              moved to another commit.
                            type: boolean
                          ports:
                            items:
                              type: integer
                            type: array
                          readyAt:
                            nullable: true
                            type: string
                          refusal:
                            description: >-
                              Why the start was refused before a sandbox
                              started.
                            enum:
                              - read_only
                              - trial_hours_used
                              - spending_cap_reached
                              - unavailable
                              - at_limit
                              - null
                            nullable: true
                            type: string
                            x-extensible-enum:
                              - read_only
                              - trial_hours_used
                              - spending_cap_reached
                              - unavailable
                              - at_limit
                          startedAt:
                            description: When a runner took the preview.
                            nullable: true
                            type: string
                          state:
                            description: >-
                              `queued` waits for a runner, `starting` runs setup
                              and seed, `ready` serves the app, `stopped` ended
                              and `failed` ended with a failed command or a
                              refused start.
                            enum:
                              - queued
                              - starting
                              - ready
                              - stopped
                              - failed
                            type: string
                            x-extensible-enum:
                              - queued
                              - starting
                              - ready
                              - stopped
                              - failed
                        required:
                          - id
                          - state
                          - headSha
                          - openPort
                          - ports
                          - startedAt
                          - readyAt
                          - endedAt
                          - endReason
                          - failedCommand
                          - failedOutput
                          - refusal
                          - outOfDate
                        type: object
                    required:
                      - preview
                      - joined
                    type: object
                required:
                  - data
                type: object
          description: The preview.
        '400':
          content:
            application/json:
              schema:
                properties:
                  error:
                    properties:
                      code:
                        type: string
                      message:
                        type: string
                    required:
                      - code
                      - message
                    type: object
                required:
                  - error
                type: object
          description: Invalid request parameters (validation failed).
        '401':
          content:
            application/json:
              schema:
                properties:
                  error:
                    properties:
                      code:
                        type: string
                      message:
                        type: string
                    required:
                      - code
                      - message
                    type: object
                required:
                  - error
                type: object
          description: Missing or invalid credentials.
        '402':
          content:
            application/json:
              schema:
                properties:
                  error:
                    properties:
                      code:
                        type: string
                      message:
                        type: string
                    required:
                      - code
                      - message
                    type: object
                required:
                  - error
                type: object
          description: The organization is read-only (`billing_read_only`).
        '403':
          content:
            application/json:
              schema:
                properties:
                  error:
                    properties:
                      code:
                        type: string
                      message:
                        type: string
                    required:
                      - code
                      - message
                    type: object
                required:
                  - error
                type: object
          description: >-
            The caller lacks `work.insert`, or is not a signed-in member
            (`forbidden`).
        '404':
          content:
            application/json:
              schema:
                properties:
                  error:
                    properties:
                      code:
                        type: string
                      message:
                        type: string
                    required:
                      - code
                      - message
                    type: object
                required:
                  - error
                type: object
          description: No such work item.
        '409':
          content:
            application/json:
              schema:
                properties:
                  error:
                    properties:
                      code:
                        type: string
                      message:
                        type: string
                    required:
                      - code
                      - message
                    type: object
                required:
                  - error
                type: object
          description: >-
            No preview is offered (`preview_not_offered`), the gateway provides
            no managed sandboxes (`preview_needs_managed_sandboxes`) or a hold
            applies (`managed_build_held`).
        '503':
          content:
            application/json:
              schema:
                properties:
                  error:
                    properties:
                      code:
                        type: string
                      message:
                        type: string
                    required:
                      - code
                      - message
                    type: object
                required:
                  - error
                type: object
          description: >-
            GitHub was rate limiting or failing (`github_unavailable`, safe to
            retry).
components:
  securitySchemes:
    AppId:
      description: Factory id the request is scoped to.
      in: header
      name: X-Outerlayer-App-Id
      type: apiKey
    BearerAuth:
      description: API key (sk_outerlayer_*)
      scheme: bearer
      type: http

````

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