Back to Blog
Tutorial

Emily Watson8 min
+K

Classic web automation stacks fetch a page, find an element by selector, and click it. That pattern fails when UIs change, elements shift, or you need multi-step workflows with intermediate state like form filling or navigation. The computer use API lets agents see the screen and act like a human. You can either make one-shot predictions with vision or manage a stateful session that carries trajectory memory. The choice changes how you pay, how you model your agent, and how robust your automation becomes.

How it works

The stateless predict endpoint runs a single vision inference. You send a base64 screenshot, an instruction, and a cua_version, and you get a list of actions and a status. You repeat capture, predict, act until the status is done. This model is simple but stateless, so each call sees only the current frame. The stateful session endpoint first creates a session, then you send a predict request scoped to that session. The server stores the trajectory memory from previous steps, so later predictions can use that context. Both endpoints send actions in the same format and both return a status field. The key difference is that a session persists state across calls, while a one-shot predict does not.

bash
curl -X POST https://coasty.ai/v1/sessions \ 
  -H "X-API-Key: $COASTY_API_KEY" \ 
  -H "Content-Type: application/json" \ 
  -d '{"machine_id": "my-machine", "cua_version": "v4"}'
python
import base64
import requests
import os

api_key = os.getenv("COASTY_API_KEY")
base_url = "https://coasty.ai/v1"

# Create a stateful session
resp = requests.post(
    f"{base_url}/sessions",
    headers={"X-API-Key": api_key},
    json={
        "machine_id": "my-machine",
        "cua_version": "v4",
    },
)
resp.raise_for_status()
session = resp.json()
session_id = session["id"]
print("Session ID:", session_id)

# Helper to encode a screenshot to base64
with open("screenshot.png", "rb") as f:
    img_b64 = base64.b64encode(f.read()).decode()

# Predict within the session
predict_url = f"{base_url}/sessions/{session_id}/predict"
resp = requests.post(
    predict_url,
    headers={"X-API-Key": api_key},
    json={
        "screenshot": img_b64,
        "instruction": "click the submit button",
        "cua_version": "v4",
    },
)
resp.raise_for_status()
result = resp.json()
print("Actions:", result["actions"])
print("Status:", result["status"])

Key differences

  • Stateless predict costs $0.05 per inference and returns actions plus a status. You own the loop.
  • Stateful sessions first POST /v1/sessions with machine_id and cua_version. Predict calls are $0.04 each within a session.
  • Stateless predict carries no trajectory memory between calls. Each prediction sees only the current screenshot.
  • Stateful sessions store trajectory memory, so later predictions can reason about prior steps and maintain context across multi-step workflows.
  • Both endpoints return an actions list and a status field. The difference is where memory lives: in your code for stateless, or on the server for stateful.

Use stateful sessions when you need multi-step workflows that depend on previous steps. Use stateless predict only for one-shot tasks where you control the loop and do not need server-side memory.

Where this beats brittle automation

Traditional automation relies on selectors like CSS paths or XPath to locate elements. When UIs change, those selectors break, forcing you to re-crawl your selectors or maintain many fallbacks. The computer use API lets agents see the screen and generate action sequences from raw pixels. Stateful sessions let agents remember where they are in a workflow, so they can fill forms, navigate through multi-step wizards, and recover from UI shifts without you changing your automation code. You also get server-side trajectory memory, which is useful when you want to pause a run, resume it later, or stream events to a webhook. The result is automation that adapts to visual changes instead of breaking when selectors become stale.

Stateful sessions and stateless predict both give you a computer use agent powered by vision, but stateful sessions are the right choice for multi-step, context-rich workflows. Start with a stateless predict for simple tasks, then move to sessions for complex automation. Get your API key and start building at https://coasty.ai/developers .

© 2026 Coasty

Backed byYCombinator