Tutorial

Automating Form Filling and Checkout Flows Over the API

Priya Patel||8 min
+Tab

You want to fill a multi-step checkout, capture input fields, handle validation states, and submit the order automatically. Traditional tools rely on IDs or XPath selectors, which break when a site updates a class name. A computer use agent reads the screen and acts like a human, so it works even when the DOM changes.

How it works

You send a task and an optional system prompt to POST /v1/runs. The server provisions a machine, starts a browser, and runs an agent that loops until it reaches a terminal state. Each loop is a step billed $0.05. The agent sees the current screenshot, predicts actions, and performs them. Events stream back as Server-Sent Events so you can monitor progress in real time. The response includes the run state (queued, running, awaiting_human, succeeded, failed, cancelled, timed_out) and an events endpoint you can poll with GET /v1/runs/{id}.

bash
#!/usr/bin/env bash

COASTY_API_KEY="${COASTY_API_KEY}"

TASK='Fill the checkout form on example.com, type the email and address details, and submit the order'

# POST /v1/runs creates a task run with a default CUA version v3
RESPONSE=$(curl -s -X POST https://coasty.ai/v1/runs \
  -H "Authorization: Bearer ${COASTY_API_KEY}" \
  -H "Content-Type: application/json" \
  -d '{
    "machine_id": "dev-mac-01",
    "task": "'"${TASK}"'",
    "cua_version": "v3"
  }')

RUN_ID=$(echo "$RESPONSE" | jq -r '.run.id')
echo "Created run $RUN_ID"

# Stream events from GET /v1/runs/{id}/events
while true; do
  EVENTS=$(curl -s -N "https://coasty.ai/v1/runs/${RUN_ID}/events" \
    -H "Authorization: Bearer ${COASTY_API_KEY}" \
    --compressed \
    --retry 0)

  echo "$EVENTS"

  # Stop when the run is done
  STATE=$(echo "$EVENTS" | jq -r 'last | .run.status // empty')
  if [[ "$STATE" == "succeeded" || "$STATE" == "failed" || "$STATE" == "cancelled" ]]; then
    break
  fi
  sleep 1
done

Key fields and pricing

  • POST /v1/runs requires machine_id, task, and cua_version (default v3).
  • You may set instructions to append to the base prompt, max_steps to limit iterations, and deadline_seconds to enforce a timeout.
  • You can pass on_awaiting_human as pause, fail, or cancel when the agent encounters a human approval step.
  • Each agent step costs $0.05.
  • The events endpoint streams run events; use Last-Event-ID to reconnect after a disconnect.
  • States include queued, running, awaiting_human, succeeded, failed, cancelled, timed_out.

One run ID and a loop reading events is all you need to drive a checkout to completion.

Where this beats brittle automation

Browser automation with selectors breaks when a site changes class names or layout. A computer use agent reads pixels and observes the current state, so it can handle unexpected layouts, dynamic validation errors, and human approval prompts without brittle selectors. You can also run it on desktop apps or native UIs, not just browsers.

Start automating checkout flows and other multi-step tasks with a computer use agent. Get an API key at https://coasty.ai/developers and try the example above.

Want to see this in action?

View Case Studies
Try Coasty Free