Automating Form Filling and Checkout Flows with the Coasty Computer Use API
Checkout flows are the hardest part of web automation. They live in a moving DOM, race with dynamic prices, and often require human-like choices. Traditional tools rely on brittle selectors that break on layout shifts or missing IDs. The Coasty Computer Use API changes that. It gives you a computer use agent that sees the screen, understands context, and acts like a human. You drive it over a REST API. This guide shows how to automate form filling and checkout flows with real code.
How it works
You start by provisioning a machine to host the agent. POST /v1/machines creates a cloud VM you can start and stop. The agent runs on that machine and can control a real desktop, browser, or terminal. Then you create a task run with POST /v1/runs. You provide a task description like 'fill the shipping form and complete checkout', the cua_version (v3 or v4), and any extra instructions. The server streams events via GET /v1/runs/{id}/events. When the status is 'succeeded', the checkout completed. Billed at $0.05 per agent step. No up-front API keys for each action. Just a prepaid wallet where 1 credit equals $0.01.
import os
import requests
import json
from time import sleep
COASTY_API_KEY = os.getenv("COASTY_API_KEY")
BASE_URL = "https://coasty.ai/v1"
HEADERS = {
"Authorization": f"Bearer {COASTY_API_KEY}",
"Content-Type": "application/json"
}
def create_machine():
resp = requests.post(
f"{BASE_URL}/machines",
headers=HEADERS,
json={"name": "checkout-agent-machine"}
)
resp.raise_for_status()
return resp.json()
def start_run(machine_id, task, cua_version="v3", extra_instructions=None):
body = {
"machine_id": machine_id,
"task": task,
"cua_version": cua_version,
"max_steps": 100,
"deadline_seconds": 600
}
if extra_instructions:
body["instructions"] = extra_instructions
resp = requests.post(
f"{BASE_URL}/runs",
headers=HEADERS,
json=body
)
resp.raise_for_status()
return resp.json()
def stream_events(run_id):
url = f"{BASE_URL}/runs/{run_id}/events"
resp = requests.get(url, headers=HEADERS, stream=True)
resp.raise_for_status()
for line in resp.iter_lines():
if line:
data = json.loads(line.decode("utf-8"))
yield data
def main():
# Provision a machine for the agent
machine = create_machine()
machine_id = machine["id"]
print(f"Machine provisioned: {machine_id}")
# Define the task and extra instructions
task = "fill the shipping form and complete checkout"
extra_instructions = (
"Select the first option from the dropdown, enter your name as 'John Doe', "
"enter a valid email, and click the final checkout button."
)
# Start the task run
run = start_run(machine_id, task, cua_version="v3", extra_instructions=extra_instructions)
run_id = run["id"]
print(f"Task run started: {run_id}")
# Stream status updates and actions
for event in stream_events(run_id):
status = event.get("status")
print(f"Event: {event}")
if status in ("succeeded", "failed", "cancelled", "timed_out"):
print(f"Run finished with status: {status}")
break
sleep(1)
if __name__ == "__main__":
main()Key configuration fields
- ●machine_id: returns from POST /v1/machines and tells the run which cloud VM to use
- ●task: natural language description of the form filling and checkout flow
- ●cua_version: 'v3' for guided runs, 'v4' for autonomous runs with a pass/fail verifier
- ●instructions: optional text appended to the base prompt, useful for behavior constraints
- ●max_steps: limit steps to avoid runaway loops, each step costs $0.05
- ●deadline_seconds: the server stops the run if no status change occurs within this window
- ●status: one of 'queued', 'running', 'awaiting_human', 'succeeded', 'failed', 'cancelled', 'timed_out'
- ●1 credit = $0.01, billed per agent step when you use the server-driven agent
Start with POST /v1/runs and stream events from GET /v1/runs/{id}/events. Each step costs $0.05, and status changes are the signal that your checkout flow finished.
Why this beats brittle automation
Traditional automation relies on static selectors like .btn-checkout, #email-input, or XPath expressions. Those break when a layout changes, a class is renamed, or the site adds a wrapper. Coasty does not know about attributes. It sees the screen exactly as a human does. It can read labels, understand context like 'click the button that says Finish', and adapt to unexpected changes. The API also gives you stateful trajectory memory via POST /v1/sessions/{id}/predict, so the agent can recall previous steps and avoid re-entering data. You do not need to maintain a complex selector database. You describe what you want and let the computer use agent handle the details.
What to build next
Once you have form filling and checkout flows working, you can extend them. Use POST /v1/workflows to compose multiple runs into a sequence that handles account creation, checkout, and post-order verification. Or switch to cua_version 'v4' for autonomous runs with a pass/fail verifier. Explore machines to host agents on different OS types or browsers. For more details and to get your API key, visit https://coasty.ai/developers.