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

# Author routines

> Replace the Deck agent with your own Playwright routine for a task on a specific source.

By default, the Deck agent completes a [task](https://docs.deck.co/concepts/tasks.md). A **routine** lets you take control for one source: every run of the task on that source runs your own Playwright code instead.

Routines are set per task and source. A task that runs on five utility portals can use a `playwright` routine on one portal and the agent on the other four. You can manage routines in the Console, with the [Deck CLI](https://docs.deck.co/cli.md), or through the API.

```mermaid theme={null}
%%{init: {'theme': 'base', 'themeVariables': {'darkMode': true, 'background': '#0D100F', 'primaryColor': '#1B1E1D', 'primaryTextColor': '#F6F6F6', 'primaryBorderColor': '#323534', 'lineColor': '#60917E'}}}%%
flowchart LR
    T["Task: Fetch latest bill"]
    T --> A["Source: ConEdison"]
    T --> B["Source: PG&E"]
    T --> C["Source: Duke Energy"]
    A --> TA["Routine: playwright<br/>Your routine runs"]
    B --> TB["Routine: agent<br/>Deck agent runs"]
    C --> TC["No routine<br/>Deck agent runs"]
```

## When to write a routine

Start with the agent. It works out the steps from your prompt and works around changes on the source, so most tasks don't need a routine.

Consider a routine for a source when:

* **The agent keeps failing on agent mode.** If runs on one source fail with `task_failed` again and again while other sources succeed, a routine can do the task there instead.
* **You need the same steps every time.** For example, the data has to come from a specific page or from the portal's own API, not wherever the agent finds it.

The trade-off is upkeep. A routine runs exactly the code you saved and doesn't adapt. When the source changes, runs on it fail until you update the routine.

## Routine types

| Type | What runs |
| - | - |
| `agent` | The Deck agent completes the task. This is the default when a source has no routine. |
| `playwright` | Your Python code, using Playwright's sync API. |

A task can have one routine per source.

## How a run uses a routine

When a task run starts, Deck looks up the routine for the run's task and source:

1. If the run has a credential, the Deck agent logs in to the source. See [Deck handles login](#deck-handles-login).
2. If the routine is `playwright`, Deck calls your routine with the logged-in browser and the run's input.
3. Whatever your routine returns becomes the run's `output`.

With no routine, or an `agent` routine, the agent runs the task as usual.

## Deck handles login

Your routine never logs in. Authentication is always handled by the Deck agent, which then hands the browser to your routine:

1. The Deck agent logs in with the run's credential, including MFA. If the source asks for a code, the run pauses for an [interaction](https://docs.deck.co/guides/interactions.md), the same as any other run.
2. Once login is complete, Deck passes the same browser to your routine, already logged in.
3. If login fails, the run ends with the login error, such as `auth_invalid` or `account_locked`, and your routine doesn't run.

If the run's [session](https://docs.deck.co/concepts/sessions.md) is already logged in, Deck skips login and starts your routine straight away.

Your routine doesn't receive the credential. Write it as if it starts after login.

## Two ways to get a routine

You can have Deck write the routine, or write it yourself. Both save a new version of the routine, and you can mix them: let Deck write the first version and edit it yourself, or the other way around.

| | Let Deck build it | Write it yourself |
| - | - | - |
| Who writes the routine | Deck | You, or a coding agent such as Claude Code or Codex |
| How it starts | Start a build in the Console or with `POST /v2/routines/{routine_id}/build` | Run the task once with the agent, then study the run and write against a logged-in browser |
| How it's saved | The build saves the routine it wrote as a new version | You save the routine in the Console or with the Routines API |

See [Let Deck build it](#let-deck-build-it), or start with [Before you write](#before-you-write-study-an-agent-run) to write it yourself.

## Let Deck build it

A build logs in to the source, works through the task, and writes a Playwright routine from what it did. When the build completes, the routine gets a new `playwright` version, and runs on that source use it right away. If the build fails, the routine doesn't change.

Deck doesn't check the routine's output against the task's `output_schema` before saving it. When the build completes, run the task on that source and check the run's `output`. If it doesn't match, the run fails with `task_failed`.

### Start a build

In the Console, open the task's **Routines** tab. For a source without a routine, click **Create routine** and select **Deck builds routine**. For a source that has one, select **Build routine** on an `agent` routine or **Rebuild routine** on a `playwright` routine. Pick a credential and enter an example input. The **Instructions** field starts with the task's prompt. Edits there apply to this build only.

Through the API, create the routine as `agent` first if the source doesn't have one yet:

```text theme={null}
POST /v2/routines
```

```json theme={null}
{
  "task_id": "task_a1b2c3...",
  "source_id": "src_d4e5f6...",
  "name": "Fetch latest bill",
  "type": "agent"
}
```

Then start the build:

```text theme={null}
POST /v2/routines/rtn_g7h8i9.../build
```

```json theme={null}
{
  "credential_id": "cred_7k2m...",
  "input": { "account_id": "AC-2291" },
  "instructions": "Pull bills from the Billing History page, not the dashboard."
}
```

| Field | Required | Description |
| - | - | - |
| `credential_id` | When the source requires login | The credential the build logs in with. It must belong to the routine's source. |
| `input` | When the task has required inputs | An example input, validated against the task's `input_schema` the same way as a task run. |
| `instructions` | No | Plain-text guidance for the build, up to 10,000 characters. The build also reads the task's prompt. |

The build only sees the parts of the portal available to the credential you provide. Pick a credential that covers all the parts of the portal the task needs to see.

The response is `202` with a `routine_build` in `queued`:

```json theme={null}
{
  "id": "rbld_x1y2z3...",
  "object": "routine_build",
  "routine_id": "rtn_g7h8i9...",
  "task_id": "task_a1b2c3...",
  "source_id": "src_d4e5f6...",
  "credential_id": "cred_7k2m...",
  "session_id": null,
  "live_view_url": null,
  "status": "queued",
  "version": null,
  "instructions": "Pull bills from the Billing History page, not the dashboard.",
  "errors": null,
  "interaction": null,
  "runtime_ms": null,
  "created_at": "2026-11-05T16:41:03Z",
  "updated_at": "2026-11-05T16:41:03Z",
  "request_id": "req_..."
}
```

To update an existing `playwright` routine, start another build on it. Each build writes a new version. Earlier versions stay in the [version history](#edit-a-routine).

With the [Deck CLI](https://docs.deck.co/cli.md), `--wait` starts a build and returns the finished one. If the build needs an interaction, the command returns as soon as the build is waiting.

```bash theme={null}
deck routines build rtn_g7h8i9... --wait --yes --input '{
  "credential_id": "cred_7k2m...",
  "input": { "account_id": "AC-2291" }
}'
```

### Follow the build

Retrieve the build with `GET /v2/routine-builds/{routine_build_id}`, or subscribe to [`routine_build.*` events](https://docs.deck.co/events/events-reference#routine-build-events). Builds use the same statuses as task runs:

| Status | Meaning |
| - | - |
| `queued` | Waiting to start, or logging in |
| `running` | Working through the task and writing the routine |
| `interaction_required` | The source needs input from your user during login |
| `completed` | A new version was saved. `version` is the new version number. |
| `failed` | No version was saved. See `errors`. |
| `canceling` | Cancel requested, stopping |
| `canceled` | Canceled before it finished |

If the source asks for an MFA code, the build pauses with an `interaction`, the same as a task run. Submit the code with `POST /v2/routine-builds/{routine_build_id}/interaction`, using the same body as a [task run interaction](https://docs.deck.co/guides/interactions.md). To stop a build, call `POST /v2/routine-builds/{routine_build_id}/cancel`.

To see what a build did in the browser, read its logs with `GET /v2/routine-builds/{routine_build_id}/browser-logs`. They cover login and the build's work on the task, and use the same shape and filters as [task run browser logs](#read-browser-logs). Retrieve the build with `include=browser` for its DOM and HAR files.

When you retrieve a build that's `running` or `interaction_required`, `live_view_url` is a read-only view of its browser. It's `null` otherwise, and in lists. Each retrieve returns a new URL that works for 30 minutes. The URL carries a token, so treat it like an API key. It's always `null` for a [sensitive task](https://docs.deck.co/concepts/tasks.md#sensitive-tasks).

A build can run for up to 60 minutes, regardless of the task's `timeout_seconds`. If it runs longer, it fails with `timeout`. If Deck can't produce a routine, the build fails with `routine_build_failed`. Either way, the routine doesn't change.

### How builds affect the rest of your account

* **Task runs.** A build isn't a task run. It doesn't appear in `GET /v2/task-runs` and doesn't send `task_run.*` events. Runs of the task keep using the current routine version until a build saves a new one.
* **Credentials.** A build doesn't change a credential's status or send `credential.*` events. If login fails, the build fails with the login error, such as `auth_invalid`. With [credential queueing](https://docs.deck.co/concepts/credentials.md#credential-queueing) on, a build holds the credential from when it starts until it ends, like a task run.
* **Edits.** A routine can have one active build at a time. While a build is active, starting another build, updating the routine, or deleting it fails with `routine_build_in_progress`. Cancel the build first.
* **Versions.** Versions saved by a build have `routine_build_id` set in [the routine's history](#edit-a-routine).

## Before you write: study an agent run

The quickest way to write a reliable routine is to see what the portal does when the agent completes the task. Run the task once with no routine, then read that run's [browser logs](#read-browser-logs):

```text theme={null}
GET /v2/task-runs/trun_a1b2c3.../browser-logs?type=network,navigation
```

`navigation` entries show the pages the agent visited in order. `network` entries show the XHR and fetch requests those pages made. Most portals load their data from a few JSON endpoints, and calling those endpoints from your routine is usually faster and more stable than reading the rendered page.

> [!TIP]
>
> Add `include=browser` when you retrieve the run to download a HAR file of every request. It opens in Chrome DevTools, Charles, and Proxyman.

## Write the routine

A routine is a Python module that defines `execute`:

```python theme={null}
import deck


def execute(page, context, browser, input):
    page.goto("https://portal.example.com/billing")
    page.wait_for_selector("table.bills")

    rows = page.locator("table.bills tbody tr").all()
    if not rows:
        deck.document_not_found("No bills are listed for this account.")

    bills = []
    for row in rows:
        cells = row.locator("td").all()
        bills.append({
            "period": cells[0].inner_text(),
            "amount": cells[1].inner_text(),
        })
    return {"bills": bills}
```

| Argument | Contents |
| - | - |
| `page` | The browser page, already logged in if the run has a credential |
| `context` | The page's browser context |
| `browser` | The browser |
| `input` | The run's `input`. Deck restores [tokenized fields](https://docs.deck.co/concepts/tasks.md#tokenizing-sensitive-fields) to their real values so your routine can enter them on the source. Don't print or return them. |

Your routine starts on whatever page the browser is showing after [login](#deck-handles-login), so navigate to where you need to be.

### Return the output

The return value must match the task's `output_schema` exactly:

* Include every required field, and don't set a required field to `null`.
* Don't add fields the schema doesn't define.

If the output doesn't match, the run fails with `task_failed` and `output` is `null`. `print()` doesn't affect the output.

### Fetch data from inside the page

Routines have no direct internet access. To call a portal's API, run the request in the page, where it uses the page's logged-in session:

```python theme={null}
def execute(page, context, browser, input):
    page.goto("https://portal.example.com/billing")
    return page.evaluate(
        """async (accountId) => {
            const res = await fetch(`/api/accounts/${accountId}/bills`);
            return { bills: await res.json() };
        }""",
        input["account_id"],
    )
```

Use `page.evaluate`. Playwright's request API (`page.request` and `context.request`) doesn't work in routines.

### Save files

To capture files, turn on [storage](https://docs.deck.co/guides/storage.md) for the task and save files to `/downloads`. After the routine succeeds, Deck uploads every file it wrote there to the run's storage.

```python theme={null}
with page.expect_download() as download:
    page.click("a.download-pdf")
download.value.save_as("/downloads/latest-bill.pdf")
```

If a file fails to upload, the run fails.

### End with a specific outcome

Call a `deck` helper to end the run with a specific [error code](https://docs.deck.co/api/errors.md) instead of a generic failure. Pass a message to replace the default one. The message is returned to you on the run.

| Helper | Error code |
| - | - |
| `deck.account_not_found(message)` | `resource_not_found` |
| `deck.document_not_found(message)` | `resource_not_found` |
| `deck.resource_not_ready(message)` | `resource_not_ready` |
| `deck.input_rejected(message, field)` | `input_invalid` |
| `deck.account_locked(message)` | `account_locked` |
| `deck.password_reset_required(message)` | `password_reset_required` |
| `deck.source_error(message)` | `source_error` |
| `deck.source_not_available(message)` | `source_not_available` |
| `deck.blocked(message)` | `blocked` |
| `deck.task_not_supported(message)` | `task_not_supported` |

Add `import deck` at the top of the routine to use them. Messages are limited to 1,000 characters.

Helpers stop the routine immediately, and `except Exception` doesn't catch them. Before calling a `*_not_found` helper on an empty list, confirm the page actually loaded, such as with `wait_for_selector`. A page that failed to load also looks empty.

Any other exception fails the run with `task_failed`. See [When a routine fails](#when-a-routine-fails).

## Create the routine

A routine takes effect as soon as you save it. The next run of the task on that source uses it, so test it first with the [local runner](#2-test-with-a-runner). To undo a change, [restore an earlier version](#edit-a-routine).

### In the Console

1. Open the task and select the **Routines** tab.
2. Click **Create routine**, select **Build routine yourself**, and pick the source.
3. Write your routine in the editor. It starts with a template that defines `execute`.
4. Click **Save changes**.

The Routines tab lists every source that has a routine. Sources that aren't listed use the Deck agent.

### With the Deck CLI

Pass the task, the source, and your code in `playwright.script`. This example builds the request body with `jq`, which reads `routine.py` as a string:

```bash theme={null}
jq -n --rawfile script routine.py '{
  task_id: "task_a1b2c3...",
  source_id: "src_d4e5f6...",
  name: "Fetch latest bill",
  type: "playwright",
  playwright: { script: $script }
}' | deck routines create --input - --yes
```

If the source already has a routine, pipe the same body without `task_id`, `source_id`, and `name` to `deck routines update rtn_g7h8i9... --input - --yes`.

### Through the API

Create the routine with the task, the source, and the code in `playwright.script`:

```text theme={null}
POST /v2/routines
```

```json theme={null}
{
  "task_id": "task_a1b2c3...",
  "source_id": "src_d4e5f6...",
  "name": "Fetch latest bill",
  "type": "playwright",
  "playwright": {
    "script": "import deck\n\n\ndef execute(page, context, browser, input):\n    ..."
  }
}
```

```json theme={null}
{
  "id": "rtn_g7h8i9...",
  "object": "routine",
  "task_id": "task_a1b2c3...",
  "source_id": "src_d4e5f6...",
  "name": "Fetch latest bill",
  "type": "playwright",
  "playwright": {
    "script": "import deck\n\n\ndef execute(page, context, browser, input):\n    ..."
  },
  "created_at": "2026-09-22T12:00:00Z",
  "updated_at": "2026-09-22T12:00:00Z",
  "request_id": "req_..."
}
```

If the source already has a routine for the task, the request fails with `routine_already_exists`. Update or delete the existing routine instead.

Routines can be up to 200,000 characters and run within the task's timeout.

To see every routine a task uses, retrieve the task with `include=routines`:

```text theme={null}
GET /v2/tasks/task_a1b2c3...?include=routines
```

```json theme={null}
{
  "id": "task_a1b2c3...",
  "object": "task",
  "name": "Fetch latest bill",
  "sources": [
    {
      "source_id": "src_d4e5f6...",
      "routines": [
        {
          "id": "rtn_g7h8i9...",
          "object": "routine",
          "name": "Fetch latest bill",
          "type": "playwright",
          "updated_at": "2026-09-22T12:00:00Z"
        }
      ]
    }
  ]
}
```

## Author locally with a coding agent

You can write and test a routine from your own machine with a coding agent such as Claude Code or Codex. Deck logs in to the source, then gives you access to the same browser your routine will get. The steps below use the [Deck CLI](https://docs.deck.co/cli.md), so your coding agent can run them itself. Each command maps to an API endpoint if you'd rather call it directly.

### 1. Get a logged-in browser

Run the task once with the credential. The agent run from [Before you write](#before-you-write-study-an-agent-run) works, and so does a run that used your routine. When the run finishes, its [session](https://docs.deck.co/concepts/sessions.md) stays open and logged in for 10 minutes.

```bash theme={null}
deck tasks run task_a1b2c3d4... --wait --input '{
  "credential_id": "cred_a1b2c3d4...",
  "input": { "account_id": "AC-2291" }
}'
```

Request browser access for the run's `session_id`:

```bash theme={null}
deck sessions browser-access create sess_a1b2c3d4... --yes
```

```json theme={null}
{
  "id": "bacc_e5f6g7h8...",
  "object": "browser_access",
  "session_id": "sess_a1b2c3d4...",
  "cdp_url": "wss://api.deck.co/v2/browser/cdp/sess_a1b2c3d4...?token=bt_x9y8z7...",
  "live_view_url": null,
  "status": "active",
  "expires_at": "2026-09-22T12:30:00Z",
  "created_at": "2026-09-22T12:00:00Z",
  "request_id": "req_..."
}
```

This is `POST /v2/sessions/{session_id}/browser-access` in the API. The command needs `--yes` because requesting access again replaces the earlier grant and drops its connection.

Connect Playwright to `cdp_url` to drive the browser. The URL carries a token, so treat it like an API key. Connect before `expires_at`, 30 minutes after the request. Once open, a connection stays up until you revoke access or the session ends. Only one connection can be open at a time.

The session stays open while your client is sending commands, and closes 10 minutes after its last command or after you disconnect. A session's browser lasts up to an hour. Keep at least one tab open: closing the last tab ends the session. While Playwright is connected, you can't start a task run in the session. Wait for any run in the session to finish before requesting access.

### 2. Test with a runner

Save this next to your routine as `run_routine.py`. It calls your `execute` the same way Deck does and stands in for the `deck` module:

```python theme={null}
import json
import sys
import types

from playwright.sync_api import sync_playwright

OUTCOMES = [
    "account_not_found", "document_not_found", "resource_not_ready",
    "input_rejected", "account_locked", "password_reset_required",
    "source_error", "source_not_available", "blocked", "task_not_supported",
]


class DeckOutcome(BaseException):
    pass


def _outcome(name):
    def end(message="", field=""):
        raise DeckOutcome(f"{name}: {message} {field}".strip())
    return end


deck = types.ModuleType("deck")
for name in OUTCOMES:
    setattr(deck, name, _outcome(name))
sys.modules["deck"] = deck

import routine  # your routine.py

cdp_url, input_path = sys.argv[1], sys.argv[2]
with sync_playwright() as p:
    browser = p.chromium.connect_over_cdp(cdp_url)
    context = browser.contexts[0]
    page = context.pages[-1]  # the tab Deck logged in on
    with open(input_path) as f:
        run_input = json.load(f)
    try:
        output = routine.execute(page=page, context=context, browser=browser, input=run_input)
        print(json.dumps(output, indent=2))
    except DeckOutcome as outcome:
        print(f"Outcome: {outcome}")
```

```bash theme={null}
python run_routine.py "$DECK_CDP_URL" input.json
```

Your machine has internet access and Deck's routine environment doesn't, so a routine can pass locally and still fail on Deck if it makes requests outside the page. The runner doesn't upload files; check downloads with a real run.

### 3. Brief your agent

Paste this into your coding agent, filled in with your task's details:

```text theme={null}
Write a Deck routine in routine.py for this task.

Task prompt: <paste the task's prompt>
Output schema: <paste the task's output_schema>
Example input: <paste an example input, also saved as input.json>

Rules:
- Python with Playwright's sync API. Define
  def execute(page, context, browser, input) and return a dict that matches
  the output schema exactly: every required field, no null required fields,
  no extra fields.
- The browser is already logged in. Never write login code.
- Navigate to the page you need first. Don't assume the current page.
- Fetch data only from inside the page with page.evaluate and fetch. Don't use
  page.request, context.request, requests, or any other network library.
- Save downloaded files to /downloads.
- import deck and end with a deck helper for these states:
  account_not_found, document_not_found, resource_not_ready,
  input_rejected(message, field), account_locked, password_reset_required,
  source_error, source_not_available, blocked, task_not_supported.
  Confirm the page loaded before calling a *_not_found helper.
- Raise an exception for anything else.
- Don't close pages or the browser you didn't open.

Get a browser with the Deck CLI:
  deck sessions browser-access create <session_id> --yes
Use the cdp_url it returns. If the session has closed, run the task again
with deck tasks run <task_id> --wait and request access for the new session.

Explore the portal with short Playwright scripts that connect with
connect_over_cdp. Only one connection can be open at a time, so let each one
exit before starting the next. Test with:
python run_routine.py "<cdp_url>" input.json
```

### 4. Ship it

When the routine works, end the session:

```bash theme={null}
deck sessions end sess_a1b2c3d4...
```

Then save `routine.py` as the routine with [the Deck CLI](#with-the-deck-cli).

Run the task on that source and check that the run's `output` has what you expect. Retrieve the run with `include=routines` to confirm your routine ran.

## Check which routine a run used

Retrieve a run with `include=routines` to see the prompt and the exact routine version it ran:

```text theme={null}
GET /v2/task-runs/trun_j1k2l3...?include=routines
```

```json theme={null}
{
  "id": "trun_j1k2l3...",
  "object": "task_run",
  "status": "completed",
  "prompt": "Fetch the latest bill for the account.",
  "routines": [
    {
      "id": "rtn_g7h8i9...",
      "object": "routine",
      "name": "Fetch latest bill",
      "type": "playwright",
      "version": 3,
      "playwright": { "script": "..." }
    }
  ]
}
```

`routines` records the routine as it was when the run executed, so later edits don't change it. An empty array means the source had no routine and the agent ran.

## When a routine fails

When a routine raises an exception, runs past the task's timeout, or returns output that doesn't match `output_schema`, the run fails with `task_failed`.

If login fails, the run ends with the login error, such as `auth_invalid`, and your routine doesn't run. Errors from `deck` helpers keep their own codes.

Most routine failures come from a change on the portal, such as a moved element or a renamed endpoint. To fix one, reproduce it against a logged-in browser with the [local runner](#author-locally-with-a-coding-agent), or [start a build](#let-deck-build-it) to have Deck write a new version.

## Edit a routine

### In the Console

Open the task's **Routines** tab and select **Edit routine** on the source's row. The routine's version history is below the editor: select a version to compare it with the one before, or load it into the editor and save to restore it. To hand the source back to the Deck agent, select **Remove routine**.

When a run that used a routine fails, its page in the Console links straight to that routine's editor.

### Through the API

Update a routine with the fields you want to change:

```text theme={null}
PATCH /v2/routines/rtn_g7h8i9...
```

```json theme={null}
{
  "playwright": {
    "script": "import deck\n\n\ndef execute(page, context, browser, input):\n    ..."
  }
}
```

Each change to a routine's name, type, or code creates a new version.

| Goal | Request |
| - | - |
| See a routine's history | `GET /v2/routines/{routine_id}/versions` |
| Read an old version | `GET /v2/routines/{routine_id}/versions/{version}` |
| Restore an old version | `PATCH` the routine with the old version's `playwright.script` |
| Hand the source back to the agent | `PATCH` with `"type": "agent"`, or delete the routine |

Changing a routine to `agent` removes its code. The old code stays in the version history.

## Read browser logs

Deck records what happens in the browser during a task run: console output, XHR and fetch requests, and page navigations. Use them to learn how a portal works before you write a routine for it, or to see what went wrong on an agent run. Runs that use a `playwright` routine record the login only, not your routine. [Builds](#follow-the-build) have browser logs too.

```text theme={null}
GET /v2/task-runs/trun_a1b2c3.../browser-logs
```

```json theme={null}
{
  "data": [
    {
      "id": "logb_m4n5o6...",
      "object": "browser_log",
      "type": "navigation",
      "created_at": "2026-09-22T12:00:03.120Z",
      "page_url": "https://portal.example.com/billing",
      "data": { "url": "https://portal.example.com/billing", "status": 200 }
    },
    {
      "id": "logb_p7q8r9...",
      "object": "browser_log",
      "type": "network",
      "created_at": "2026-09-22T12:00:03.480Z",
      "page_url": "https://portal.example.com/billing",
      "data": {
        "method": "GET",
        "url": "https://portal.example.com/api/accounts/1234/bills",
        "status": 200,
        "content_type": "application/json",
        "response_size": 1832,
        "response_body_sample": null,
        "request_body": null,
        "request_body_truncated": false
      }
    }
  ],
  "has_more": true,
  "next_cursor": "bzoxMDA="
}
```

Entries are listed oldest first. Filter with `type` (`console`, `network`, `navigation`, comma-separated) and page with `limit` and `cursor`, as with other [list endpoints](https://docs.deck.co/api/pagination.md).

| Type | `data` fields |
| - | - |
| `console` | `level` and `text`, up to 500 characters |
| `network` | `method`, `url`, `status`, `content_type`, `response_size`, `response_body_sample`, `request_body` (up to 16 KB), `request_body_truncated` |
| `navigation` | `url` and `status` |

`response_body_sample` is often `null`, so use `response_size` and `content_type` to spot the requests that return data.

Credential values are masked, and request headers such as cookies are never recorded. Entries appear while the run is still in progress. An empty list means nothing was captured.

### Browser files

Retrieve the run with `include=browser` to get two downloadable files:

```text theme={null}
GET /v2/task-runs/trun_a1b2c3...?include=browser
```

```json theme={null}
{
  "browser": {
    "logs_truncated": false,
    "dom": {
      "page_url": "https://portal.example.com/billing",
      "file_type": "text/html",
      "file_size": 48213,
      "truncated": false,
      "url": "/v2/task-runs/trun_a1b2c3.../browser-logs/dom",
      "created_at": "2026-09-22T12:00:41Z"
    },
    "har": {
      "file_type": "application/json",
      "file_size": 90412,
      "truncated": false,
      "url": "/v2/task-runs/trun_a1b2c3.../browser-logs/har",
      "created_at": "2026-09-22T12:00:42Z"
    }
  }
}
```

* `dom` is the HTML of the last page the run was on, available once the run finishes or pauses for an [interaction](https://docs.deck.co/guides/interactions.md).
* `har` is every network request from the run as a HAR file, available once the run finishes.

Each `url` is an API path. Download it with your API key, like any other request. The HAR keeps request bodies as sent, so entries from login can include the user's password.

### Limits

Deck keeps the first 5,000 network, 10,000 console, and 1,000 navigation entries from each run. If a run goes past a limit, later entries of that type are dropped and `logs_truncated` is `true`. The earliest entries, such as the login, are always kept.


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