Skip to main content

Overview

Session control commands allow you to manage task execution dynamically. You can pause tasks for inspection, resume them, stop the current task, or terminate the entire session. All control commands use the same endpoint but with different message payloads:

newTask

Start a new task in the current session. This is the only control action that returns a taskId for result tracking. Use REST for simple integrations, WebSocket for real-time event handling:
If the task completes within 50 seconds, you get the result inline:
For longer tasks, you receive a pollUrl to check status. Poll every 2-3 seconds until complete:
Set terminateOnCompletion: true on your final task to auto-close the session and avoid idle charges.

pause

Pause the current task. The agent will stop after completing its current action and wait for a resume command. Use cases:
  • Inspect the current state before continuing
  • Wait for external conditions to be met
  • Synchronize with other systems
Response:
The agent will complete its current action before pausing. It does not immediately halt mid-action.

resume

Resume a paused task. The agent will continue from where it left off.
Response:

stop

Stop the current task immediately. The session remains active and ready for new tasks. Difference from terminate:
  • stop: Ends the current task only, session stays active
  • terminate: Ends the entire session and all connections
Response:
When to use:
  • Task is taking too long
  • Task is heading in wrong direction
  • Need to intervene and start a different task
After stopping: You can immediately send a new task or manually interact with the browser before sending the next task.

terminate

End the session completely. This closes the browser instance and all connections (WebSocket, video stream).
Response:
Always terminate sessions when you’re done to avoid unnecessary charges. Idle sessions expire after 5 minutes of inactivity, but you should terminate explicitly to avoid unnecessary costs.

State Transitions

Understanding how session states work:

Cost Optimization Tips

1. Terminate Sessions Promptly

Don’t leave sessions idle. Terminate them as soon as your workflow completes:

2. Use stop to Intervene Early

If a task is taking too long or going off-track, stop it immediately:

3. Set Appropriate maxDuration

Limit task duration to prevent runaway costs:

4. Use pause for Inspection

Pause tasks to inspect state before continuing:

Control Flow Example

Complete example showing pause/resume/stop/terminate in action: