Engineering

Human in the Loop Automation: Awaiting Human and Resume in the Runs API

Lisa Chen||7 min
F12

Most automation scripts break when they hit an unexpected UI element or need approval. A computer use agent can pause and ask a human, then resume exactly where it left off. The runs API adds awaiting_human and resume to the server-driven workflow. You specify on_awaiting_human in the initial run, the server sends events with state queued, running, or awaiting_human, and you call POST /v1/runs/{id}/resume to continue.

How it works

Create a run with on_awaiting_human set to pause or fail. The agent steps through tasks, bills $0.05 per step, and sends Server-Sent Events to your webhook_url. When the agent encounters an action that needs human input, its state becomes awaiting_human and the event stream shows the context. You inspect the event, call POST /v1/runs/{id}/resume with your approval, and the agent continues from that step. If you choose fail, the run ends and you must restart.

bash
#!/bin/bash

COASTY_API_KEY="${COASTY_API_KEY}"
BASE_URL="https://coasty.ai/v1"

# Start a run that pauses for human approval
curl -X POST "$BASE_URL/runs" \
  -H "Authorization: Bearer $COASTY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "machine_id": "cloud-vm-123",
    "task": "Find the approval button and click it, then fill the form",
    "cua_version": "v4",
    "on_awaiting_human": "pause",
    "webhook_url": "https://your-server.com/webhook",
    "max_steps": 50,
    "deadline_seconds": 600
  }' | jq '.'

# Then poll the run with GET /v1/runs or watch the SSE stream
# When state is awaiting_human, inspect the event details, then resume
curl -X POST "$BASE_URL/runs/{id}/resume" \
  -H "Authorization: Bearer $COASTY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "approval": true,
    "comment": "Approved: click the button and continue"
  }'

Key fields and states

  • on_awaiting_human: pause, fail, or cancel. Choose pause to keep the run alive and resume later.
  • cua_version: v3 for classic computer use, v4 for autonomous with a pass/fail verifier.
  • States include queued, running, awaiting_human, succeeded, failed, cancelled, timed_out.
  • Each agent step costs $0.05. Billed from a prepaid USD wallet where 1 credit is $0.01.
  • GET /v1/runs/{id}/events streams Server-Sent Events. Reconnect with Last-Event-ID on disconnect.
  • POST /v1/runs/{id}/cancel stops the run. POST /v1/runs/{id}/resume continues from the last step after human approval.

Set on_awaiting_human to pause, resume with approval to keep the workflow alive, and use the SSE stream to track state changes.

Where this beats brittle automation

Traditional scripts rely on CSS selectors, XPath, or fixed IDs. If a UI changes, the script breaks. A computer use agent sees the screen like a human. It can inspect buttons, read text, and adapt to layout changes. By pausing for human approval, it can handle edge cases, compliance checks, or multi-step approvals without breaking. The runs API manages the lifecycle and billing, so you only pay for steps that actually run.

Use awaiting_human and resume to build agents that pause for approval and continue autonomously. Combine this with workflows, machines, and the vision API to control real desktops, browsers, and terminals. Get your API key at https://coasty.ai/developers and start building resilient computer use workflows.

Want to see this in action?

View Case Studies
Try Coasty Free