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

> ## Agent Instructions
> Anchor Browser is cloud browser infrastructure for AI agents and automation: browser sessions you control over CDP or REST, natural-language web tasks, versioned automation tasks, managed authentication into third-party web apps (identities with MFA), persistent volumes and profiles, recordings, live view, batch sessions, webhooks, and network options including residential proxies, extra stealth, and captcha solving for sites that block standard browsers. AI agents should start at https://docs.anchorbrowser.io/for-agents, then get an API key with Agent Access at https://docs.anchorbrowser.io/quickstart/agent-access — no dashboard account required. Read those two pages before authentication or API calls.

# Creating a Task

> Create reusable browser tasks from a demonstration or prompt.

## Overview

Automation Tasks are reusable browser automations you define once and run reliably in production. Anchor generates a versioned task from your input — combining deterministic automation with AI-assisted steps where needed.

<Card title="Automation Tasks Overview" icon="layer-group" href="/tasks/overview">
  Visual tour of prompts, demonstrations, the workflow UI, runs, editing, and self-healing.
</Card>

## Ways to create a task

| Method | Best for |
| - | - |
| [**Demonstration**](#create-from-a-demonstration) | Show the flow once in a live browser |
| [**Prompt**](#create-from-a-prompt) | Describe what the task should accomplish in natural language |

Both paths produce the same result: a task you can test and call from your application.

<CardGroup cols={2}>
  <Card title="Create from a demonstration" icon="video" href="#create-from-a-demonstration">
    Demonstrate a task in a live browser. Anchor captures your actions and builds a reusable task.
  </Card>

  <Card title="Create from a prompt" icon="message" href="#create-from-a-prompt">
    Describe what the task should accomplish. Anchor generates the task from your description.
  </Card>
</CardGroup>

## Create from a demonstration

Demonstrate a task in a live browser — navigate, click, fill forms, download files. As you work, Anchor captures every browser event and compiles them into **deterministic, repeatable code**.

### In the Anchor UI

<Steps>
  <Step title="Open the Tasks page">
    Go to [Tasks](https://app.anchorbrowser.io/tools) and click **Create Task**.
  </Step>

  <Step title="Set up identity and describe the task">
    The creation wizard walks you through four steps:

    1. **Identity** — enter the application URL (and an identity, if the task requires login).
    2. **Task Definition** — describe what the task should do in natural language.
    3. **Demonstration** — choose to demonstrate the task yourself.
    4. **Review** — confirm the task name, inputs, and outputs before saving.
  </Step>

  <Step title="Start the demonstration">
    On the **Demonstration** step, select the option to demonstrate the task manually, then click **Continue**.

    A live browser opens at your start URL. Perform the task — navigate, click, fill forms, download files. Anchor captures every browser event as you go.

    <Tip>
      **Pro tip:** Right-click anywhere to investigate elements or data. Those inspection moments give richer context to your final task.
    </Tip>
  </Step>

  <Step title="Finish and create the task">
    Click **Finish Demonstration** when you're done. Review the generated inputs and outputs on the **Review** step, then save the task.
  </Step>
</Steps>

### Shareable demonstrations

To collect a demonstration from someone who works outside your Anchor workspace, use the [Demonstrations API](/advanced/demonstrations-api) to issue a secure demonstration link. They complete the task in a hosted browser session; Anchor processes the session and delivers the generated task to your workspace.

<Card title="Demonstrations API" icon="video" href="/advanced/demonstrations-api">
  Create demonstration links, monitor session status, and retrieve the generated task.
</Card>

## Create from a prompt

Describe what the task should do. Anchor generates the automation from your `taskPrompt`.

<AccordionGroup>
  <Accordion title="How to structure your prompt">
    | Section | Include |
    | - | - |
    | **Objective** | What the task should accomplish |
    | **Start URL** | Where the browser opens |
    | **Inputs** | Runtime values as `{{parameter_name}}` |
    | **Steps** | Ordered actions, one per line |
    | **Output** | Fields to return when the task completes |

    **Example prompt**

    ```text theme={null}
    Objective: Export the monthly invoice report as a PDF.

    Start URL: https://www.princexml.com/samples/

    Inputs:
    - report_name (required): The report to export

    Steps:
    1. Open Reports
    2. Search for {{report_name}}
    3. Open the first matching result
    4. Click Export → PDF
    5. Wait 5 seconds after clicking the download
    6. Confirm the download completed

    Output: report_title, exported_file_name
    ```

    Add edge cases when they matter — e.g. "If no exact match is found, use the closest result."
  </Accordion>
</AccordionGroup>

### In the UI

1. Open [Tasks](https://app.anchorbrowser.io/tools) and click **Create Task**.
2. Enter a name and describe the task — what site to visit, what to click, what data to return.
3. Wait for generation to finish, then test with sample inputs.

### Via API

Call `POST /v2/tasks/generate`, then poll `GET /v2/tasks/{taskId}/generation-status` until `status` is `ready`.

<CodeGroup>
  ```javascript node.js theme={null}
  import { client } from 'anchorbrowser';

  client.setConfig({ auth: () => process.env.ANCHOR_API_KEY });

  const { data: { id: taskId } } = await client.post({
    url: '/v2/tasks/generate',
    body: {
      taskName: 'invoice-report-export',
      description: 'Export the monthly invoice report as a PDF',
      taskPrompt: `Objective:
  Export the monthly invoice report as a PDF.

  Start URL:
  https://www.princexml.com/samples/

  Inputs:
  - report_name (required): The report to export

  Steps:
  1. Open Reports
  2. Search for {{report_name}}
  3. Open the first matching result
  4. Click Export → PDF
  5. Wait 5 seconds after clicking the download
  6. Confirm the download completed

  Output:
  - report_title
  - exported_file_name`,
    },
  });

  let status;
  do {
    ({ data: { status } } = await client.get({ url: `/v2/tasks/${taskId}/generation-status` }));
    if (status === 'failed') throw new Error('Task generation failed');
    if (status !== 'ready') await new Promise((r) => setTimeout(r, 3000));
  } while (status !== 'ready');

  console.log('Task ready:', taskId);
  ```

  ```python python theme={null}
  import os
  import time
  from anchorbrowser import Anchorbrowser

  anchor_client = Anchorbrowser(api_key=os.getenv('ANCHOR_API_KEY'))

  response = anchor_client.tasks.generate_task(
      task_name='invoice-report-export',
      description='Export the monthly invoice report as a PDF',
      task_prompt="""Objective:
  Export the monthly invoice report as a PDF.

  Start URL:
  https://www.princexml.com/samples/

  Inputs:
  - report_name (required): The report to export

  Steps:
  1. Open Reports
  2. Search for {{report_name}}
  3. Open the first matching result
  4. Click Export → PDF
  5. Wait 5 seconds after clicking the download
  6. Confirm the download completed

  Output:
  - report_title
  - exported_file_name""",
  )
  task_id = response.id

  while True:
      status_response = anchor_client.tasks.get_task_generation_status(task_id)
      status = status_response.status
      if status == 'failed':
          raise RuntimeError('Task generation failed')
      if status == 'ready':
          break
      time.sleep(3)

  print('Task ready:', task_id)
  ```
</CodeGroup>

**Optional fields** on `POST /v2/tasks/generate`:

| Field | Purpose |
| - | - |
| `application_id` | Tie the task to a managed application |
| `identity_id` | Pre-authenticate with a saved identity |
| `input_schema` / `output_schema` | Define typed inputs and outputs up front |
| `human_intervention` | Allow the task to pause for human input |
| `retries` | Retry a failed run on a new browser, `0` to `3`. Defaults to `0`. See [Retries](/tasks/run-a-task#retries). |
| `task_browser_default_configuration` | Default browser session settings for runs |

## Next steps

* [Run a Task](/tasks/run-a-task) — execute a task via API with inputs, identity, and session options
* [Which task type?](/tasks/which-task-type) — compare Automation Tasks with Perform Web Task
* [Demonstrations API](/advanced/demonstrations-api) — shareable links for demonstrating a task
* [Task Examples](/examples/task-examples) — browse ready-made tasks in the library


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