# OpenOps API Reference

- **Base URL:** `https://openops.run/api/v1`
- **Specification:** `https://openops.run/openapi.json` (OpenAPI 3.1)
- **Format:** UTF-8 JSON (`Content-Type: application/json`)

## Authentication

1. **Browser & Native Sessions:** `HttpOnly`, `Secure`, `SameSite=Lax` session cookie with double-submit CSRF protection on state-changing requests.
2. **Scoped API & Agent Tokens:** Pass `Authorization: Bearer ops_live_...` (human automation) or `Authorization: Bearer ops_agent_...` (delegated agent). Tokens are scoped to one workspace, explicit permission scopes, and optional expiry, and can be revoked immediately.

## Idempotency & Pagination

- **Idempotency:** Send an `Idempotency-Key` header (unique string, up to 128 chars) on all write endpoints (`POST /events/ingest`, `POST /incidents/:id/execute`, `POST /mcp` write tools). Re-sending the same key returns the original receipt without repeating the side effect.
- **Pagination:** List endpoints accept `?limit=25&cursor=<opaque_cursor>` and return `{ items: [...], next_cursor: string | null }`.

## Primary Endpoints

| Resource | Endpoints |
|---|---|
| **Health & Revision** | `GET /api/health`, `GET /api/health/ready`, `GET /api/revision` |
| **Auth & Account** | `GET /api/v1/auth/providers`, `POST /api/v1/auth/register`, `POST /api/v1/auth/login`, `POST /api/v1/auth/magic-link`, `GET /api/v1/me`, `GET /api/v1/auth/sessions`, `POST /api/v1/account/export`, `DELETE /api/v1/account` |
| **Workspaces & Team** | `GET/POST /api/v1/orgs`, `GET/POST /api/v1/workspaces`, `POST /api/v1/workspaces/:id/switch`, `POST /api/v1/workspaces/:id/invites`, `DELETE /api/v1/workspaces/:id/members/:memberId`, `GET/POST/DELETE /api/v1/workspaces/:id/tokens` |
| **Objectives** | `GET/POST /api/v1/objectives`, `POST /api/v1/objectives/compile`, `PATCH /api/v1/objectives/:id`, `POST /api/v1/objectives/:id/activate` |
| **Connectors & Events** | `GET /api/v1/connectors/catalog`, `GET/POST /api/v1/connectors`, `POST /api/v1/connectors/:id/{test,rotate,revoke}`, `POST /api/v1/events/ingest`, `GET /api/v1/graph` |
| **Incidents & Recovery** | `GET /api/v1/incidents`, `GET /api/v1/incidents/:id`, `POST /api/v1/incidents/:id/{plan,dry-run,execute,approve,verify,retry,pause,cancel,escalate,reopen}` |
| **Procedures & Agents** | `GET/POST /api/v1/procedures`, `POST /api/v1/procedures/:id/{dry-run,promote,pin,rollback}`, `GET /api/v1/marketplace`, `GET/POST /api/v1/agents/schedules` |
| **Insights & Billing** | `GET /api/v1/insights`, `GET /api/v1/insights/export`, `GET /api/v1/billing/{plans,summary,invoices}`, `POST /api/v1/billing/{checkout,portal,cancel}` |

## Webhook Signatures

Inbound generic webhooks and outbound OpenOps callbacks are signed using HMAC-SHA256:

```text
X-OpenOps-Timestamp: 1795700000
X-OpenOps-Signature: v1=<hex(HMAC-SHA256(secret, "<timestamp>.<raw_body>"))>
```

Verify signatures using constant-time comparison and reject timestamps older than 5 minutes.

## Standard Error Format

```json
{
  "error": {
    "code": "policy_denied",
    "message": "This action requires owner approval under active policy v2.",
    "trace_id": "tr_01J...",
    "retryable": false
  }
}
```
