Stateful Sessions vs Stateless Predict in the Computer Use API
Stateless prediction (POST /v1/predict) is great for quick tasks but loses context on each turn. Stateful sessions (POST /v1/sessions then POST /v1/sessions/{id}/predict) keep a trajectory in memory, so the agent can remember previous clicks, inputs, and screen state. This post shows how both work and how to pick the right one for your use case.
Stateless predict: the baseline
Stateless prediction runs a single turn. You send a screenshot, an instruction, and a CUA version. The endpoint returns actions and a status. You must send the full screenshot again on the next turn because the server has no memory of previous steps. This model is simple but can be expensive for long workflows.
Stateful sessions: persistent memory
Stateful sessions give you trajectory memory. First, you create a session with POST /v1/sessions. This returns a session ID and an initial state. Then, you POST /v1/sessions/{id}/predict with a screenshot and instruction. The server attaches your new actions to the existing trajectory, so the agent can reference earlier clicks and inputs. You loop capture, predict, act until status is done.
curl -X POST https://coasty.ai/v1/sessions \
-H 'X-API-Key: $COASTY_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"cua_version": "v3"
}'
# Response
# {
# "id": "sess_abc123",
# "cua_version": "v3",
# "created_at": 1715620800
# }
# Next turn: send screenshot + instruction
curl -X POST https://coasty.ai/v1/sessions/sess_abc123/predict \
-H 'X-API-Key: $COASTY_API_KEY' \
-H 'Content-Type: application/json' \
-d '{
"screenshot": "base64_encoded_image",
"instruction": "Click the submit button",
"cua_version": "v3"
}'Cost comparison per step
- ●Stateless: POST /v1/predict costs $0.05 per turn
- ●Stateful: POST /v1/sessions costs $0.10 once, then $0.04 per predict
- ●Long workflows with many turns cost significantly less with stateful sessions
- ●Stateless is best for single-turn or infrequent actions
Stateful sessions cost $0.04 per predict after the one-time $0.10 session creation.
Where this beats brittle automation
Stateless predict forces you to send a fresh screenshot each time, which means you lose any window of where the user last clicked. Stateful sessions keep a trajectory, so the agent can reason about the full history of actions. This makes the agent more robust to UI changes and reduces the need for brittle selectors or complex APIs. It also lowers per-step cost because the server does not have to re‑encode the full trajectory into each request.
Start with stateless predict for quick demos, then switch to stateful sessions for longer workflows. Check the full documentation with endpoints, models, and pricing at https://coasty.ai/developers to get your key.