Back to Blog
Tutorial

Marcus Sterling8 min
⌘+D

Most automation stacks rely on brittle selectors and hardcoded APIs. You might wait for an element to appear, then click a specific class or ID. If the UI shifts, the script breaks. The /v1/predict endpoint flips that model. You send a screenshot and a natural-language instruction. The model sees the UI, decides where to click, and returns concrete actions. You loop until the status is done. This is the core of a computer use agent.

How it works

The /v1/predict endpoint is stateless. It takes a base64-encoded screenshot, an instruction, and a cua_version. It returns a list of actions and a status. You capture the screen, POST to /v1/predict, execute the actions, repeat. When the server says status is done, you stop. The endpoint costs $0.05 per call. You do not need a session or a workflow for this simplest pattern.

python
import base64
import os
import requests
import time

API_KEY = os.environ.get("COASTY_API_KEY")
BASE_URL = "https://coasty.ai/v1"

def capture_screen_as_base64() -> str:
    # Replace this with your own screenshot capture logic.
    # For example, use pyautogui.screenshot() and encode.
    from PIL import ImageGrab
    img = ImageGrab.grab()
    buffer = io.BytesIO()
    img.save(buffer, format="PNG")
    return base64.b64encode(buffer.getvalue()).decode("utf-8")

def predict_step(screenshot_b64: str, instruction: str) -> dict:
    url = f"{BASE_URL}/predict"
    headers = {
        "X-API-Key": API_KEY,
        "Content-Type": "application/json",
    }
    payload = {
        "screenshot": screenshot_b64,
        "instruction": instruction,
        "cua_version": "v3",
    }
    resp = requests.post(url, json=payload, headers=headers)
    resp.raise_for_status()
    return resp.json()

def run_agent(goal: str, max_steps: int = 20) -> dict:
    for step in range(1, max_steps + 1):
        screen = capture_screen_as_base64()
        result = predict_step(screen, goal)
        print(f"Step {step}: {result}")
        # result['status'] should be "done" to stop.
        if result.get("status") == "done":
            return result
        # Apply actions here (pyautogui, playwright, etc.)
        # time.sleep(0.5) # optional delay
    raise RuntimeError("Max steps reached without status=done.")

if __name__ == "__main__":
    final = run_agent("Click the login button.")
    print("Final result:", final)

Request schema details

  • screenshot: base64-encoded PNG (string).
  • instruction: natural language describing the goal (string).
  • cua_version: one of the supported wrapper versions, e.g., "v3" (string).

Response shape

  • actions: array of action objects such as click, type, move, etc.
  • status: can be "done" (stop looping) or other intermediate states (string).

Loop capture → predict → act until status is "done".

Where this beats brittle automation

The model reads the UI like a person. It does not need to know a button ID or a class name. It can handle layout changes, dynamic text, and multi-step flows because it sees the current state. This is why a computer use agent can operate real browsers and desktop apps rather than brittle selectors. You build once on top of vision, not on fragile selectors.

The /v1/predict endpoint is the entry point for a vision-based computer use agent. Build a simple clicker, then expand into multi-step workflows, parallel tasks, or even full desktop assistants. Get your API key at https://coasty.ai/developers and start seeing the screen and acting with your own agent.

© 2026 Coasty

Backed byYCombinator