# HTTP API

## Authentication

| Endpoints | Credential |
| --- | --- |
| `/mcp` | A user key: `Authorization: Bearer <key>` |
| `/api/*` (admin) | The admin token: `Authorization: Bearer <token>`, or `?token=<token>` for the event stream |
| `/api/*` (Cloud) | The `gg_session` cookie from signing in |
| `/healthz`, `/api/demo`, `POST /api/leads` | None |

## MCP

### `POST|GET|DELETE /mcp`

The MCP Streamable HTTP endpoint. See [MCP gateway](/docs/mcp-gateway).

## Admin

### `GET /api/state`

Everything the dashboard shows:

```json
{
  "servers": [{ "name": "github", "kind": "http", "url": "https://api.githubcopilot.com/mcp/", "oauth": false,
                "status": "connected", "connected": true, "error": null,
                "tools": [{ "name": "create_issue", "fullName": "github__create_issue", "description": "…",
                            "labels": ["egress"], "manualLabels": false, "readOnly": false,
                            "destructive": null, "quarantined": null }] }],
  "sessions": [{ "id": "…", "user": "alice", "taint": { "private": "github__get_file" },
                 "startedAt": 1792590000000, "lastSeen": 1792590060000, "calls": 4 }],
  "approvals": [{ "id": "…", "user": "alice", "tool": "github__delete_repo", "args": "{…}",
                  "reason": "…", "requestedAt": 1792590000000, "expiresAt": 1792590300000 }],
  "calls": [{ "id": "…", "ts": 1792590000000, "user": "alice", "tool": "…", "decision": "deny",
              "reason": "…", "status": "denied" }],
  "policy": { "default": "allow", "trifecta": "block", "approvalTimeoutSeconds": 300, "rules": [] }
}
```

`calls` holds the latest 200; `sessions` the 100 most recently active.

### Live events

`GET /api/events?token=<admin token>` is a Server-Sent Events stream:

| Event | Data |
| --- | --- |
| `call` | A call record, each time one is created or updated |
| `approvals` | The full list of pending approvals, whenever it changes |

```bash
curl -N "https://your-gate/api/events?token=$GODELGATE_ADMIN_TOKEN"
```

### `POST /api/approvals/:id`

Approve or reject a pending call. Body: `{"approve": true, "by": "alice"}`. `approve` must be exactly `true` to approve; anything else rejects. Returns `404` if the call isn't pending.

### `POST /api/servers/:server/refresh`

Re-read a server's tools now, applying [tool pinning](/docs/tool-pinning).

### `POST /api/servers/:server/tools/:tool/trust`

Pin the current definition of a tool and lift its quarantine. `:tool` is the tool's upstream name, without the server prefix.

### `GET /api/leads`

Demo requests and newsletter sign-ups from the landing page.

## Audit log

### `GET /api/calls`

The audit log, newest first. Query parameters, all optional: `user`, `status`, `decision`, `tool` (substring), `q` (searches tool, user, reason and arguments), `since` and `before` (milliseconds), `limit` (default 200). Page back by passing the oldest `ts` you have as `before`. Returns `{ "calls": [...], "users": [...] }`.

### `GET /api/calls.csv`

The same filters, as a CSV download of up to 10,000 calls. Cells that a spreadsheet would run as a formula are prefixed with `'`.

## Cloud workspaces

Available when `cloud.enabled` is `true`. The dashboard authenticates with an `HttpOnly` session cookie set by sign-up or sign-in. Cookie-authenticated writes must send `content-type: application/json`. Endpoints marked *admin* need the owner or admin role and return `403` otherwise.

### Accounts

| Endpoint | Description |
| --- | --- |
| `POST /api/auth/signup` | Body: `email`, `password` (10+ characters), optional `workspace`, optional `invite`. Creates the account and signs in; with an invite, joins that workspace instead of creating one. `409` if the email is taken. |
| `POST /api/auth/login` | Body: `email`, `password`, optional `invite`. `401` on wrong credentials. |
| `POST /api/auth/logout` | Ends the session. |
| `GET /api/auth/providers` | `{"google": true}` when Google sign-in is set up. |
| `GET /auth/google` | Starts Google sign-in. Optional `?invite=<token>` joins that workspace. |
| `GET /auth/google/callback` | Where Google sends the browser back. Signs in and redirects to `/app`, or to `/login?error=…`. |
| `GET /api/me` | The signed-in member: `email`, `role`, `groups`, current `workspace`, all `workspaces`, and `mcpUrl`. |
| `POST /api/account/password` | Body: `current`, `next`. Signs out your other sessions. |

Sign-up is limited to 5 and sign-in to 10 attempts per minute per client.

### Workspaces

| Endpoint | Description |
| --- | --- |
| `POST /api/workspaces` | Body: `name`. Creates a workspace you own and switches to it. |
| `POST /api/workspaces/switch` | Body: `id`. Switches this session's current workspace. |
| `PATCH /api/workspace` | *Admin.* Body: `name`. Renames the current workspace. |

### Keys

| Endpoint | Description |
| --- | --- |
| `GET /api/keys` | Your active keys in this workspace (name, prefix, created, last used). |
| `POST /api/keys` | Body: `name`. Returns the new `key` once. |
| `DELETE /api/keys/:id` | Revokes a key. |

### Servers

| Endpoint | Description |
| --- | --- |
| `GET /api/catalog` | The server catalog. |
| `POST /api/servers` | *Admin.* Body: `name`, `url`, optional `headers` (object), `oauth` (boolean), `catalog` (a catalog id, which fills in the URL, sign-in and labels). With `type: "openapi"`, `url` is an OpenAPI document and `baseUrl` is optional. With `type: "hosted"`: `runtime` (`npx` or `uvx`), `package`, `args`, `env` — answers `status: "connecting"` and starts the microVM in the background. Connects at once and returns `status` (`connected`, `needs_auth`, `error`), `error` and, for OAuth, `authorizeUrl` to send the person to. |
| `PATCH /api/servers/:name` | *Admin.* Body: any of `url`, `headers` (a header set to `""` is removed; headers left out keep their value), `oauth`. Reconnects. |
| `DELETE /api/servers/:name` | *Admin.* Removes the server, its credentials and its tool pins. |
| `POST /api/servers/:name/reconnect` | *Admin.* Connects again. |
| `POST /api/servers/:name/oauth` | *Admin.* Starts signing in; returns `authorizeUrl`. Body `{"reset": true}` forgets the current sign-in first. |
| `POST /api/servers/:name/tools/:tool/labels` | *Admin.* Body: `{"labels": ["private"]}`, or `{"labels": null}` to return to automatic labels. |
| `GET /oauth/callback` | Where OAuth servers send the browser back. Finishes sign-in and redirects to the dashboard. |

### Policy

`PUT /api/policy` (*admin*) replaces the workspace policy. The body is the `policy` object described in [Configuration](/docs/configuration#policy). Invalid policies are refused with `400` and the first problem.

### Models, usage and Chat

| Endpoint | Description |
| --- | --- |
| `GET /api/llm` | Provider keys (masked, for admins), budgets, prices, proxy URLs and this month's spend |
| `PUT /api/llm` | *Admin.* Any of `anthropicKey`, `openaiKey` (`null` removes), `monthlyBudget`, `memberBudget` (USD or `null`), `prices` (`{model: {input, output}}`, USD per million tokens) |
| `GET /api/usage` | This month's usage: totals, by person, by model, by day and recent requests. Members get their own. |
| `POST /api/chat` | Body: `messages` (Messages API format), `model`, `conversation`. Answers with Server-Sent Events: `text`, `tool`, `tool_result`, `usage`, `done` (the updated messages) or `error`. |
| `POST /llm/...` | The [LLM proxy](/docs/llm-proxy), authenticated with a `gg_` key |

### SSO, SCIM and telemetry

| Endpoint | Description |
| --- | --- |
| `GET /api/sso`, `PUT /api/sso`, `DELETE /api/sso` | *Owner.* The SSO connection: `type` (`oidc` with `issuer`, `clientId`, `clientSecret`; or `saml` with `metadataXml`, or `entryPoint` and `idpCert`), `defaultRole`, `enforced` |
| `POST /api/sso/domains`, `POST /api/sso/domains/:domain/verify`, `DELETE /api/sso/domains/:domain` | *Owner.* Domains and DNS verification |
| `POST /api/scim/token`, `DELETE /api/scim/token` | *Owner.* Create (shown once) or revoke the SCIM token |
| `/scim/v2/Users`, `/scim/v2/Groups` | SCIM 2.0, with the SCIM token; see [Single sign-on and SCIM](/docs/sso) |
| `POST /api/auth/sso` | Public. Body `email`; returns the SSO start URL for that email's domain |
| `GET /api/telemetry`, `PUT /api/telemetry`, `POST /api/telemetry/test` | *Admin.* The OpenTelemetry collector (`endpoint`, `headers`) |
| `GET /metrics` | Prometheus metrics, with the admin token |

### Team

| Endpoint | Description |
| --- | --- |
| `GET /api/members` | Members (email, role, groups, joined) and, for admins, pending invites. |
| `PATCH /api/members/:accountId` | *Admin.* Body: `role` and/or `groups`. Ends the member's open MCP sessions. |
| `DELETE /api/members/:accountId` | *Admin.* Removes the member and revokes their keys in this workspace. |
| `POST /api/invites` | *Admin.* Body: `role`, optional `email`. Returns the invite `url`. |
| `DELETE /api/invites/:id` | *Admin.* Revokes a pending invite. |
| `GET /api/invites/:token` | Public: the workspace name and role an invite is for. |
| `POST /api/invites/:token/accept` | Joins the workspace with the signed-in account. |

## Public

### `GET /healthz`

Returns `{"ok": true}`.

### `POST /api/demo`

Runs the attack demo on an isolated in-memory gate and returns the steps. Only when `demo.public` is `true`. Limited to 10 per minute per IP.

### `POST /api/leads`

Stores a demo request. Body: `email` (required), `company`, `teamSize`, `message`. Limited to 5 per minute per IP.

## Errors

Admin and public endpoints return errors as JSON, `{"error": "…"}`, with status `400`, `401`, `404`, `429` or `500`. The MCP endpoint answers a missing or unknown key with a plain-text `401`.
