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

# Stream a Worker

> Streams a Worker's live output as an AI SDK UI message stream over Server-Sent Events (`text/event-stream`). Sends the current assistant message state first, then incremental chunks until `data: [DONE]`. Returns `204` if the Worker is not actively running. See [Workers](/workers#stream-a-run).



## OpenAPI

````yaml /openapi.json get /v1/rooms/{roomId}/workers/{workerId}/stream
openapi: 3.1.0
info:
  title: Worklayer Factory API
  version: 1.0.0
  description: >-
    Create custom interfaces to interact with your Worklayer factory—an
    always-on workspace with its own connected apps, skills, memory, files, and
    background Workers (also called an Environment in parts of the web app).
    Send Events into Rooms, read Room History, resolve human Reviews, follow or
    steer Workers, and receive real-time updates via signed Subscriptions.
servers:
  - url: https://api.myworklayer.com
    description: Production
security:
  - bearerAuth: []
tags:
  - name: Rooms
    description: >-
      Create and manage isolated Rooms and read Room History. Every factory
      includes a main Room (`web`) and supports creating additional Rooms via
      the API. Room History is read-only.
  - name: Events
    description: Send Events into a Room and retrieve stored API Events.
  - name: Workers
    description: Inspect, stream, and steer background Workers spawned by your factory.
  - name: Review
    description: >-
      List and resolve pending approvals, questions, and app connections
      blocking a Worker.
  - name: Subscriptions
    description: >-
      Create, update, rotate, and delete HTTPS webhook endpoints for your
      factory.
  - name: Subscription events
    description: Signed webhook payloads delivered by Worklayer when factory events occur.
paths:
  /v1/rooms/{roomId}/workers/{workerId}/stream:
    parameters:
      - $ref: '#/components/parameters/RoomId'
      - $ref: '#/components/parameters/WorkerId'
    get:
      tags:
        - Workers
      summary: Stream a Worker
      description: >-
        Streams a Worker's live output as an AI SDK UI message stream over
        Server-Sent Events (`text/event-stream`). Sends the current assistant
        message state first, then incremental chunks until `data: [DONE]`.
        Returns `204` if the Worker is not actively running. See
        [Workers](/workers#stream-a-run).
      operationId: streamWorker
      responses:
        '200':
          description: >-
            The stream. The response has the header
            `x-vercel-ai-ui-message-stream: v1`.
          content:
            text/event-stream:
              schema:
                $ref: '#/components/schemas/StreamChunk'
              example: >+
                data: {"type":"start","messageId":"msg_02"}


                data: {"type":"text-start","id":"txt_0"}


                data: {"type":"text-delta","id":"txt_0","delta":"I added the
                tracking number"}


                data: {"type":"text-end","id":"txt_0"}


                data: {"type":"finish"}


                data: [DONE]

        '204':
          description: The Worker has no active run.
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          description: The factory owner does not have access to this Worker.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                statusCode: 403
                message: Environment owner cannot access this Worker.
                error: Forbidden
        '404':
          $ref: '#/components/responses/WorkerNotFound'
        '429':
          $ref: '#/components/responses/TooManyRequests'
        '503':
          description: The stream is not available now. Try again later.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                statusCode: 503
                message: Worker stream unavailable.
                error: Service Unavailable
      x-codeSamples:
        - lang: bash
          label: cURL
          source: >-
            curl -N
            "https://api.myworklayer.com/v1/rooms/cmhx3q7v20004l808sd5k2r1m/workers/6f1c2a9e-4b7d-4e2a-9c51-3d8e0b7a1f24/stream"
            \
              -H "Authorization: Bearer $WORKLAYER_API_KEY"
        - lang: javascript
          label: fetch
          source: >-
            const response = await
            fetch('https://api.myworklayer.com/v1/rooms/cmhx3q7v20004l808sd5k2r1m/workers/6f1c2a9e-4b7d-4e2a-9c51-3d8e0b7a1f24/stream',
            {
              headers: {
                Authorization: `Bearer ${process.env.WORKLAYER_API_KEY}`,
              },
            });

            if (response.status === 204) {
              console.log('The Worker has no active run.');
            } else {
              const reader = response.body.pipeThrough(new TextDecoderStream()).getReader();
              let buffer = '';
              read: for (;;) {
                const { value, done } = await reader.read();
                if (done) break;
                buffer += value;
                const events = buffer.split('\n\n');
                buffer = events.pop();
                for (const event of events) {
                  const data = event.replace(/^data: /, '');
                  if (data === '[DONE]') break read;
                  const chunk = JSON.parse(data);
                  if (chunk.type === 'text-delta') process.stdout.write(chunk.delta);
                }
              }
            }
components:
  parameters:
    RoomId:
      name: roomId
      in: path
      required: true
      description: >-
        Room ID. Pass `web` to target your factory's main Room (the conversation
        in the Worklayer web app).
      schema:
        type: string
        minLength: 1
        maxLength: 191
      example: cmhx3q7v20004l808sd5k2r1m
    WorkerId:
      name: workerId
      in: path
      required: true
      description: The Worker id.
      schema:
        type: string
      example: 6f1c2a9e-4b7d-4e2a-9c51-3d8e0b7a1f24
  schemas:
    StreamChunk:
      type: object
      description: >-
        One chunk of the AI SDK UI message stream. The `type` field tells the
        kind of chunk.
      required:
        - type
      properties:
        type:
          type: string
          enum:
            - start
            - text-start
            - text-delta
            - text-end
            - reasoning-start
            - reasoning-delta
            - reasoning-end
            - file
            - source-url
            - source-document
            - tool-input-start
            - tool-input-available
            - tool-output-available
            - tool-output-error
            - start-step
            - finish-step
            - abort
            - finish
            - error
    Error:
      type: object
      description: The error body. Most errors have this shape.
      required:
        - statusCode
        - message
      properties:
        statusCode:
          type: integer
          description: The HTTP status code.
        message:
          type: string
          description: A short description of the error.
        error:
          type: string
          description: The name of the HTTP status.
  responses:
    Unauthorized:
      description: >-
        The API key is missing, not valid or revoked. The response has the
        header `WWW-Authenticate: Bearer`.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            statusCode: 401
            message: Unauthorized
    WorkerNotFound:
      description: The Room or the Worker is not found, or the Worker is not in this Room.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            statusCode: 404
            message: Worker not found.
            error: Not Found
    TooManyRequests:
      description: Too many requests in a short time. Wait, then send the request again.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            statusCode: 429
            message: 'ThrottlerException: Too Many Requests'
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: wrk-…
      description: >-
        Your factory's Worklayer API key (`wrk-...`). See [Get an API
        key](/quickstart#get-an-api-key) and [Authentication](/authentication).
        Requests sent from the playground execute live against your factory.

````

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