Skip to main content
WebRun charges for session time and token usage. Three quick changes can cut your costs by 50% or more.

Quick Wins

1. Terminate Sessions Explicitly

Set terminateOnCompletion: true on your final task, or call terminate explicitly. This alone reduces costs by 50% if you’re currently letting sessions timeout.
// Single task - auto-terminates
const result = await fetch("https://connect.webrun.ai/start/run-task", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "Authorization": `Bearer ${API_KEY}`
  },
  body: JSON.stringify({
    taskDetails: "Extract data from this page"
  })
});

// Multi-task - terminate on last task
const finalTask = await fetch("https://connect.webrun.ai/start/send-message", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "Authorization": `Bearer ${API_KEY}`
  },
  body: JSON.stringify({
    sessionId,
    message: {
      actionType: "newTask",
      taskDetails: "Final task here",
      terminateOnCompletion: true
    }
  }
});

2. Write Concise Task Descriptions

Shorter descriptions = fewer input tokens. Be specific, not verbose. Verbose (150 tokens):
"Please navigate to the Amazon website and then perform a search for wireless keyboards. After you get the results, I need you to look through them carefully and find the ones that have good ratings, preferably above 4 stars, and then return me a list of the top 5 products with their titles, prices, and rating information."
Concise (35 tokens):
"Go to Amazon, search 'wireless keyboard'. Return top 5 with rating ≥ 4.0 as JSON: title, price, rating."
Impact: 75% reduction in input tokens for this task.

3. Set startingPoint When Known

Skip navigation by providing the starting URL directly.
{
  "mode": "default",
  "initialTask": {
    "taskDetails": "Search for products",
    "startingPoint": "https://amazon.com"  // Skips "go to amazon.com" step
  }
}
Impact: Saves 5-10 seconds and ~500-1000 tokens per task.

Additional Optimizations

Set Appropriate maxDuration

Limit task duration to prevent runaway costs:
{
  "taskDetails": "Quick search task",
  "maxDuration": 30000  // 30 seconds max task duration
}
Guidelines:
  • Simple searches: 30,000ms (30s)
  • Form filling: 60,000ms (1 min)
  • Multi-step workflows: 120,000ms (2 min)

Reuse sessions for related tasks instead of creating new ones. Expensive:
await runTask("Go to amazon.com");      // New session
await runTask("Search for keyboards");  // Another new session
await runTask("Get first result");      // Yet another session
Optimized:
const session = await startSession("Go to amazon.com");
await sendTask(session, "Search for keyboards");
await sendTask(session, "Get first result", { terminateOnCompletion: true });
Impact: 3x reduction in session overhead costs.

Limit Token Usage

For simple tasks, reduce token limits:
{
  "taskDetails": "Get product price",
  "maxInputTokens": 10000,   // Lower for simple tasks (default: 100000)
  "maxOutputTokens": 1000    // Lower for short responses (default: 100000)
}

Use avoidDomains to Prevent Detours

Block unnecessary domains to prevent wasted navigation:
{
  "taskDetails": "Research this topic",
  "avoidDomains": ["facebook.com", "twitter.com", "ads.example.com"]
}

Monitoring Costs

Real-time: Check usage.cost in every API response.
{
  "success": true,
  "sessionId": "abc123",
  "taskId": "xyz789",
  "type": "task_completed",
  "data": {
    "message": "Task completed successfully"
  },
  "usage": {
    "prompt_tokens": 12450,
    "completion_tokens": 3200,
    "total_tokens": 15650,
    "completion_time": 23.5,
    "cost": 0.0124
  }
}
Dashboard: View historical usage at app.webrun.ai/usage. During polling: The usage object updates in real-time as tasks execute.

Cost Optimization Checklist

  • Use /start/run-task for single tasks (auto-terminates)
  • Set terminateOnCompletion: true on final tasks in multi-task workflows
  • Write concise, specific task descriptions
  • Provide startingPoint when the starting point is known
  • Set appropriate maxDuration based on task complexity
  • Batch related tasks into single sessions
  • Limit maxInputTokens and maxOutputTokens for simple tasks
  • Use avoidDomains to prevent accidental navigation
  • Monitor usage.cost in responses to track spending

Example: Before & After

Before: Expensive
// Creates 3 separate sessions
const result1 = await runTask("Go to amazon.com");
await sleep(5000); // Forgot to terminate, paying for idle time
const result2 = await runTask("Please navigate to the search box and then type in 'wireless keyboard' and press enter");
await sleep(5000);
const result3 = await runTask("Get me information about the first result");
After: Optimized
// Single session, concise tasks, explicit termination
const session = await startSession({
  mode: "default",
  initialTask: {
    taskDetails: "Go to amazon.com",
    startingPoint: "https://amazon.com",
    maxDuration: 60000  // 1 minute max
  }
});

await sendTask(session, "Search 'wireless keyboard'");

await sendTask(session, "Return first result as JSON: title, price, rating", {
  terminateOnCompletion: true
});
Savings: ~70% cost reduction from session reuse, concise prompts, and explicit termination.