Tutorial

Automating Form Filling and Checkout Flows with the Computer Use API

Priya Patel||6 min
+Enter

Checkout flows are fragile. Forms change, CAPTCHAs appear, and button labels shift. Traditional automation relies on brittle selectors that break often. The Coasty Computer Use API gives you a computer use agent that sees the UI and acts like a human, making form filling robust and maintainable.

How it works

You create a task run on a real machine using POST /v1/runs. The agent receives a screenshot, an instruction, and the current state, then returns a list of actions such as click, type, and scroll. The server drives the desktop, and you poll for events until the task succeeds or fails. The computer use API charges $0.05 per agent step, giving you predictable, per-action billing.

bash
#!/bin/bash

# Create a task run that fills a checkout form using the Computer Use API
# Replace YOUR_MACHINE_ID with a real machine ID from /v1/machines

export COASTY_API_KEY=$(cat ~/.coasty_key)
machine_id="YOUR_MACHINE_ID"

# Create a task run
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": "'"$machine_id"'",
    "task": "Fill the checkout form on https://example.com/checkout with the following details and complete the purchase. Use the email [email protected] and the shipping address 123 Main St, City, State, ZIP."
  }')

echo "Response: $response"

# Extract the run ID
run_id=$(echo $response | jq -r '.id')

# Poll for events until the run finishes
while true; do
  events=$(curl -s -X GET "https://coasty.ai/v1/runs/$run_id/events" \
    -H "X-API-Key: $COASTY_API_KEY")
  
  echo "Events: $events"
  
  # Check for terminal states
  status=$(echo $events | jq -r '.runs[0].status')
  echo "Current status: $status"
  
  if [[ "$status" == "succeeded" ]] || [[ "$status" == "failed" ]] || [[ "$status" == "cancelled" ]] || [[ "$status" == "timed_out" ]]; then
    break
  fi
  
  # Sleep before the next poll
  sleep 2
done

echo "Run $run_id finished with status $status"

Key parameters for reliable checkout automation

  • machine_id: The ID of a provisioned machine from POST /v1/machines that runs a real browser or desktop session.
  • task: Clear, natural language instructions that describe the form fields, values, and desired outcome.
  • cua_version: Set to "v3" for controlled automation or "v4" for autonomous runs with a pass/fail verifier.
  • instructions: Optional extra instructions appended to the base prompt, useful for CAPTCHA handling or special input methods.
  • max_steps: Limits the number of agent steps to avoid runaway runs; each step costs $0.05.
  • deadline_seconds: Optional deadline, after which the run times out.
  • on_awaiting_human: Set to "pause", "fail", or "cancel" when the agent encounters a human approval step.

Each agent step costs $0.05, so design your task to minimize unnecessary actions and focus on the checkout sequence.

Where this beats brittle automation

Traditional automation tools depend on CSS selectors, XPath, or fixed DOM structures. When a site changes a class name or reorders fields, your scripts break. The computer use agent sees the screen, recognizes the button, and clicks it regardless of implementation changes. It can handle dynamic forms, CAPTCHAs, and unexpected UI layouts, making checkout automation resilient to site updates.

Next steps

Start by provisioning a machine with POST /v1/machines, then create a checkout task run with POST /v1/runs. Poll the events stream with GET /v1/runs/{id}/events to monitor progress. For more complex workflows, explore POST /v1/workflows to orchestrate multiple steps, asserts, and conditional logic. You can also use the MCP server to drive Coasty from Cursor or Claude Desktop. Get your API key at https://coasty.ai/developers and build robust, human-like automation.

Want to see this in action?

View Case Studies
Try Coasty Free