Source: https://sopops.dev/docs/api/

# API reference

Every sopops endpoint, grouped by what you're trying to do. Paths start with `/v1`, and `{ws}` is a workspace id (each team has one).

The examples use two variables:

| Variable | What | Hosted | Self-hosted |
|---|---|---|---|
| `SOPOPS_URL` | The workspace's API URL, as Settings → Access → Tokens prints it and the SDKs read it. Calls under `/v1/workspaces/{ws}` start here. | `https://sopops.dev/api/v1/workspaces/<id>` | `http://127.0.0.1:8484/v1/workspaces/<id>` |
| `SOPOPS_API` | The server's API root, for calls outside a workspace (`/v1/auth`, `/v1/org`, `/v1/orgs`, `/v1/workspaces`, `/v1/validate`, `/v1/render`, `/v1/lint`, `/v1/migrate`, `/v1/onboarding`, `/v1/github`). | `https://sopops.dev/api` | `http://127.0.0.1:8484` |

So `GET /v1/workspaces/{ws}/agents/{agent}` is:

```sh
curl -s -H "Authorization: Bearer $SOPOPS_TOKEN" \
  "$SOPOPS_URL/agents/copper-wok-harbor"
```

| Where | What |
|---|---|
| `/openapi.json` | The OpenAPI spec: every field. |
| `/docs` | Try each endpoint in a browser. |
| `operationId` | Each operation's route name (`list_workspaces`, `get_agent`, `config_put_procedure`), so generated clients read well. The web UI's typed client (`web/src/client`) is generated this way. |
| Everything else | Paths outside `/v1`, `/docs` and `/openapi.json` serve the web UI. |

## Pagination

For a collection GET such as `/v1/workspaces/{ws}/review`, request `?limit=50&offset=0`. If the response includes `X-Next-Offset`, pass that value as the next request's `offset` and keep the same filters and limit. The final page omits the header. Rows can move between pages when the collection changes. Omitting pagination parameters keeps each endpoint's previous default.

Sessions also support cursor pagination. Pass the response body's `next_cursor` as the next request's `cursor`. For numbered pages, use `offset` and `limit`. The web app shows ten rows per page. Where a count is available, `include_total=true` requests the filtered total in `X-Total-Count`.

## Pages

| Page | What it covers |
|---|---|
| [Agents and config](https://sopops.dev/docs/api/agents-and-config.md) | Editing agents, shared instructions, procedures and groups; the files behind them; stateless sop checks |
| [Releases](https://sopops.dev/docs/api/releases.md) | Publishing and rolling back, serving instructions when a call starts, and pushing them to ElevenLabs or Vapi |
| [Sessions](https://sopops.dev/docs/api/sessions.md) | Sending calls and chats to sopops, streaming, backfill, the session format, and importing a file |
| [Checks and review](https://sopops.dev/docs/api/checks-and-review.md) | How sessions are checked, grouped mistakes, verdicts, suggested fixes, and reworded rules |
| [Insights](https://sopops.dev/docs/api/insights.md) | Pass rates, trends, release comparisons, A/B tests, and model spend |
| [Teams and access](https://sopops.dev/docs/api/teams-and-access.md) | Sign-in, teams and members, tokens, and a team's AI keys and models |
| [Import](https://sopops.dev/docs/api/import.md) | Importing agents' existing instructions, including the endpoints a coding agent calls |
| [GitHub](https://sopops.dev/docs/api/github.md) | Connecting a repository, syncing, and the GitHub App |

## Authentication

| Caller | Sends |
|---|---|
| Agents, webhooks, coding agents | A workspace token as `Authorization: Bearer <token>` ([Tokens](https://sopops.dev/docs/api/teams-and-access.md#tokens)) |
| Everyone else, once sign-in is on | A signed-in session: password, GitHub, Google or email ([Sign-in](https://sopops.dev/docs/sign-in.md)) |

With sign-in off, only tokens guard anything, so keep sopops on a private network. [Sign-in and access](https://sopops.dev/docs/api/teams-and-access.md#sign-in-and-access) lists which endpoints need what.

## Errors

| Status | Body |
|---|---|
| `404`, `409` | `{"detail": "..."}` |
| `404`, no such endpoint | `{"error": "no_such_endpoint", "detail", "nearest": [{"methods", "path", "url"}], "docs", "openapi"}` |
| `405`, wrong method | `{"error": "method_not_allowed", "detail", "allowed_methods", "docs", "openapi"}`, and an `Allow` header |
| `422`, request doesn't match the schema | `{"error": "invalid_request", "message", "detail": [{"loc", "msg", ...}], "openapi"}`. `message` names each field to change |
| `422` from sop | `{"valid": false, "issues": [...]}` |
| `429` | `{"detail": "..."}`, and a `Retry-After` header in seconds |
| `500` | `{"error": "internal_error", "detail": "..."}`. Nothing in the request needs to change; session ingest is safe to resend |

```json
{
  "valid": false,
  "issues": [
    {
      "code": "unknown_block",
      "message": "blocks lists 'nope', which is not an instruction, SOP or group",
      "path": "agents/bayleaf-bistro.yaml",
      "severity": "error",
      "kind": "agent",
      "id": "bayleaf-bistro",
      "field": "blocks",
      "index": null,
      "text": "Lists 'nope', which isn't a shared instruction, procedure or group."
    }
  ]
}
```

| Field | Type | |
|---|---|---|
| `code`, `message`, `path`, `severity` | string | sop's own. `severity` is `error` or `warning`. |
| `kind` | string | `agent`, `instruction`, `procedure`, `group` or `settings`. |
| `id` | string | Which one. |
| `field` | string | As the `/config` endpoints name it, e.g. `blocks`, `steps`. |
| `index` | int | Which entry of a list field. |
| `text` | string | The problem in plain words. |
