Guide

Build an Autonomous Agent Using /v1/runs

James Liu||7 min
End

Most automation relies on brittle selectors or thin APIs. You want a system that sees the screen, understands intent, and clicks like a human. The /v1/runs endpoint lets you submit a task and let Coasty run a complete agent until success, failure, or cancellation. The server handles vision, planning, and low-level actions. You just watch events and pay per agent step.

How /v1/runs works

POST /v1/runs starts a task run. You provide a machine_id (a cloud VM you provision), a task description, and optional instructions. You can specify cua_version (v3 or v4), max_steps, deadline_seconds, and how to handle waiting for human input (pause, fail, or cancel). The server returns an id and initial state. You then stream events to track progress. The agent runs until success, failure, cancellation, or timeout. Each agent step is billed $0.05.

bash
#!/usr/bin/env bash
export COASTY_API_KEY

TASK="Open Chrome, navigate to coasty.ai, click the Get Started button, and verify the page title contains 'Computer Use API'."
max_steps=100
deadline_sec=600

response=$(curl -s -X POST https://coasty.ai/v1/runs \
  -H "X-API-Key: $COASTY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "machine_id": "vm-12345",
    "task": "'"$TASK"'",
    "cua_version": "v4",
    "max_steps": '"$max_steps"',
    "deadline_seconds": '"$deadline_sec"',
    "on_awaiting_human": "pause",
    "system_prompt": "You are a helpful assistant that completes tasks on a desktop.",
    "webhook_url": null
  }')
echo "$response"

Run and stream events

  • Use GET /v1/runs/{id}/events with SSE to watch each action and state change.
  • Reconnect using Last-Event-ID header on disconnects.
  • States include queued, running, awaiting_human, succeeded, failed, cancelled, timed_out.
  • Each agent step is billed $0.05 regardless of action type.

POST /v1/runs starts the agent; GET /v1/runs/{id}/events streams progress.

Where this beats brittle automation

Traditional automation relies on stable selectors, versioned APIs, and brittle heuristics. If a UI changes, your script breaks. With the computer use API, the agent sees the actual screenshot, interprets context, and plans actions accordingly. It can handle dynamic elements, window management, and multi-step workflows without hard-coded CSS selectors. The server steps are billed per agent action, not per HTTP request, giving you predictable cost for complex processes.

You can now spin up a real desktop, browser, or terminal, hand off a task to an autonomous agent, and stream progress via SSE. From there, integrate workflows, retry policies, and human approval gates. Get your API key at https://coasty.ai/developers and start building agents that see and act like humans.

Want to see this in action?

View Case Studies
Try Coasty Free