# Writing runs over the HTTP API

Use the API when your agent or test harness is not one of the supported agents: create a run, add frames, commands, and artifacts as they happen, then finalize it and share the link. The CLI, hooks, and overlay use these same endpoints.

## Base URL and keys

The base URL is `https://api.23step.com`. Send `Authorization: Bearer st_...` on every call. A key in a query string is rejected. Create keys on [Account](https://app.23step.com/app/account): `runs:write` creates and writes runs, `runs:read` reads them. Requests are rate limited per key and per organization, and image uploads have a daily byte allowance; both depend on the plan. Over a limit the API answers `429` with `Retry-After`.

New steps get your organization's default visibility (set in Settings, private unless an admin changed it). Change it per step in the browser or with `PATCH /s/{share_id}`. Secrets (API keys, tokens, passwords, private keys) are always redacted before storage; email PII is redacted by default and can be toggled per organization in Settings.

## Endpoints

Runs (https://api.23step.com):

| Method and path | Scope | Purpose |
| --- | --- | --- |
| `POST /runs` | `runs:write` | Create a run. Returns `run_id` and `viewer_url`. |
| `POST /runs/{id}/frames` | `runs:write` or `up_` | Describe one frame (or up to 50 as `{"frames":[…]}`) and get an upload URL for each PNG. |
| `PUT <upload_url>` | none | Upload the PNG. The URL is valid for 15 minutes. |
| `POST /runs/{id}/commands` | `runs:write` or `up_` | Record one shell command: text, cwd, exit code, timing. Never stdout or stderr. |
| `POST /runs/{id}/artifacts` | `runs:write` | Attach a Markdown document or a PNG the agent produced. |
| `POST /runs/{id}/frames/{seq}/note` | `runs:write` | Add an agent note to a frame (`{"text":"…"}`). |
| `POST /runs/{id}/heartbeat` | `runs:write` | Mark a long, quiet run as alive. |
| `POST /runs/{id}/upload-token` | `runs:write` | Mint an `up_` token for a subagent that may write only to this run. |
| `POST /runs/{id}/finalize` | `runs:write` | Close the run and write its manifest. |
| `POST /runs/{id}/share` | `runs:write` | Get the step link (`step_url`). |
| `GET /runs/{id}` | `runs:read` | Manifest: frames in `seq` order, gaps, `finalized`. |
| `GET /runs/{id}/frames/{seq}` | `runs:read` | Download the stored PNG for one frame. |
| `GET /runs/{id}/feedback` | `runs:read` or `runs:write` | Review comments left on the step. `?include_session=1` adds the session's other runs. |
| `DELETE /runs/{id}` | `runs:write` (owner) | Delete the run and its images. Returns `204`. |

Steps (browser session, or unauthenticated when public) (https://app.23step.com):

| Method and path | Purpose |
| --- | --- |
| `GET /s/{share_id}.json` | The step as JSON (schema `23step.step/v2`). Public steps need no auth; private/org steps use the browser session cookie (for API-key reads, use `/runs/{id}` or [MCP](https://23step.com/docs/v0.1/mcp.md)). |
| `GET /s/{share_id}.md` | The step as Markdown, for handing to another AI. |
| `PATCH /s/{share_id}` | Signed-in owner: change `visibility` (`private`, `squad`, `team`, `org`, `public`), `discoverability`, or retention (`retention_mode`: `default`, `days`, `forever`, with `retention_days`). `apply_to_session: true` updates every run in the session. |
| `POST /s/{share_id}/comments` | Signed-in viewer in the org: comment on the step (`{"text":"…"}`). Comments reach a running agent through `feedback`. |

## 1. Create a run

`screen_w`, `screen_h`, and `scale` describe the coordinate space of the frames you will send (`scale` must be above 0). Everything else is optional. `prompt` is redacted and capped at 16 KB. `session_id` chains successive prompts of one conversation; `previous_step` names an earlier run explicitly; `correlation_id` puts a parent agent and its subagents in one run. Set `join_session: true` to attach to a run already open for `session_id` instead of creating a second one.

Terminal (POST /runs):

```sh
curl -sS https://api.23step.com/runs \
  -H "Authorization: Bearer $STEP23_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "run_name": "nightly-e2e",
    "screen_w": 1280, "screen_h": 720, "scale": 1,
    "source": "my-harness",
    "prompt": "Check that checkout totals include tax",
    "session_id": "conv-8812",
    "agent_name": "e2e-bot",
    "git_repo": "github.com/acme/shop", "git_branch": "main"
  }'
# {"run_id":"6f0c2a7e-...","viewer_url":"https://api.23step.com/runs/6f0c2a7e-.../view"}
```

Optional run metadata:

| Field | Meaning |
| --- | --- |
| `run_name`, `source`, `hostname` | Label, the client that recorded it, and the machine. |
| `agent_name`, `agent_role`, `session_title`, `conversation_id` | Shown on the run and the session. |
| `git_repo`, `git_branch`, `workspace` | Where the agent worked. |
| `is_background`, `background_kind` | Background task: `command`, `subagent`, `schedule`, `workflow`, `swarm`. |

## 2. Add frames

Each frame is two requests: a JSON description, then a PUT of the PNG to the `upload_url` it returns. `seq` runs from 1 to 5000, orders the timeline, and is the idempotency key: sending the same `seq` again returns the same object and a fresh URL. Send `Content-Type: image/png` and `x-goog-if-generation-match: 0` on the PUT; a `412` means the image is already stored and counts as success.

Required fields: `seq`, `trigger` (`click`, `key`, or `timer`), `ts` (RFC 3339), `x`, `y`, `window_title`, `app`. Optional: `url`, `button`, `key_category` (a class such as `letter` or `enter`, never the key), `description`, and `dom_snapshot` (page text, so an AI can read the frame without the image).

Terminal (POST /runs/{id}/frames + PUT):

```sh
RUN=6f0c2a7e-5d1b-4c39-9a51-0b7f3f8e2c11

# 1. Describe the frame. The response holds a short-lived upload URL.
UP=$(curl -sS https://api.23step.com/runs/$RUN/frames \
  -H "Authorization: Bearer $STEP23_TOKEN" -H "Content-Type: application/json" \
  -d '{"seq":1,"trigger":"click","ts":"2026-11-23T10:00:00Z","x":640,"y":360,
       "window_title":"Checkout","app":"chrome","url":"https://shop.example/checkout","button":1}' \
  | python3 -c 'import json,sys; print(json.load(sys.stdin)["upload_url"])')

# 2. PUT the PNG there. No bearer on this request.
curl -sS -X PUT "$UP" -H "Content-Type: image/png" \
  -H "x-goog-if-generation-match: 0" --data-binary @frame-0001.png
```

## 3. Record commands and artifacts

Commands go on the same timeline as frames. They are redacted and capped at 8 KB, and limited to 10 per second per key. Artifacts are files the agent produced: `kind` is `markdown` (with `text`, up to 256 KB) or `image` (with base64 `png`). Each becomes one or more frames.

Terminal (POST /runs/{id}/commands):

```sh
curl -sS https://api.23step.com/runs/$RUN/commands \
  -H "Authorization: Bearer $STEP23_TOKEN" -H "Content-Type: application/json" \
  -d '{"command":"npm test","cwd":"/src/shop","shell":"bash","exit_code":0,
       "started_at":"2026-11-23T10:00:05Z","duration_ms":8120}'
# {"seq":2,"branch":"main","received_at":"..."}
```

Terminal (POST /runs/{id}/artifacts):

```sh
curl -sS https://api.23step.com/runs/$RUN/artifacts \
  -H "Authorization: Bearer $STEP23_TOKEN" -H "Content-Type: application/json" \
  -d '{"name":"REPORT.md","kind":"markdown","text":"# Result\n\nAll 14 checks passed."}'
# {"seqs":[4001]}
```

## 4. Finalize and share

A run that stops receiving anything is eventually closed by the server. Send a heartbeat during long quiet stretches. `finalize` takes an optional body: `outcome` (such as `completed`, `error`, or `stopped_by_user`), `reason`, `killed`, and the same session and git metadata as `POST /runs`. A run that was never finalized still has a manifest from `GET /runs/{id}`.

Terminal (heartbeat, finalize, share):

```sh
# Keep a long run from being reaped as idle
curl -sS -X POST https://api.23step.com/runs/$RUN/heartbeat -H "Authorization: Bearer $STEP23_TOKEN"

# Close it
curl -sS https://api.23step.com/runs/$RUN/finalize -H "Authorization: Bearer $STEP23_TOKEN" \
  -H "Content-Type: application/json" -d '{"outcome":"completed"}'
# {"ok":true,"frame_count":3,"gaps":[]}

# Get the step link
curl -sS -X POST https://api.23step.com/runs/$RUN/share -H "Authorization: Bearer $STEP23_TOKEN"
# {"share_id":"9b1c...","step_url":"https://app.23step.com/s/9b1c...","visibility":"private",...}
```

## Subagents

Give a subagent an `up_` token instead of your key. It lasts one hour by default and at most 24 hours (`ttl_seconds`, up to 86400) and can only add frames and commands to that one run: it cannot read, delete, or touch another run. Send it as `Authorization: Bearer up_...`. Mark the subagent's entries with `branch` and `parent_branch` so the step draws them as their own lane.

Terminal (POST /runs/{id}/upload-token):

```sh
curl -sS https://api.23step.com/runs/$RUN/upload-token \
  -H "Authorization: Bearer $STEP23_TOKEN" -H "Content-Type: application/json" \
  -d '{"ttl_seconds":3600}'
# {"token":"up_...","expires_at":"2026-11-23T11:00:00Z","run_id":"6f0c..."}
```

## Read a step back

Terminal:

```sh
# API-key reads (runs:read)
curl -sS https://api.23step.com/runs/$RUN           -H "Authorization: Bearer $STEP23_READ_KEY"
curl -sS https://api.23step.com/runs/$RUN/frames/1  -H "Authorization: Bearer $STEP23_READ_KEY" -o frame-1.png
curl -sS https://api.23step.com/runs/$RUN/feedback  -H "Authorization: Bearer $STEP23_TOKEN"

# Public steps (or any step with a signed-in browser session cookie)
curl -sS https://app.23step.com/s/<share_id>.json
curl -sS https://app.23step.com/s/<share_id>.md
```

## OpenTelemetry (OTLP)

Agents that already emit OpenTelemetry can send it directly: `POST https://api.23step.com/v1/traces` and `POST /v1/logs` accept OTLP/HTTP as protobuf (`application/x-protobuf`) or JSON, optionally gzip-compressed, with the same bearer key. Spans are mapped with the GenAI semantic conventions: `gen_ai.conversation.id` groups a session, prompts, thoughts, tool calls and results, responses, and token counts (`gen_ai.usage.*`) become the step's timeline.

OTel exporter:

```sh
export OTEL_EXPORTER_OTLP_ENDPOINT=https://api.23step.com
export OTEL_EXPORTER_OTLP_HEADERS="Authorization=Bearer st_REPLACE_WITH_YOUR_WRITE_KEY"
export OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
```

---

Version: `v0.1` (archived — latest is https://23step.com/docs/http-api.md). All v0.1 developer docs: https://23step.com/docs/v0.1.md
