Tutorial

Build an Autonomous Agent That Finishes a Task with /v1/runs

James Liu||8 min
Pg Up

You want a single API call that launches an agent, watches it navigate a desktop, browser, or terminal, and tells you when the task succeeds or fails. The /v1/runs endpoint is exactly that. It provisions a cloud machine, starts the computer use agent, and streams state updates until the agent finishes or you cancel it. No manual loop of capture, predict, and act required.

How /v1/runs works

POST to https://coasty.ai/v1/runs with a machine_id, a task, and a cua_version. The agent drives the real desktop and returns actions like clicks, scrolls, and key presses. The server streams events including step count, current state, and final status. You can add instructions to the base prompt, set a deadline, and configure behavior when the agent awaits human input. Each agent step costs $0.05.

bash
curl -X POST https://coasty.ai/v1/runs \
  -H "X-API-Key: $COASTY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "machine_id": "pm-12345",
    "task": "open chrome, navigate to coasts.ai, search for computer use API, click the first result",
    "cua_version": "v4",
    "instructions": "use the latest Chrome in the VM",
    "max_steps": 100,
    "deadline_seconds": 300,
    "on_awaiting_human": "pause"
  }'

Key request fields

  • machine_id: the cloud VM ID to drive
  • task: plain language description of the goal
  • cua_version: v3 for guided mode, v4 for autonomous with pass/fail verifier
  • instructions: additional text to append to the base prompt
  • max_steps: maximum agent steps before timing out internally
  • deadline_seconds: overall deadline for the run
  • on_awaiting_human: pause, fail, or cancel when the agent asks for human input

Response and streaming events

The initial response is an object with an id, status (queued or running), and a URL for streaming events. Use GET /v1/runs/{id} to fetch the latest state and GET /v1/runs/{id}/events to stream real-time updates. Events include step_number, current_state (queued, running, awaiting_human, succeeded, failed, cancelled, timed_out), and optional payloads. Reconnect using the Last-Event-ID header if you restart the stream.

Each agent step on /v1/runs costs $0.05 and the server handles step counting and verification.

Where this beats brittle automation

Traditional desktop automation relies on brittle selectors, DOM IDs, and fixed coordinates. If a UI changes, your scripts break. A computer use agent sees the screen like a human does, understands context, and adapts. It can handle dynamic layouts, popups, and unexpected states. You describe what you want, not how to click a specific button.

Start by sending a task to /v1/runs and watch events stream. Try a browser automation task, then a terminal command sequence, and finally a multi-step workflow. Get your API key at https://coasty.ai/developers and integrate the computer use agent into your next project.

Want to see this in action?

View Case Studies
Try Coasty Free