Brute-force automation that clicks the same button ID every time breaks when UIs change. The Coasty Computer Use API solves this by letting agents see the screen and act like humans. Two patterns exist: stateless predict and stateful sessions. Stateless predict is cheap and simple, but it forgets where it is. Stateful sessions keep a trajectory memory so the agent remembers tasks and UI state across steps. This post shows you how to build a robust computer use agent using stateful sessions.
How it works
Stateless predict is a single request to POST /v1/predict. You send a base64 screenshot, an instruction, and a cua_version. The API returns actions and a status. You loop capture, predict, act until status is "done". This model is billed $0.05 per predict call and has no memory of previous steps. Stateful sessions start with POST /v1/sessions to create a session. You get an id and a trajectory memory object. Then you POST /v1/sessions/{id}/predict using the same screenshot, instruction, and cua_version. The response includes actions and the updated trajectory memory. You keep calling predict with the new trajectory memory until the agent finishes. This costs $0.04 per predict call and maintains context across steps.
curl -X POST https://coasty.ai/v1/sessions \
-H 'X-API-Key: $COASTY_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"machine_id": "demo-machine",
"task": "Open Google and search for Coasty",
"cua_version": "v3"
}'
# Response example
# {
# "id": "sess_abc123",
# "trajectory_memory": {
# "context": "Starting new session",
# "ui_state": "empty"
# }
# }When to use stateless predict
- You need a quick one-off action and cannot afford session overhead.
- You do not need to remember previous steps or UI state.
- You are testing a single prompt and do not need trajectory memory.
- Billed $0.05 per predict call.
- No session ID to manage or store.
Use stateless predict for simple, one-shot tasks where context is not needed.
When to use stateful sessions
- You are building a multi-step computer use agent that must remember UI state.
- You need to handle dynamic UIs that change over time.
- You want to debug by inspecting the trajectory memory between steps.
- Billed $0.04 per predict call (cheaper per step than stateless).
- You get an id from POST /v1/sessions and reuse it across predict calls.
Where this beats brittle automation
Traditional automation relies on selectors like XPath or CSS that break when UIs change. The Coasty Computer Use API lets agents see the screen with vision and decide where to click or type. Stateful sessions preserve the trajectory memory so the agent knows the sequence of events and current state. This reduces maintenance and makes agents more resilient to UI updates. Developers can build complex workflows that handle navigation, login, form filling, and error recovery without rewriting selectors.
Start building a robust computer use agent with stateful sessions. Use POST /v1/sessions to create a session, then POST /v1/sessions/{id}/predict to drive the agent step by step. You can also run full task agents with POST /v1/runs for automated workflows. Get your API key at https://coasty.ai/developers and begin integrating computer use into your projects.
Want to see this in action?
View Case Studies