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

# WebRouter Browse

> Have an agent drive a real browser through a task, on any browse provider, as a job you poll

> [!NOTE]
>
> **WebRouter is in closed beta.** It's available to selected accounts, and the API may still change. To get access, [talk to the Nimble team](https://nimbleway.com/contact-general/).

WebRouter **Browse** gives a task to an agent that drives a real browser. It clicks, types, and reads through pages until the task is done, then returns its answer and the steps it took.

Use it for what needs a browser, such as filling in a form or working through a site's own search. To read a page you have the URL of, use [Extract](https://docs.nimbleway.com/nimble-sdk/web-router/extract.md). A browse task takes minutes and is billed. It runs as a job: start it, then poll it until it ends.

## Quick Start

### Example Request

```python Python theme={"system"}
import requests

BASE = "https://sdk.nimbleway.com/v2/web-router"
HEADERS = {"Authorization": "Bearer YOUR-API-KEY"}

job = requests.post(
    f"{BASE}/browse",
    headers=HEADERS,
    json={
        "task": "Report the main heading text on this page",
        "start_url": "https://example.com",
        "max_steps": 5,
    },
).json()["job"]

while True:
    result = requests.get(
        f"{BASE}/browse/{job['job_id']}",
        headers=HEADERS,
        params={"wait": 60},
    ).json()["result"]
    if result["state"] in ("completed", "failed", "cancelled"):
        break

if result["state"] == "completed":
    print(result["response"]["answer"])
```

```typescript TypeScript theme={"system"}
const BASE = "https://sdk.nimbleway.com/v2/web-router";
const headers = {
  Authorization: "Bearer YOUR-API-KEY",
  "Content-Type": "application/json",
};

const start = await fetch(`${BASE}/browse`, {
  method: "POST",
  headers,
  body: JSON.stringify({
    task: "Report the main heading text on this page",
    start_url: "https://example.com",
    max_steps: 5,
  }),
});
const { job } = await start.json();

let result;
do {
  const poll = await fetch(`${BASE}/browse/${job.job_id}?wait=60`, { headers });
  ({ result } = await poll.json());
} while (result.state === "queued" || result.state === "running");

if (result.state === "completed") {
  console.log(result.response.answer);
}
```

```bash cURL theme={"system"}
# Start the task
curl -X POST 'https://sdk.nimbleway.com/v2/web-router/browse' \
--header 'Authorization: Bearer <YOUR-API-KEY>' \
--header 'Content-Type: application/json' \
--data-raw '{
    "task": "Report the main heading text on this page",
    "start_url": "https://example.com",
    "max_steps": 5
}'

# Poll it, waiting up to 60 seconds per call
curl 'https://sdk.nimbleway.com/v2/web-router/browse/<JOB-ID>?wait=60' \
--header 'Authorization: Bearer <YOUR-API-KEY>'
```

### Example Response

The start answers at once, with status `202`:

```json theme={"system"}
{
  "meta": { "tool": "browse" },
  "job": {
    "job_id": "wgbj_8d0e4f6a2c1b4a7eb9d35f6a7b8c9d0e",
    "provider": "nimble_selection",
    "byok": false,
    "state": "queued"
  }
}
```

A poll of a completed task:

```json theme={"system"}
{
  "meta": { "tool": "browse" },
  "result": {
    "job_id": "wgbj_8d0e4f6a2c1b4a7eb9d35f6a7b8c9d0e",
    "provider": "nimble_selection",
    "byok": false,
    "state": "completed",
    "detail": null,
    "response": {
      "provider": "nimble_selection",
      "byok": false,
      "answer": "The main heading text on the page is: 'This domain is for use in documentation examples without needing permission.'",
      "structured": null,
      "steps": [
        {
          "action": "{\"evaluate\": {\"code\": \"document.querySelector('h1').innerText\"}}",
          "url": "https://example.com/",
          "detail": "I have navigated to example.com and can see the page content. I need to identify the main heading text.",
          "screenshot_url": null,
          "extra": { "number": 1, "duration": 5.73 }
        }
      ],
      "outcome": "complete"
    }
  }
}
```

## How it works

**1. Start the task**

`POST /v2/web-router/browse` answers at once with a `job_id`. Every start is
a new, billed task. Nimble picks the provider and keeps the task with it.

**2. The agent works in a browser**

It starts at `start_url`, stays on `allowed_domains`, and takes at most
`max_steps` actions.

**3. Poll it**

`GET /v2/web-router/browse/{job_id}?wait=60` waits up to a minute for the
task to end. Call again while `state` is `queued` or `running`.

**4. Read the answer**

Once `state` is `completed`, `result.response` holds the answer, the steps
the agent reported, and a recording when the provider made one.

> [!WARNING]
>
> Poll the task you have instead of starting it again. If a start fails with
> `may_have_started`, a task may be running: do not start another.

## Parameters

> [accordion] task - Required
>
> **task** `string` *required*
>
> What the agent should do, in plain words. Up to 10,000 characters.

> [accordion] start\_url
>
> **start\_url** `string`
>
> The page the agent starts on.

> [accordion] allowed\_domains
>
> **allowed\_domains** `array of strings`
>
> Keep the agent on these domains. Up to 50.

> [accordion] max\_steps
>
> **max\_steps** `integer`
>
> Upper bound on the actions the agent may take. Unset is the provider's own limit.

> [accordion] output\_schema
>
> **output\_schema** `object`
>
> A JSON Schema the answer must conform to, returned in `response.structured`. Unset asks for prose. The root must be an object with non-empty `properties`, or an array with `items`.

## Response fields

| Field | Description |
| - | - |
| `response.answer` | The prose answer, when the task produced one |
| `response.structured` | The answer in `output_schema`, when one was sent |
| `response.steps` | The actions the provider reported, in order. Empty when the provider reports none |
| `response.outcome` | `complete`, or `partial` when the provider stopped early |

## Job states and errors

| `state` | Meaning |
| - | - |
| `queued`, `running` | Still working. Poll again. |
| `completed` | Done. Read `result.response`. |
| `failed` | Stopped on an error. |
| `cancelled` | Stopped by a cancel. |

* **`502` or `504` on a poll:** the provider did not answer that poll. The task goes on, so poll again.
* **`410` on a poll:** the provider no longer knows the task. Read answers soon after a task completes.
* **Cancel:** `POST /v2/web-router/browse/{job_id}/cancel` stops the task and returns it as it stands. A stopped task cannot be resumed.

## Next Steps

> [card] [Research](https://docs.nimbleway.com/nimble-sdk/web-router/research.md)
>
> Answer questions across many sources, with citations

> [card] [API Reference](https://docs.nimbleway.com/api-reference/webrouter/start-browse.md)
>
> Every field of the request and response


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