Stateful Sessions vs Stateless Predict in the Coasty Computer Use API
Most automation scripts start with a screenshot and an instruction, then call predict again and again until the task finishes. That pattern is simple but brittle. The agent forgets context between steps and you pay for every loop. The Coasty computer use API offers a stateful sessions model that keeps a trajectory of actions and lets you predict from the last state. This post explains the two models, the real endpoints, and how to pick the right one for your use case.
Stateless Predict Model
The stateless predict endpoint takes a fresh screenshot, an instruction, and the cua_version you want to use, then returns actions and a status. You loop capture, predict, act until the status is done. This model has no memory of previous steps. Each prediction is an isolated decision based only on the current image. The pricing is fixed per call. POST /v1/predict costs $0.05. You do not need to create a session first, just read the API key from COASTY_API_KEY and send the base64 screenshot and instruction.
Stateful Sessions Model
The stateful model starts a session with POST /v1/sessions, which creates a session that holds the last screenshot and the trajectory of actions taken so far. You then POST /v1/sessions/{id}/predict from that session. The request accepts an instruction and returns actions plus a status. The server remembers the current state between calls, so the agent does not need to resend the full history each time. This model costs $0.04 per predict call inside a session, and creating the session costs $0.10. The session persists until you close it, which lets you resume later or inspect the full trajectory.
Example: stateless predict loop with curl
# Read key from environment
export COASTY_API_KEY="your-key-here"
# Capture screenshot and encode to base64
SCREENSHOT=$(base64 -i screenshot.png)
# Stateless predict loop
while true; do
response=$(curl -s -X POST https://coasty.ai/v1/predict \
-H "X-API-Key: $COASTY_API_KEY" \
-H "Content-Type: application/json" \
-d "{
\"screenshot\": \"$SCREENSHOT\",
\"instruction\": \"Click the submit button on the page\",
\"cua_version\": \"v3\"
}")
echo "$response"
status=$(echo "$response" | jq -r '.status')
if [ "$status" = "done" ]; then break; fi
# In production, use the returned actions and act on the screen
sleep 1
doneStateful predict from a session
With a stateful session you first create a session, then predict from it. The session holds the last screenshot and accumulated actions, so you only send the latest instruction and receive actions that build on the current state. The session persists until you explicitly close it, letting you resume later or inspect the full trajectory. This model saves tokens and money. A session costs $0.10 to create and $0.04 per predict call. You can also stream events from the session with GET /v1/sessions/{id}/events to watch progress in real time.
Example: stateful session with Python requests
import os
import base64
import json
import requests
API_KEY = os.environ.get("COASTY_API_KEY")
BASE_URL = "https://coasty.ai/v1"
# Capture screenshot and encode
with open("screenshot.png", "rb") as f:
screenshot_b64 = base64.b64encode(f.read()).decode("utf-8")
# Create stateful session
resp = requests.post(
f"{BASE_URL}/sessions",
headers={"X-API-Key": API_KEY},
json={"initial_screenshot": screenshot_b64},
)
session_id = resp.json()["id"]
print("Session created", session_id)
# Predict from the session
resp = requests.post(
f"{BASE_URL}/sessions/{session_id}/predict",
headers={"X-API-Key": API_KEY},
json={
"instruction": "Click the submit button on the page",
"cua_version": "v3"
},
)
result = resp.json()
print("Status", result["status"])
print("Actions", result["actions"])Stateful sessions give you trajectory memory and lower predict costs ($0.04 vs $0.05) while keeping the current screen state between calls.
Where this beats brittle automation
Many scripts rely on selectors like CSS classes or XPath, which break when a UI changes or an element gets hidden. Stateless and stateful computer use models see the screen and act like a human, so they adapt to layout shifts, missing elements, or dynamic content. The stateful model adds memory of previous steps, letting the agent reason about the full workflow instead of isolated interactions. This approach scales to complex browser or desktop tasks where selectors become impractical. Coasty agents also integrate with OSWorld benchmarks, achieving high success rates on real desktop environments.
Start with stateless predict for quick experiments and simple loops. Switch to stateful sessions when you need longer workflows, resume capability, or lower per-step costs. The Coasty computer use API gives you both models with clear pricing and real endpoints. Get your API key at https://coasty.ai/developers and begin building agents that see and act like humans.