---
title: Flows API · Agent Playground docs
description: Save, check, simulate and run Agent Playground flows over plain HTTP, and write flows as JSON. The same plan limits and Policies apply as in the builder.
url: https://www.quietrobot.ai/docs/playground/api
---

# Flows API

Save, check, simulate and run Agent Playground flows over plain HTTP, and write flows as JSON. The same plan limits and Policies apply as in the builder.

Everything the builder does, you can do from code. A flow you draw in the builder and a flow you send as JSON are the same thing: you can draw a flow and run it from your CI, or generate one in code and open it in the builder. The same calls are coming soon to the TypeScript and Python SDKs and the `qr` command line ([SDK and CLI](https://www.quietrobot.ai/docs/playground/sdk)). To let an AI app build and run flows, see [MCP tools](https://www.quietrobot.ai/docs/playground/mcp).

## Before you start

You need two keys:

1. **An API key, for these calls.** In the dashboard, open **API keys** and make one under **New key**. It starts with `qr_live_` and is shown once. Send it as `Authorization: Bearer qr_live_...`. A read-only key can list and read flows and runs, and simulate. Saving, starting and stopping runs need a full key. See [Authentication](https://www.quietrobot.ai/docs/sandboxes/authentication).
2. **Your Claude key, only if the flow has AI steps.** In the dashboard, open **Policies**, then **Secrets**, and save your key as `ANTHROPIC_API_KEY`, sent only to `api.anthropic.com`. Flows name it in `secrets`. The key never enters the sandbox.

Every call that sends a body (`POST`, `PUT`, `PATCH`) also needs `Content-Type: application/json`.

## Run a recipe or a saved flow

The quickest way to start: run a recipe by its id, or a flow you saved in the builder (its id starts with `flw_` and is in the builder's address bar).

```bash
export QR_API_KEY=qr_live_...

# Run a recipe
curl -s -X POST https://api.quietrobot.ai/api/v1/runs -H "Authorization: Bearer $QR_API_KEY" -H "Content-Type: application/json" \
  -d '{"recipe":"fix-until-pass"}'

# Run your saved flow, with tighter limits for this run
curl -s -X POST https://api.quietrobot.ai/api/v1/flows/flw_123/runs -H "Authorization: Bearer $QR_API_KEY" -H "Content-Type: application/json" \
  -d '{"guards":{"maxLoops":3,"timeSec":600,"budgetUsd":0.50}}'
```

Both answer `201` with the [run](#the-run-object). A run that needs more sandboxes at once than your plan allows is refused with `403 plan_limit`, and every command it runs goes through your [Policies](https://www.quietrobot.ai/docs/sandboxes/approvals), as in the builder. Then check on it:

```bash
curl -s https://api.quietrobot.ai/api/v1/runs/run_123 -H "Authorization: Bearer $QR_API_KEY"
```

Poll every few seconds until `status` is `done`, `failed`, `stopped` (it reached a limit) or `cancelled`. Stop it early with `POST /runs/run_123/cancel`.

## Simulate first

Get the same forecast the builder shows, before you spend anything:

```bash
curl -s -X POST https://api.quietrobot.ai/api/v1/graphs/simulate -H "Authorization: Bearer $QR_API_KEY" -H "Content-Type: application/json" \
  -d '{"flow":"flw_123","guards":{"maxLoops":5,"timeSec":300,"budgetUsd":0.25}}'
```

```json
{
  "forecast": {
    "costUsd": { "p50": 0.0009, "p90": 0.0014 },
    "seconds": { "p50": 38, "p90": 55 },
    "loops": { "mean": 2.8, "p90": 4 },
    "outcomes": { "done": 1800, "failed": 0, "guard": 200 },
    "guardHits": { "loops": 0.1, "time": 0, "budget": 0 },
    "worstCaseUsd": 0.0031,
    "worstCaseWhy": "the time cap (180s) on up to 1 sandbox",
    "modelCostUsd": { "p50": 0, "p90": 0 },
    "notes": []
  }
}
```

`p50` is the typical run and `p90` one run in ten. A CI job can refuse to start a run whose `worstCaseUsd` is over budget.

## Write a flow as JSON

Every call that takes a flow takes the same document: a `name`, the flow itself under `graph` (its steps, `nodes`, and arrows, `edges`), and its limits under `guards`. It's the same document the builder's [JSON view](https://www.quietrobot.ai/docs/playground/json-editor) and [export](#flow-json-export-edit-import) give you.

```json
{
  "name": "Fix until tests pass",
  "graph": {
    "template": "base",
    "start": "get",
    "secrets": ["ANTHROPIC_API_KEY"],
    "nodes": [
      { "id": "get", "kind": "run", "label": "Get the code", "cmd": "git clone https://github.com/you/app proj" },
      { "id": "test", "kind": "run", "label": "Run tests", "cwd": "proj", "cmd": "python3 -m pytest -q" },
      { "id": "fix", "kind": "agent", "label": "Fix it",
        "goal": "Make the tests in proj pass without changing them. They said:\n{{steps.test.output}}",
        "maxTurns": 12, "maxUsd": 0.5, "done": "cd proj && python3 -m pytest -q" },
      { "id": "done", "kind": "end", "label": "Fixed" }
    ],
    "edges": [
      { "from": "get", "to": "test" },
      { "from": "test", "to": "fix", "when": "fail" },
      { "from": "fix", "to": "test" },
      { "from": "test", "to": "done", "when": "pass" }
    ],
    "rewindTo": "get"
  },
  "guards": { "maxLoops": 3, "timeSec": 600, "budgetUsd": 1 }
}
```

Send this document as is to `POST /flows` (save a new flow), `PUT /flows/{id}` (save over one), `POST /flows/validate` (check it), and `POST /runs` or `POST /graphs/simulate` (run or forecast it without saving). Keep the steps inside `graph`: a body with no `graph` and no `recipe` saves an empty flow.

Inside `graph`:

* `template` is the [sandbox template](https://www.quietrobot.ai/docs/sandboxes/templates) the run starts from.
* `start` is the first step. It must run something in the main sandbox.
* `secrets` lists the saved secrets the run may use. AI steps need `ANTHROPIC_API_KEY` here (see [Before you start](#before-you-start)).
* `rewindTo` is the step whose checkpoint the sandbox goes back to if a limit stops the run.
* An edge's `when` is `pass` (the default), `fail`, `always` (either way), or `choice:<label>` after an AI choice.

`guards` are the run's limits: `maxLoops`, `timeSec` and `budgetUsd` (US dollars).

### Step kinds

| `kind` | Block | Main fields |
|---|---|---|
| `run` | Run command | `cmd`, `cwd`, `files` (a map of path to text, written before it runs) |
| `code` | Run code | `code`, `lang` (`python`, `node` or `bash`) |
| `model` | Ask AI | `prompt`, `model`, `key`, `output` (`text`, `json` or `decision`), `choices`, `schema`, `expect`, `out` |
| `agent` | Agent | `goal`, `model`, `key`, `tools` (`shell`, `files`), `maxTurns`, `maxUsd`, `done` |
| `team` | Agents together | `members` (2 to 6 step ids), `need` (`all` or `any`) |
| `branch` | Decide | `cmd`: exit 0 follows `pass`, anything else `fail` |
| `approval` | Approval | `ask`, the question for the person |
| `wait` | Wait | `seconds`, 1 to 600 |
| `fork` | Try in parallel | `lanes`, 2 to 10 names |
| `judge` | Keep the best | `metric`, `best` (`min` or `max`) |
| `end` | Output | |

Every step has an `id` and a `label`. Steps that run something also take `sandbox` (a lane name, or the main sandbox when left out), `timeoutMs`, `checkpoint`, `network: "none"`, `approve: true` (ask a person first), and the forecast hints `estSec` and `passRate`. Models are `claude-sonnet-5-5` (the default), `claude-opus-5-5` and `claude-haiku-5-5`.

A flow's own rules go in `policy`, inside `graph` next to `nodes` and `edges`:

```json
"graph": {
  "nodes": [ ... ],
  "edges": [ ... ],
  "policy": {
    "network": { "mode": "allowlist", "allow": ["pypi.org", "*.github.com"], "lock": true },
    "hold": [{ "pattern": "git push|npm publish", "description": "Publishing needs a person" }]
  }
}
```

`mode` is `deny`, `allowlist` or `open`. A flow that breaks a rule (an unknown step in an edge, a reference to a later step, a lane no fork makes) is refused with a message that names the step. To find every place before you save, [check it first](#check-a-flow-before-you-save-or-run-it).

## Check a flow before you save or run it

Send flow JSON (or a saved flow's id, or a recipe's id) to `/flows/validate`. It runs the same checks as **Run** in the builder, without saving or starting anything:

* the flow itself: every step, arrow and reference, and the limits
* your plan: how many sandboxes the flow runs at once, against how many your plan allows (Free runs 3 at a time)
* your keys: AI steps need their key saved under **Policies → Secrets**
* your [Policies](https://www.quietrobot.ai/docs/sandboxes/approvals): which steps will likely wait for a person, or have no network

```bash
curl -s -X POST https://api.quietrobot.ai/api/v1/flows/validate -H "Authorization: Bearer $QR_API_KEY" -H "Content-Type: application/json" \
  -d @flow.json
```

```json
{
  "valid": false,
  "problems": [
    { "message": "step test: cmd is required", "code": "invalid_flow", "step": "test", "path": "/graph/nodes/1/cmd" },
    { "message": "Needs Pay as you go: runs 4 sandboxes at once, and Free runs 3", "code": "plan_limit" }
  ],
  "sandboxes": { "atOnce": 4, "limit": 3, "plan": "free" },
  "policy": { "ship": "Waits for a person (this step asks)" },
  "steps": 6,
  "guards": { "maxLoops": 5, "timeSec": 300, "budgetUsd": 0.25 }
}
```

A flow that wouldn't run still answers `200`, with `valid: false` and the problems; nothing is refused. Each problem has a `code` and, when it points at one, the `step` and a `path` into your JSON, so an editor or a CI job can show exactly where it is.

| `code` | What to do |
|---|---|
| `invalid_flow` | Fix the step or field the message names. |
| `plan_limit` | Use fewer parallel lanes, or add a card on the **Billing** page to run more sandboxes at once. |
| `missing_secret`, `secret_host` | Save the key under **Policies → Secrets**, with the host the message names. |
| `model_steps_off`, `agent_steps_off` | AI or agent steps are switched off for your organization right now. |

`/flows/validate` also takes `{"flow": "flw_123"}` or `{"recipe": "pr-reviewer"}`, and `size` like a run.

## Flow JSON: export, edit, import

The builder's JSON view, the API and the MCP tools all use the document from [Write a flow as JSON](#write-a-flow-as-json). An export adds two fields:

```json
{
  "$schema": "https://api.quietrobot.ai/api/v1/flows/schema",
  "name": "Fix until tests pass",
  "graph": { "start": "get", "nodes": [ ... ], "edges": [ ... ], "secrets": ["ANTHROPIC_API_KEY"] },
  "guards": { "maxLoops": 5, "timeSec": 300, "budgetUsd": 0.25 },
  "layout": { "get": { "x": 80, "y": 120 } }
}
```

* `layout` is where each block sits on the canvas. Leave it out and the builder lays the flow out for you.
* `$schema` points editors at the flow's JSON Schema, so they can complete field names and flag mistakes as you type. The API ignores it.

```bash
# Export a flow (no ids or dates, ready to keep in your repository)
curl -s https://api.quietrobot.ai/api/v1/flows/flw_123/export -H "Authorization: Bearer $QR_API_KEY" > flow.json

# Check your edits, then save them back over the flow...
curl -s -X POST https://api.quietrobot.ai/api/v1/flows/validate -H "Authorization: Bearer $QR_API_KEY" -H "Content-Type: application/json" -d @flow.json
curl -s -X PUT https://api.quietrobot.ai/api/v1/flows/flw_123 -H "Authorization: Bearer $QR_API_KEY" -H "Content-Type: application/json" -d @flow.json

# ...or import it as a new flow, here or in another organization
curl -s -X POST https://api.quietrobot.ai/api/v1/flows -H "Authorization: Bearer $QR_API_KEY" -H "Content-Type: application/json" -d @flow.json

# The JSON Schema, for your editor (no key needed)
curl -s https://api.quietrobot.ai/api/v1/flows/schema
```

In VS Code and other editors that read `$schema`, an exported flow gets hints straight away.

### In the builder

You don't need the API to work on a flow as JSON. In the builder, press **JSON** in the toolbar (on a tablet or phone it's under **More**). The panel shows the flow you're editing as this same document.

* **Edit it in place.** A change that's valid shows up on the canvas a moment after you stop typing, and saves like any other change.
* **Mistakes don't break your flow.** If the JSON doesn't parse, or the flow it describes couldn't be saved, nothing changes on the canvas. A note tells you the line, or what's wrong with which step.
* **Copy JSON** or **Download .json** to keep a flow in your repository or share it.
* **Import JSON** replaces the flow with one you paste or pick from a file (up to 1 MB). It asks first, and you can undo it.

The [JSON editor](https://www.quietrobot.ai/docs/playground/json-editor) page covers the checks under the editor and the **Fields** list.

## Save flows

```bash
# Save a new flow from a recipe, or from your own JSON
curl -s -X POST https://api.quietrobot.ai/api/v1/flows -H "Authorization: Bearer $QR_API_KEY" -H "Content-Type: application/json" -d '{"recipe":"pr-reviewer"}'
curl -s -X POST https://api.quietrobot.ai/api/v1/flows -H "Authorization: Bearer $QR_API_KEY" -H "Content-Type: application/json" \
  -d @- <<'EOF'
{ "name": "Fix my tests", "graph": { ... }, "guards": { "maxLoops": 3, "timeSec": 600, "budgetUsd": 1 } }
EOF
```

The flow opens in the builder like any other. A saved flow can be a draft that can't run yet: `runnable` is `false` and `problem` says why.

| Call | What it does |
|---|---|
| `GET /recipes`, `GET /recipes/{id}` | The recipes, with their category, default limits (`guards`), flow, and `needsKey` |
| `GET /flows`, `POST /flows` | List your flows, save a new one |
| `POST /flows/validate` | Check flow JSON, a saved `flow` or a `recipe` without running it: problems, sandboxes at once against your plan, steps your Policies will hold |
| `GET /flows/{id}/export` | The flow JSON, without ids or dates |
| `GET /flows/{id}/triggers`, `POST /flows/{id}/triggers` | List a flow's triggers, add one. See [Triggers](https://www.quietrobot.ai/docs/playground/triggers#from-code) |
| `PATCH`, `DELETE /flows/{id}/triggers/{triggerId}` | Turn a trigger on or off, change it, delete it |
| `POST /hooks/flows/{triggerId}` | Start a flow from a webhook (its token in `X-QR-Token`) or GitHub. No API key |
| `GET /flows/schema` | The flow JSON's JSON Schema, for editors. No key needed. |
| `GET`, `PUT`, `DELETE /flows/{id}` | Read, change (fields you leave out keep their value) or delete a flow. Deleting keeps its runs. |
| `GET /flows/{id}/versions`, `POST /flows/{id}/versions` | List versions, newest first; save one with an optional `note` |
| `GET /flows/{id}/versions/{n}` | One version, with its flow |
| `POST /flows/{id}/restore` | `{"version": n}` restores a version |
| `GET /flows/{id}/runs`, `POST /flows/{id}/runs` | List a flow's runs, start one |
| `POST /graphs/simulate` | Forecast a `graph`, `recipe` or `flow` |
| `POST /runs` | Start a run of a `graph`, `recipe` or `flow`, with optional `guards`, `size` and `metadata` |
| `GET /runs`, `GET /runs/{id}` | Recent runs; one run with its steps |
| `POST /runs/{id}/cancel` | Stop a run |

`size` picks the sandbox size for the run, like `{"cpuClass": "standard", "cpus": 2, "memoryMb": 4096}`. The default is your plan's default size. `metadata` is up to 16 strings of your own, kept with the run.

## The run object

```json
{
  "id": "run_...", "name": "Fix until tests pass", "recipe": "fix-until-pass",
  "status": "done", "guards": { "maxLoops": 5, "timeSec": 180, "budgetUsd": 0.05 },
  "loops": 3, "costUsd": 0.0011, "modelCostUsd": 0, "elapsedSec": 41.2,
  "flowId": null, "flowVersion": null, "stopReason": null, "error": null,
  "steps": [
    { "seq": 1, "node": "setup", "label": "Set up project", "status": "ok",
      "message": "Project ready, 4 attempts prepared", "output": "...",
      "costUsd": 0.0001, "durationMs": 1830, "snapshotId": "snp_..." }
  ]
}
```

A step's `status` is `running`, `waiting` (for a person), `ok`, `fail`, `stopped` or `skipped`. An agent step also has `agent`, its turn-by-turn replay: each turn's text, tool calls with exit codes and output, tokens and cost, and the final check.

## From code and the command line

Flow calls in the TypeScript and Python SDKs and the `qr` command line are coming soon: see [SDK and CLI](https://www.quietrobot.ai/docs/playground/sdk). Until then, use the calls on this page.

## Track your own loops

Already have an agent loop in your own code, or in LangGraph? You can still see it in the Playground's run view and use its limits. Start a run with `"mode": "external"` and a flow that only names the steps, then report each step as your code runs it:

```bash
curl -s -X POST https://api.quietrobot.ai/api/v1/runs/run_123/steps -H "Authorization: Bearer $QR_API_KEY" -H "Content-Type: application/json" \
  -d '{"node":"test","status":"fail","sandboxId":"sbx_...","message":"2 tests failed"}'
```

The answer says `"stop": true` once a limit is reached, and your code should stop there. Reported runs show in **Recent runs** marked "reported".
