Back to Blog
Tutorial

Rachel Kim9 min
+Tab

One night a developer at Coasty needed to process 200 order forms across a dozen sites. Using only API calls and static selectors, the script failed after a few rows because of layout shifts, hidden fields, and CAPTCHAs. They switched to a computer use agent that watches the screen, clicks, types, and scrolls like a human. That agent finished the job in under five minutes with near-zero maintenance. In this post, you will see how to build that same pattern with the Coasty Computer Use API.

How Form Filling and Checkout Work Over the API

The core idea is a loop. The agent sends a screenshot of the current desktop to the /v1/runs endpoint. The server runs a CUA agent (v4 by default) that looks at the visual state, follows your instructions, and produces an action. You stream those actions and keep sending screenshots until the run completes. The key fields you need are machine_id, task, cua_version, and optional instructions. The server drives real desktops and browsers, so the agent can see input fields, dropdowns, and button states that APIs hide.

bash
#!/usr/bin/env bash
# Example: POST /v1/runs to fill a checkout form and complete the purchase

COASTY_API_KEY="${COASTY_API_KEY}"

# Start a cloud desktop (optional; the /v1/runs endpoint can also drive browsers directly)
curl -s -X POST https://coasty.ai/v1/machines \
  -H "X-API-Key: $COASTY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "machine_type": "browser",
    "os": "linux",
    "image": "latest"
  }' | jq -r '.id' > machine_id.txt

MACHINE_ID=$(cat machine_id.txt)

# Start the checkout run
RUN_ID=$(curl -s -X POST https://coasty.ai/v1/runs \
  -H "X-API-Key: $COASTY_API_KEY" \
  -H "Content-Type: application/json" \
  -d "{
    \"machine_id\": \"$MACHINE_ID\",
    \"task\": \"Navigate to https://example.com/cart and complete checkout.\",
    \"cua_version\": \"v4\",
    \"max_steps\": 100,
    \"deadline_seconds\": 300,
    \"instructions\": \"Fill the email field with [email protected], the password field with a secure password, and click the Checkout button.\",
    \"on_awaiting_human\": \"pause\"
  }" | jq -r '.id')

echo "Run started with ID: $RUN_ID"

# Wait for completion and stream events
while true; do
  EVENTS=$(curl -s "https://coasty.ai/v1/runs/$RUN_ID/events" \
    -H "X-API-Key: $COASTY_API_KEY" \
    -H "Accept: text/event-stream" \
    --no-buffer)

  if echo "$EVENTS" | grep -q "data: {\"status\": \"done\"}"; then
    echo "Run finished successfully."
    break
  fi

  # Optional: decode and print events for debugging
  echo "$EVENTS" | grep "data:" | jq -r '.data' 2>/dev/null || echo "$EVENTS"
  sleep 1
done

Key Fields and Pricing for Checkout Flows

  • machine_id: The cloud machine ID you start with POST /v1/machines. This lets the server drive a real desktop or browser session.
  • task: A natural-language instruction describing the checkout goal. The CUA agent interprets it and produces actions.
  • cua_version: Use "v4" for an autonomous agent with a pass/fail verifier, or "v3" for a simpler agent. Default is "v3".
  • instructions: Optional extra guidance appended to the base prompt, such as 'fill the email field with [email protected]'.
  • max_steps: Maximum number of agent steps. Each step costs $0.05. A typical checkout flow rarely exceeds 20, 40 steps.
  • deadline_seconds: How long the run is allowed to run before timing out.
  • on_awaiting_human: What to do when the agent asks for human input, pause, fail, or cancel the run.
  • The server streams events via GET /v1/runs/{id}/events. Include Last-Event-ID on reconnects for resumable streaming.

Each agent step you pay $0.05. Typical checkout flows are 20, 40 steps, so you can expect $1, 2 per order, including the $0.10 session and $0.05 per predict call for vision.

Where This Beats Brittle Automation

API-only tools and static selectors break when layouts shift, CAPTCHAs appear, or hidden fields change. A computer use agent processes live screenshots, so it can see a button that is partially visible, a password field that appears only after scrolling, or a CAPTCHA that requires human-like interaction. It can also navigate to arbitrary URLs, switch tabs, and handle dynamic content. This makes it ideal for checkout flows that depend on site behavior, not just static HTML.

Next Steps

You can extend this pattern to batch processing, A/B testing checkout flows, or integrating with order management systems via webhooks. Start building now by getting a key at https://coasty.ai/developers. With the Computer Use API, you can drive real desktops and browsers over HTTP and automate form filling and checkout flows with human-like reliability.

© 2026 Coasty

Backed byYCombinator