Tutorial

Orchestrating Multi-Step Automations with the Workflows API

David Park||7 min
+W

You need more than a single task. A regression test suite starts a browser, runs a user flow, verifies a UI element, and then checks credentials. A deployment pipeline spins up a cloud VM, installs a database, loads fixtures, and asserts health. Running these in one go requires stateful orchestration, not a chain of fragile HTTP calls. The Workflows API gives you a versioned JSON DSL for exactly that. You can define tasks, asserts, loops, and parallel branches, and the server executes them with a real computer use agent on a cloud desktop, browser, or terminal.

How it works

A workflow is a versioned JSON object. You POST it to /v1/workflows. The server returns a workflow id. Then you POST /v1/workflows/{id}/runs to start a run. The run is billed per agent step at $0.05. The flow lives in the server’s memory, so each step can reference variables from previous steps, like {{inputs.username}} or stepId.field. You can add hard guards: budget_cents, max_iterations, and deadline_seconds. Step types include task (billed $0.05), assert, if, loop, parallel, human_approval, retry, succeed, and fail. The server returns the run state and streams events via GET /v1/runs/{id}/events (Server-Sent Events).

bash
Create a workflow that logs into an app, clicks a button, and asserts a success message.

COASTY_API_KEY=$(cat ~/.coasty_key) # Read from env, never hardcode
WORKFLOW_ID=$(curl -s https://coasty.ai/v1/workflows \
  -H "X-API-Key: $COASTY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "version": "1",
    "steps": [
      {
        "type": "task",
        "task": "Log in to the web application using the provided credentials and wait for the dashboard to load.",
        "system_prompt": "You are a computer use agent. Use the computer use API to log in."
      },
      {
        "type": "assert",
        "condition": {
          "type": "text_on_screen",
          "text": "Dashboard loaded",
          "case_sensitive": true
        }
      },
      {
        "type": "task",
        "task": "Click the Settings icon and open the General settings tab.",
        "system_prompt": "Use the computer use API to click the Settings icon and navigate to the General settings tab."
      },
      {
        "type": "assert",
        "condition": {
          "type": "url_contains",
          "url_fragment": "settings/general"
        }
      },
      {
        "type": "succeed"
      }
    ],
    "variables": {
      "inputs.username": "{{inputs.username}}",
      "inputs.password": "{{inputs.password}}"
    },
    "hard_guards": {
      "budget_cents": 1000,
      "max_iterations": 50,
      "deadline_seconds": 600
    }
  }' | jq -r '.id')

# Start the workflow run
RUN_ID=$(curl -s https://coasty.ai/v1/workflows/$WORKFLOW_ID/runs \
  -H "X-API-Key: $COASTY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "task": "Run the workflow defined above.",
    "instructions": "Ensure the dashboard loads before proceeding.",
    "cua_version": "v3"
  }' | jq -r '.id')

# Poll the run status
while true; do
  STATUS=$(curl -s https://coasty.ai/v1/runs/$RUN_ID \
    -H "X-API-Key: $COASTY_API_KEY" | jq -r '.status')
  echo "Run status: $STATUS"
  if [[ "$STATUS" == "succeeded" ]] || [[ "$STATUS" == "failed" ]] || [[ "$STATUS" == "cancelled" ]] || [[ "$STATUS" == "timed_out" ]]; then
    break
  fi
  sleep 2
done

Workflow step types

  • task: Executes a computer use agent step. Billed $0.05 per step. You can append instructions and system_prompt to the base prompt.
  • assert: Can check for text on screen, URL fragments, or other conditions. Failures stop the run.
  • if: Branches execution based on a condition. Conditions are structured objects.
  • loop: Repeats a block of steps up to a max_iterations count or until a condition is met.
  • parallel: Runs multiple branches concurrently. Useful for matrix tests or multi-service health checks.
  • human_approval: Pauses the run for manual intervention. Options are pause, fail, or cancel.
  • retry: Retries a step on failure for a specified number of attempts.
  • succeed: Marks the run as successful.
  • fail: Marks the run as failed and returns an error.

The workflow is versioned JSON, stateful, and billed per agent step at $0.05.

Where this beats brittle automation

Traditional automation relies on CSS selectors, XPath, or brittle API mocks. A UI change breaks the selector. A new field name breaks the mapping. With the computer use API, the agent sees the screen, understands natural language, and clicks, types, and navigates like a human. The Workflows API orchestrates these steps, checks assertions, and retries loops. You don’t need to maintain selectors for every UI element. You describe what the app should do, and the agent figures out how to do it on the real desktop, browser, or terminal.

Start building stateful, multi-step automations with the Workflows API. Define workflows as versioned JSON, start runs with /v1/workflows/{id}/runs, and stream events with /v1/runs/{id}/events. Get your API key at https://coasty.ai/developers and try the computer use API today.

Want to see this in action?

View Case Studies
Try Coasty Free