Engineering

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

Michael Rodriguez||6 min
+Enter

Most automation scripts either run to completion or crash when they need an approval. You spend time building brittle selectors to pause for a human, then write custom logic to resume. The Coasty Runs API solves this with a built-in awaiting_human state. When your agent hits a point that needs review, the run enters awaiting_human and streams events so you can pause, ask for input, and resume with a simple POST /v1/runs/{id}/resume call. This keeps your workflow stateful and reliable without hacks.

How the awaiting_human and resume flow works

Start a task by POSTing /v1/runs with your machine_id, task, and a few options. Set on_awaiting_human to "pause" (the default) and include a webhook_url if you want notifications. The runs API runs the computer use agent behind the scenes, sending Server-Sent Events for each step. When the agent encounters a situation that requires human judgment, the run transitions to the awaiting_human state and emits an event. You then call POST /v1/runs/{id}/resume with your human input to continue. The agent picks up exactly where it left off, keeping the trajectory in memory. This is billed $0.05 per agent step.

bash
#!/bin/bash
# Start a run that will pause for human approval
# Replace YOUR_MACHINE_ID with a valid machine ID
COASTY_API_KEY="${COASTY_API_KEY}"
KEY_HEADER="X-API-Key: $COASTY_API_KEY"

RUN_RESPONSE=$(curl -s -X POST https://coasty.ai/v1/runs \
  -H "$KEY_HEADER" \
  -H "Content-Type: application/json" \
  -d '{
    "machine_id": "YOUR_MACHINE_ID",
    "task": "Open Chrome, navigate to https://coasty.ai, sign in, and submit a contact form",
    "cua_version": "v4",
    "on_awaiting_human": "pause",
    "webhook_url": "https://example.com/webhook"
  }')

RUN_ID=$(echo "$RUN_RESPONSE" | jq -r '.id')
echo "Run ID: $RUN_ID"
bash
# Stream runtime events and watch for awaiting_human
curl -s -N -H "$KEY_HEADER" \
  https://coasty.ai/v1/runs/$RUN_ID/events | while IFS= read -r line; do
  if [[ "$line" == *"awaiting_human"* ]]; then
    echo "Human approval requested. Run ID: $RUN_ID"
    # At this point, pause your process, request input, then resume
  fi
done
bash
# Resume the run after human input
curl -s -X POST https://coasty.ai/v1/runs/$RUN_ID/resume \
  -H "$KEY_HEADER" \
  -H "Content-Type: application/json" \
  -d '{
    "comment": "Approved. Continue to the next step."
  }'

Key fields and behaviors

  • on_awaiting_human: Set to 'pause' to enter awaiting_human when the agent needs input. Options are 'pause', 'fail', or 'cancel'.
  • cua_version: Use 'v4' for autonomous runs with a pass/fail verifier that can also wait for human approval.
  • webhook_url: Optional URL to receive notifications about run state changes, including awaiting_human.
  • States: queued, running, awaiting_human, succeeded, failed, cancelled, timed_out.
  • Pricing: Runs are billed $0.05 per agent step. Trajectory memory is included in the session cost.

Always read COASTY_API_KEY from the environment and set on_awaiting_human to "pause" to enter awaiting_human and resume later.

Why this beats brittle automation

Traditional automation leans on CSS selectors, XPath, or hardcoded IDs. When a page layout changes, your script breaks. The computer use agent sees the screen like a human, so it can follow visible buttons, fill forms, and wait for dynamic content. By using awaiting_human, you get a reliable checkpoint that the API signals, not a fragile polling loop. This keeps your workflows robust and easier to maintain.

Use awaiting_human and resume to build workflows that pause for approvals without brittle selectors. Combine this with vision-based prediction to handle real browsers and desktops. Get your key and start building at https://coasty.ai/developers.

Want to see this in action?

View Case Studies
Try Coasty Free