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

> ## Agent Instructions
> Agents: start with https://docs.pre.dev/agents.md, which has complete recipes, plan access, polling rules, errors and limits.
> Authenticate with the workspace API key (pdk_…) from Integrations → Built-in, sent as Authorization: Bearer <key>.
> REST API: https://api.pre.dev (OpenAPI: https://docs.pre.dev/api-reference/openapi.json). AI Gateway: https://api.pre.dev/v1, OpenAI-compatible (OpenAPI: https://docs.pre.dev/api-reference/ai-gateway.openapi.json).
> pre.dev MCP server: https://api.pre.dev/mcp. Search these docs over MCP at https://docs.pre.dev/mcp.

# Watch the live browser

> Get an authenticated WebSocket URL for available browser frames in a run you own.

Request the live-view URL using your API key and an existing run ID:

```bash theme={null}
curl --fail-with-body "https://api.pre.dev/browser-agent/$BATCH_ID/ws" \
  -H "Authorization: Bearer $PREDEV_API_KEY"
```

The response is `{ "url": "wss://…" }`. Connect to that URL exactly as returned; it includes the authorization needed for the live view. Treat it as a credential-bearing URL and keep it out of public logs.

## Frames

Where live capture is available, JSON messages with `type: "frame"` contain:

| Field | Meaning |
| - | - |
| `taskIndex` | Zero-based index within the run |
| `b64` | Base64-encoded JPEG image |
| `w`, `h` | Capture metadata dimensions, when available |
| `ts` | Unix timestamp in milliseconds |

Filter for `type: "frame"` before reading those fields. For a preview image, use `data:image/jpeg;base64,` followed by `b64` as the image source.

Frames are a live visual feed, not a durable recording, task-control channel, or completion signal. Some execution paths do not produce live frames. Use [SSE or polling](/browser-agents/api/stream-task) for authoritative task state and `includeEvents=true` for available screenshot history.

A returned URL does not guarantee that a frame will arrive. Current SDKs and MCP tools do not have a wrapper for this endpoint.

## Errors

| Status | When |
| - | - |
| `400` | `id` is not a valid run ID |
| `401` | Missing or invalid key |
| `404` | No run with this ID in your account, or no live stream for it |

Each status has an example body in the response examples. See [errors and retries](/api-reference/errors).


## OpenAPI

````yaml api-reference/openapi.json GET /browser-agent/{id}/ws
openapi: 3.1.0
info:
  title: pre.dev API
  description: >-
    Public REST API for software specifications, browser automation, and credit
    balance. Base URL: https://api.pre.dev. MCP is documented separately at
    https://docs.pre.dev/mcp/tools.
  version: 1.1.0
  contact:
    name: pre.dev Support
    url: https://pre.dev
    email: support@pre.dev
  license:
    name: Proprietary
    url: https://pre.dev/terms
servers:
  - url: https://api.pre.dev
    description: Production API Server
security:
  - apiKeyAuth: []
  - xApiKey: []
tags:
  - name: Specifications
  - name: Browser Agents
  - name: Account
paths:
  /browser-agent/{id}/ws:
    get:
      tags:
        - Browser Agents
      summary: Get a live browser URL
      description: >-
        Returns a credential-bearing WebSocket URL for live JPEG frames.
        Availability depends on the execution path. No browser input control or
        recorded playback.
      operationId: getLiveBrowser
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            description: 24-character record ID.
            pattern: ^[a-fA-F0-9]{24}$
      responses:
        '200':
          description: Connect to the returned WebSocket URL.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/LiveBrowserResponse'
              example:
                url: >-
                  wss://browser-worker.example/ws/507f1f77bcf86cd799439011?token=3f1c0b9e2d4a7c58
        '400':
          description: Invalid request.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              example:
                error: invalid batch id
        '401':
          description: Missing, invalid, or ineligible authentication.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              examples:
                missing_key:
                  summary: No key sent
                  value:
                    error: Missing API key
                    message: >-
                      Please provide an API key via Authorization: Bearer
                      <token> header or x-api-key header
                invalid_key:
                  summary: Unknown key
                  value:
                    error: Authentication failed
                    message: Invalid API key
        '404':
          description: Record unavailable.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
              examples:
                not_found:
                  summary: Unknown batch
                  value:
                    error: batch not found
                no_stream:
                  summary: No live stream for this batch
                  value:
                    error: live stream not available
components:
  schemas:
    LiveBrowserResponse:
      type: object
      required:
        - url
      properties:
        url:
          type: string
          description: >-
            Credential-bearing WebSocket URL. Keep private and use only for the
            requested batch.
          format: uri
    Error:
      type: object
      required:
        - error
      properties:
        error:
          type: string
        message:
          type: string
          description: Optional detail; not returned by every endpoint.
        code:
          type: string
          description: Machine-readable code when available.
        actionUrl:
          type: string
          format: uri
        requiresSubscription:
          type: boolean
        trialsUsed:
          type: integer
        maxTrials:
          type: integer
      additionalProperties: true
  securitySchemes:
    apiKeyAuth:
      type: http
      scheme: bearer
      bearerFormat: API key
      description: >-
        Your pre.dev workspace API key (pdk_...) from Integrations, Built-in
        tab: https://pre.dev/projects/integrations?tab=built-in
    xApiKey:
      type: apiKey
      in: header
      name: x-api-key
      description: 'Alternative to Authorization: Bearer.'

````

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