# Desktop local API

> The REST and MCP endpoints Writ Desktop serves on your machine, with local keys.

Source: https://usewrit.app/docs/local-api/

Writ Desktop serves a REST API and an MCP server on your computer. Your scripts, apps and agents call
the APIs you built there, read their data and check monitors, with no account and no credits. Calls
stay on your machine unless you open it to your network.

## Base URL and keys

The API answers at `http://127.0.0.1:8131/v1` while Writ Desktop is running. The same API
is available on other bases when you turn them on in the app:

```
http://127.0.0.1:8131/v1                  this computer
https://127.0.0.1:8132/v1                 this computer, HTTPS (after Trust certificate)
http://<your-lan-ip>:8131/v1              LAN mode (paid plans)
https://<words>.trycloudflare.com/v1      public URL (paid plans)
```

HTTPS on your computer is set up in **MCP & APIs → Endpoints → Secure connection (HTTPS)**. LAN mode and the public URL are set up in **Settings → Engine & Data → Network access** and need a paid plan (Starter and up): see [Writ Desktop](https://usewrit.app/docs/desktop).

### Keys

Every call sends `Authorization: Bearer wlk_...`. Create local keys in **MCP & APIs → API Keys**. A key is shown once.

| Preset | What it allows |
| --- | --- |
| Read-only | Reading (GET calls): workflows, runs, data, monitors, status. |
| Run automations | Read-only, plus running and cancelling workflows, monitor checks, OpenAI-compatible calls and MCP. |
| Full access | Run automations, plus creating and changing workflows, monitors and other resources. |
| Device control | A separate permission, not part of Full access: app lock, data reset and restore, issuing keys, LAN exposure, unlinking the cloud account. |

Writ Desktop also keeps an app token (`wlt_`) for programs on the same computer, such as the
SDKs’ local client. It works on this computer only and is refused over the public URL. MCP clients
can sign in with OAuth instead of a key; Writ asks you to approve each one.

## Run workflows

### Run a workflow

POST `/v1/workflows/{id}/run` free Run automations

Starts a run with new inputs. By default it answers `202` at once with a `run_id` and a `status_url` to poll. With `wait=true` it waits for the result
and answers `200`, also when the run failed (read `status`). Past the wait it
answers `504`, and the run keeps going.

The workflow’s REST access must be on in its **Call** tab (it is on by default). Off, a
key gets `403`.

Query

- `wait` (boolean): Wait for the result.
- `timeout` (integer): Seconds to wait, from 1 to 3600.
- `async` (boolean): Answer 202 at once, even with wait. Same as the header Prefer: respond-async.
- `max_age` (integer): Reuse a successful result with the same inputs younger than this many seconds. The answer then has X-Cache: HIT. The header Cache-Control: max-age=N does the same.

Body

- `inputs` (object): The workflow’s inputs.
- `function_name` (string): Run one function of an API, or function_names for several.
- `persona_id` (integer): Run as another saved sign-in.
- `mutation_mode` (string): For a function that writes: dry_run previews it without sending.

```bash
curl -X POST "http://127.0.0.1:8131/v1/workflows/7/run?wait=true" \
  -H "Authorization: Bearer $WRIT_LOCAL_KEY" \
  -H "Content-Type: application/json" \
  -d '{"inputs": {"limit": 3}}'
```

```python
import os, requests

res = requests.post(
    "http://127.0.0.1:8131/v1/workflows/7/run",
    params={"wait": "true"},
    headers={"Authorization": f"Bearer {os.environ['WRIT_LOCAL_KEY']}"},
    json={"inputs": {"limit": 3}},
    timeout=130,
)
print(res.json()["data"])
```

```typescript
const res = await fetch("http://127.0.0.1:8131/v1/workflows/7/run?wait=true", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.WRIT_LOCAL_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({ inputs: { limit: 3 } }),
});
console.log((await res.json()).data);
```

```json
{
  "run_id": 412,
  "status": "success",
  "done": true,
  "data": {
    "stories": [
      { "rank": 1, "title": "...", "points": 412 },
      { "rank": 2, "title": "...", "points": 288 },
      { "rank": 3, "title": "...", "points": 175 }
    ]
  },
  "duration_ms": 3180
}
```

```json
{
  "success": true,
  "run_id": 412,
  "status": "running",
  "status_url": "http://127.0.0.1:8131/v1/workflows/7/_runs/412",
  "events_url": "http://127.0.0.1:8131/v1/runs/412/events"
}
```

```json
{
  "success": false,
  "run_id": 412,
  "status": "running",
  "done": false,
  "error": "Run did not finish within 120s and is still in progress. ...",
  "status_url": "http://127.0.0.1:8131/v1/workflows/7/_runs/412",
  "events_url": "http://127.0.0.1:8131/v1/runs/412/events"
}
```

### Get a run’s result

GET `/v1/workflows/{id}/_runs/{run_id}` Read-only

Poll the `status_url` until `done` is `true`. A run in progress
answers with `Retry-After: 2`. A run waiting for you (a sign-in or a CAPTCHA) adds `"needs_user": true`; finish it on the **Needs you** page.

Status values

- `running` (in progress): Also repairing and awaiting_input.
- `success` (done): The run finished; data holds the result.
- `failed` (done): Also timeout, cancelled, captcha_required, twofa_required and interrupted. error says why.

```bash
curl "http://127.0.0.1:8131/v1/workflows/7/_runs/412" \
  -H "Authorization: Bearer $WRIT_LOCAL_KEY"
```

```python
import os, requests

res = requests.get(
    "http://127.0.0.1:8131/v1/workflows/7/_runs/412",
    headers={"Authorization": f"Bearer {os.environ['WRIT_LOCAL_KEY']}"},
)
print(res.json())
```

```typescript
const res = await fetch("http://127.0.0.1:8131/v1/workflows/7/_runs/412", {
  headers: { Authorization: `Bearer ${process.env.WRIT_LOCAL_KEY}` },
});
console.log(await res.json());
```

```json
{
  "success": true,
  "run_id": 412,
  "status": "running",
  "done": false,
  "status_url": "http://127.0.0.1:8131/v1/workflows/7/_runs/412",
  "events_url": "http://127.0.0.1:8131/v1/runs/412/events"
}
```

```json
{
  "success": true,
  "run_id": 412,
  "status": "success",
  "done": true,
  "data": { "stories": [ ... ] },
  "duration_ms": 3180
}
```

### List workflows

GET `/v1/workflows` Read-only

Lists the workflows and APIs saved on this computer, newest first. Use an `id` from here in the other calls.

Query

- `active_only` (boolean): Only active workflows.
- `limit` (integer): How many to return.

```bash
curl "http://127.0.0.1:8131/v1/workflows?limit=20" \
  -H "Authorization: Bearer $WRIT_LOCAL_KEY"
```

```python
import os, requests

res = requests.get(
    "http://127.0.0.1:8131/v1/workflows?limit=20",
    headers={"Authorization": f"Bearer {os.environ['WRIT_LOCAL_KEY']}"},
)
print(res.json()["data"])
```

```typescript
const res = await fetch("http://127.0.0.1:8131/v1/workflows?limit=20", {
  headers: { Authorization: `Bearer ${process.env.WRIT_LOCAL_KEY}` },
});
console.log((await res.json()).data);
```

```json
{
  "data": [
    {
      "id": 7,
      "name": "Top stories",
      "description": "Top stories from news.ycombinator.com",
      "workflow_type": "api_recorded",
      "entry_url": "https://news.ycombinator.com",
      "is_active": 1,
      "schedule_enabled": 0
    }
  ],
  "count": 1
}
```

## Runs and data

### List runs

GET `/v1/runs` Read-only

The run history of this computer: workflows, monitors, crawls and Scribe sessions, newest first.

Query

- `workflow_id` (integer): Runs of one workflow.
- `run_type` (string): One kind of run, such as workflow or crawl.
- `status` (string): One or more statuses, comma-separated.
- `since` (string): Runs after this time (ISO 8601). until sets the end.
- `limit` (integer): At most 1000. Page with offset.

```bash
curl "http://127.0.0.1:8131/v1/runs?workflow_id=7&status=failed&limit=10" \
  -H "Authorization: Bearer $WRIT_LOCAL_KEY"
```

```python
import os, requests

res = requests.get(
    "http://127.0.0.1:8131/v1/runs?workflow_id=7&status=failed&limit=10",
    headers={"Authorization": f"Bearer {os.environ['WRIT_LOCAL_KEY']}"},
)
print(res.json()["data"])
```

```typescript
const res = await fetch("http://127.0.0.1:8131/v1/runs?workflow_id=7&status=failed&limit=10", {
  headers: { Authorization: `Bearer ${process.env.WRIT_LOCAL_KEY}` },
});
console.log((await res.json()).data);
```

```json
{
  "data": [
    {
      "id": "workflow-409",
      "run_type": "workflow",
      "entity_id": 7,
      "entity_name": "Top stories",
      "status": "failed",
      "started_at": "2026-10-31T08:02:11Z",
      "finished_at": "2026-10-31T08:02:40Z",
      "duration_ms": 29110,
      "trigger_source": "schedule",
      "error": "The page did not load in time."
    }
  ],
  "count": 1,
  "total": 1,
  "limit": 10,
  "offset": 0
}
```

### Cancel a run

POST `/v1/runs/{run_id}/cancel` Run automations

Stops a run in progress and answers `202`. A run that already ended answers `409` with `"status": "not_running"`.

```bash
curl -X POST "http://127.0.0.1:8131/v1/runs/412/cancel" \
  -H "Authorization: Bearer $WRIT_LOCAL_KEY"
```

```python
import os, requests

res = requests.post(
    "http://127.0.0.1:8131/v1/runs/412/cancel",
    headers={"Authorization": f"Bearer {os.environ['WRIT_LOCAL_KEY']}"},
)
print(res.status_code, res.json())
```

```typescript
const res = await fetch("http://127.0.0.1:8131/v1/runs/412/cancel", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.WRIT_LOCAL_KEY}`,
  },
});
console.log(res.status, await res.json());
```

```json
{
  "run_id": 412,
  "status": "cancel_requested"
}
```

### Read a workflow’s data

GET `/v1/workflows/{id}/data` Read-only

Everything a workflow collected, as a table: one row per record, with the run it came from and the
data under `fields`. Nothing runs.

Query

- `q` (string): Text filter across fields.
- `view` (string): all, latest (the last run) or run (with run_id).
- `sort_by` (string): A column, or run_at. sort_dir is asc or desc.
- `limit` (integer): Rows per page. Page with offset.

```bash
curl "http://127.0.0.1:8131/v1/workflows/7/data?q=show&limit=50" \
  -H "Authorization: Bearer $WRIT_LOCAL_KEY"
```

```python
import os, requests

res = requests.get(
    "http://127.0.0.1:8131/v1/workflows/7/data?q=show&limit=50",
    headers={"Authorization": f"Bearer {os.environ['WRIT_LOCAL_KEY']}"},
)
print(res.json()["rows"])
```

```typescript
const res = await fetch("http://127.0.0.1:8131/v1/workflows/7/data?q=show&limit=50", {
  headers: { Authorization: `Bearer ${process.env.WRIT_LOCAL_KEY}` },
});
console.log((await res.json()).rows);
```

```json
{
  "workflow_id": 7,
  "workflow_name": "Top stories",
  "columns": ["rank", "title", "points"],
  "declared": true,
  "rows": [
    {
      "run_id": 412,
      "run_at": "2026-10-31T09:15:02Z",
      "status": "success",
      "record_index": 0,
      "fields": { "rank": 1, "title": "Show HN: ...", "points": 412 }
    }
  ],
  "total": 1,
  "scanned_runs": 24,
  "truncated": false,
  "limit": 50,
  "offset": 0
}
```

### Export a workflow’s data

GET `/v1/workflows/{id}/data/export` Read-only

Downloads the whole table as a file.

Query

- `format` (string): csv, json, markdown or html.

```bash
curl "http://127.0.0.1:8131/v1/workflows/7/data/export?format=csv" \
  -H "Authorization: Bearer $WRIT_LOCAL_KEY" \
  -o top-stories.csv
```

```python
import os, requests

res = requests.get(
    "http://127.0.0.1:8131/v1/workflows/7/data/export",
    params={"format": "csv"},
    headers={"Authorization": f"Bearer {os.environ['WRIT_LOCAL_KEY']}"},
)
open("top-stories.csv", "wb").write(res.content)
```

```typescript
import { writeFile } from "node:fs/promises";

const res = await fetch("http://127.0.0.1:8131/v1/workflows/7/data/export?format=csv", {
  headers: { Authorization: `Bearer ${process.env.WRIT_LOCAL_KEY}` },
});
await writeFile("top-stories.csv", Buffer.from(await res.arrayBuffer()));
```

## Monitors and status

### Check a monitor now

POST `/v1/monitors/{id}/run` Run automations

Runs one check right away, outside the schedule. `status` is `unchanged`, `changed`, `error`, `timeout`, `skipped` or `awaiting_input`. `GET /v1/monitors` lists your monitors and `GET /v1/monitors/{id}/changes` their history.

```bash
curl -X POST "http://127.0.0.1:8131/v1/monitors/3/run" \
  -H "Authorization: Bearer $WRIT_LOCAL_KEY"
```

```python
import os, requests

res = requests.post(
    "http://127.0.0.1:8131/v1/monitors/3/run",
    headers={"Authorization": f"Bearer {os.environ['WRIT_LOCAL_KEY']}"},
)
print(res.status_code, res.json())
```

```typescript
const res = await fetch("http://127.0.0.1:8131/v1/monitors/3/run", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.WRIT_LOCAL_KEY}`,
  },
});
console.log(res.status, await res.json());
```

```json
{
  "target_id": 3,
  "status": "changed",
  "change_id": 58
}
```

### Check the engine

GET `/v1/health` Read-only

Whether the engine is up and its version. `status` is `ok` or `degraded`.

```bash
curl "http://127.0.0.1:8131/v1/health" \
  -H "Authorization: Bearer $WRIT_LOCAL_KEY"
```

```python
import os, requests

res = requests.get(
    "http://127.0.0.1:8131/v1/health",
    headers={"Authorization": f"Bearer {os.environ['WRIT_LOCAL_KEY']}"},
)
print(res.json())
```

```typescript
const res = await fetch("http://127.0.0.1:8131/v1/health", {
  headers: { Authorization: `Bearer ${process.env.WRIT_LOCAL_KEY}` },
});
console.log(await res.json());
```

```json
{
  "status": "ok",
  "version": "1.0.9",
  "db_ok": true,
  "keyring_ok": true
}
```

## OpenAI-compatible, webhooks and MCP

### Call a workflow as a chat model

POST `/v1/workflows/{id}/v1/chat/completions` Run automations

Point any OpenAI client at `/v1/workflows/{id}/v1` and the workflow answers as
the assistant. The last user message reaches the workflow as the input `message`; an `input` object passes named inputs. `/v1/responses` and `/v1/models` work
at the same base. Set `stream: true` for a live session workflow.

The workflow’s OpenAI access must be on in its **Call** tab; off, the call answers `404`.

```bash
curl -X POST "http://127.0.0.1:8131/v1/workflows/7/v1/chat/completions" \
  -H "Authorization: Bearer $WRIT_LOCAL_KEY" \
  -H "Content-Type: application/json" \
  -d '{"messages": [{"role": "user", "content": "Top 3 stories"}], "input": {"limit": 3}}'
```

```python
import os
from openai import OpenAI

client = OpenAI(
    base_url="http://127.0.0.1:8131/v1/workflows/7/v1",
    api_key=os.environ["WRIT_LOCAL_KEY"],
)
reply = client.chat.completions.create(
    model="writ:workflow:7",
    messages=[{"role": "user", "content": "Top 3 stories"}],
)
print(reply.choices[0].message.content)
```

```typescript
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "http://127.0.0.1:8131/v1/workflows/7/v1",
  apiKey: process.env.WRIT_LOCAL_KEY,
});
const reply = await client.chat.completions.create({
  model: "writ:workflow:7",
  messages: [{ role: "user", content: "Top 3 stories" }],
});
console.log(reply.choices[0].message.content);
```

```json
{
  "id": "chatcmpl-writ-413",
  "object": "chat.completion",
  "model": "writ:workflow:7",
  "choices": [
    {
      "index": 0,
      "message": { "role": "assistant", "content": "{ \"stories\": [ ... ] }" },
      "finish_reason": "stop"
    }
  ]
}
```

### Receive a webhook

POST `/v1/hooks/{token}` token in the URL

An incoming webhook runs the workflow it is linked to, with inputs taken from the JSON body. It
needs no key: the token in the URL is the access. When the webhook has a secret, send `X-Writ-Signature` with the hex HMAC-SHA256 of
the raw body (a `sha256=` prefix is accepted). A wrong signature answers `401`,
an unknown token `404`.

Create webhooks in **MCP & APIs → Endpoints → Incoming webhooks**. Over the public URL, use `https://.trycloudflare.com/v1/hooks/`.

```bash
BODY='{"sku": "A-1042"}'
SIG=$(printf '%s' "$BODY" | openssl dgst -sha256 -hmac "$WEBHOOK_SECRET" -hex | sed 's/^.* //')

curl -X POST "http://127.0.0.1:8131/v1/hooks/<token>" \
  -H "Content-Type: application/json" \
  -H "X-Writ-Signature: sha256=$SIG" \
  -d "$BODY"
```

```python
import hashlib, hmac, os, requests

body = b'{"sku": "A-1042"}'
sig = hmac.new(os.environ["WEBHOOK_SECRET"].encode(), body, hashlib.sha256).hexdigest()

res = requests.post(
    "http://127.0.0.1:8131/v1/hooks/<token>",
    data=body,
    headers={"Content-Type": "application/json", "X-Writ-Signature": f"sha256={sig}"},
)
print(res.json())
```

```typescript
import { createHmac } from "node:crypto";

const body = JSON.stringify({ sku: "A-1042" });
const sig = createHmac("sha256", process.env.WEBHOOK_SECRET!).update(body).digest("hex");

const res = await fetch("http://127.0.0.1:8131/v1/hooks/<token>", {
  method: "POST",
  headers: { "Content-Type": "application/json", "X-Writ-Signature": `sha256=${sig}` },
  body,
});
console.log(await res.json());
```

```json
{
  "run_id": 414,
  "accepted": true
}
```

### MCP endpoint

POST `/mcp` Run automations or OAuth

Writ Desktop’s MCP server over HTTP, at `http://127.0.0.1:8131/mcp`. Add `?tools=all` for every tool’s full reference. Most clients connect with the local
command instead: see [Connect an AI assistant](https://usewrit.app/docs/mcp).

```bash
curl -X POST "http://127.0.0.1:8131/mcp" \
  -H "Authorization: Bearer $WRIT_LOCAL_KEY" \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc": "2.0", "id": 1, "method": "tools/list"}'
```

## Errors

Every error has the same shape: a readable `error` and a stable `code`.

```json
{
  "error": "not found: workflow 7",
  "code": "not_found"
}
```

| Status | Code | Meaning |
| --- | --- | --- |
| 400 | bad_request | An input or parameter is wrong. |
| 401 | unauthorized | No key, or an unknown key. |
| 402 | plan_required | LAN mode or the public URL needs a paid plan. |
| 403 | forbidden | The key’s preset does not allow this call, or the workflow’s REST access is off. |
| 404 | not_found | No such workflow, run or monitor. |
| 409 | conflict | The resource is not in a state for this call. |
| 423 | vault_locked | The app lock is on. Unlock Writ Desktop, then call again. |
| 504 | (run still going) | A waited run did not finish in time. Poll its status_url. |

> **note:** The local API never charges credits. A run that uses Writ Cloud features (Writ’s AI gateway, a crawl on Writ’s servers) is billed like any cloud call.

## Next

-
- [Writ Desktop](https://usewrit.app/docs/desktop): Install the app, keys, LAN mode and the public URL.
-
- [SDKs](https://usewrit.app/docs/sdks): Python, TypeScript, Go and Rust clients with a local client built in.
-
- [Link Desktop to Writ Cloud](https://usewrit.app/docs/uplink): Call these APIs from anywhere through your Writ account.
