Skip to main content

When to Use REST API

The REST API is ideal for:
  • Serverless environments (AWS Lambda, Vercel, Cloudflare Workers)
  • Simple integrations where you don’t need real-time events
  • Stateless workflows that poll for results
  • Backend services that trigger automation tasks
  • Workflow automation (n8n, Make.com, Zapier)
Choose WebSocket instead if you need:
  • Live agent thoughts and reasoning
  • Sub-second event notifications
  • Real-time UI updates

Authentication

All API requests require Bearer token authentication:
Get your API key at webrun.ai/settings Base URL:

Basic Patterns

Pattern 1: Single Task (run-task)

The simplest pattern for one-off tasks. Session auto-terminates after completion.
Response (completed within 50 seconds):
Response (still running after 50 seconds):
Most browser tasks complete in 10-40 seconds. The API waits up to 50 seconds before responding, so typical requests return results immediately: no polling required.

Pattern 2: Multi-Task Session

For workflows that require multiple sequential tasks in the same browser session. Step 1: Create persistent session
Response:
Step 2: Send follow-up task
Cost Tip: Set terminateOnCompletion: true on your last task to auto-close the session and avoid idle charges. Sessions remain billable until terminated or timed out.

Pattern 3: Polling for Results

When a task returns status: "pending", poll until completion:

Complete Examples

Example 1: Simple Task Execution


Example 2: Multi-Step Workflow


Example 3: Using a Proxy

Route traffic through a proxy for geographic targeting or IP management. The proxy field is top-level, alongside environmentId:
See the Proxies guide for custom proxy configuration and best practices.

Example 4: Using an Environment

Attach an environment to reuse saved cookies and login sessions across tasks:

Example 5: Authenticated Task with Secrets

Use secrets to provide credentials upfront so the agent can authenticate without guardrail interruptions:

Example 6: Handling Guardrails


Session Control

Control task execution with state commands:

Pause Task

Resume Task

Stop Task

Terminate Session


Error Handling

All errors follow this format:

Common Error Codes

Error Handling Example