Building a computer use agent that clicks, types, and scrolls through a real desktop often requires multiple steps. A stateless predict call acts on a single screenshot and instruction, then returns actions. A stateful session preserves the trajectory across calls, so later steps understand the previous actions. This guide explains the real endpoints, fields, and pricing for both approaches so you can pick the right model for your workflow.
How it works
The Computer Use API offers two main pathways. Stateless predict sends a base64 screenshot, instruction, and cua_version to POST /v1/predict and receives actions plus a status. The server returns a status such as 'done', 'awaiting_human', or 'continue'. You loop capture, predict, act until status is 'done'. This is ideal for one-off tasks or strict isolation. Stateful sessions use POST /v1/sessions to create a session, then POST /v1/sessions/{id}/predict for stateful steps. The session maintains trajectory memory, so the model sees the full history of actions. Both endpoints support cua_version, where 'v3' is the default and 'v4' adds autonomous verification.
import os
import requests
import base64
API_KEY = os.getenv('COASTY_API_KEY')
BASE_URL = 'https://coasty.ai/v1'
# Stateless predict example
def stateless_predict(screenshot_b64, instruction):
url = f'{BASE_URL}/predict'
payload = {
'screenshot': screenshot_b64,
'instruction': instruction,
'cua_version': 'v3'
}
headers = {'X-API-Key': API_KEY}
resp = requests.post(url, json=payload, headers=headers)
resp.raise_for_status()
return resp.json()
# Stateful session example
def create_session(system_prompt=None):
url = f'{BASE_URL}/sessions'
payload = {'system_prompt': system_prompt} if system_prompt else {}
headers = {'X-API-Key': API_KEY}
resp = requests.post(url, json=payload, headers=headers)
resp.raise_for_status()
return resp.json()['id']
def stateful_predict(session_id, screenshot_b64, instruction):
url = f'{BASE_URL}/sessions/{session_id}/predict'
payload = {
'screenshot': screenshot_b64,
'instruction': instruction,
'cua_version': 'v3'
}
headers = {'X-API-Key': API_KEY}
resp = requests.post(url, json=payload, headers=headers)
resp.raise_for_status()
return resp.json()
# Example usage
# session_id = create_session()
# result = stateful_predict(session_id, screenshot, 'Click the login button')
# print(result)
Pricing comparison
- POST /v1/predict costs $0.05 per predict call regardless of output length.
- POST /v1/sessions costs $0.10 to create a session and then $0.04 per predict call on that session.
- Stateless predict is simple and cheap for isolated steps but lacks trajectory memory across steps.
- Stateful sessions add $0.04 per predict call but give the model context from previous actions, which improves complex workflows.
Use stateless predict for single-step tasks at $0.05 per call. Use stateful sessions for multi-step workflows at $0.04 per predict call plus $0.10 to create the session.
When to choose stateless predict
- You need predictable, isolated steps that do not depend on prior actions.
- You want to keep costs low for short, repeatable operations like clicking a known button once.
- You prefer a simple request/response loop without managing session identifiers.
When to choose stateful sessions
- Your workflow spans multiple steps such as login, form filling, and navigation.
- You want the model to remember previous clicks, types, and scrolls to avoid redundant decisions.
- You need to coordinate parallel or conditional steps using workflow DSLs with variables like {{inputs.x}}.
Where this beats brittle automation
Traditional automation relies on brittle selectors like XPath, CSS selectors, or fixed element IDs. When the UI changes, those selectors break. The Computer Use API works at the screen level, sending screenshots and natural language instructions. The model understands context from the trajectory and adapts to layout changes, window positions, and dynamic content. Stateful sessions amplify this advantage by preserving a full history of actions, so the model can reason about state transitions rather than guessing the next click.
Pick stateless predict for simple, isolated tasks at $0.05 per call. Choose stateful sessions for multi-step workflows at $0.04 per predict call plus $0.10 to create the session. Start building real computer use agents with full trajectory memory today. Get your API key at https://coasty.ai/developers.
Want to see this in action?
View Case Studies