#### Cloud Agents

# Cloud Agents API

> [!NOTE]
> Public beta
>
> The Cloud Agents API v1 is in public beta. APIs may change before general
> availability.

The Cloud Agents API lets you programmatically launch and manage cloud agents that work on your repositories, along with the [environments](#environments) they run in.

* The Cloud Agents API accepts both [Basic and Bearer authentication](/build/agents-window/api#authentication). Generate a user API key from [Grok Dashboard → API Keys](https://grok.com/dashboard/api-keys), or use a [service account API key](/build/agents-window/account/enterprise/service-accounts).
* For details on authentication methods, rate limits, and best practices, see the [API Overview](/build/agents-window/api).
* View the full [OpenAPI specification](/build/agents-window/cloud-agents-openapi.yaml) for detailed schemas and examples.
* Webhooks are coming soon. The legacy [v0 API](/build/agents-window/cloud-agent/api/v0) still supports them—see [Webhooks](/build/agents-window/cloud-agent/api/webhooks).

> [!NOTE]
> Migrating from v0?
>
> This API splits work into a durable agent plus per-prompt runs, replacing the flatter v0 surface. The legacy [v0 reference](/build/agents-window/cloud-agent/api/v0) remains available.

> [!NOTE]
>
> The 15 MB image limit below applies to API image inputs. Web attachments at
> [cursor.com/agents](https://cursor.com/agents) use separate limits. See
> [Cloud Agent web attachment limits](/build/agents-window/help/ai-features/cloud-agents#what-are-the-attachment-limits-for-cloud-agents-on-the-web).

## Endpoints

### Create an agent

**POST /v1/agents**

Create a Cloud Agent and immediately enqueue its initial run. The response returns both the durable `agent` and the initial `run`.

Repositories can come from any source control provider Grok Build supports: GitHub (Cloud and Enterprise Server), GitLab (Cloud and Self-Hosted), Bitbucket Cloud, and Azure DevOps. Pass the repository URL as it appears on your provider, including a self-hosted host such as `gitlab.example.com`. See [Cloud Agents setup](/build/agents-window/cloud-agent/setup) for connecting a provider.

#### Request body

`prompt` object (required) — The task prompt for the agent, including optional images.

`prompt.text` string (required) — The instruction text for the agent.

`prompt.images` array (optional) — Image inputs for the prompt. Each entry must include either data (base64-encoded bytes with a required mimeType) or url (an http or https URL that Grok Build fetches). Maximum 5 images, 15 MB each. Supported MIME types: image/png, image/jpeg, image/gif, image/webp.

`model` object (optional) — Model selection. Omit this field to use the configured default. When omitted, Grok Build resolves your user default model, then your team default model, then a system default.

`model.id` string (required if \`model\` provided) — An explicit model ID returned by GET /v1/models (for example, claude-4-sonnet-thinking).

`model.params` array (optional) — Per-model parameters to apply to the run, such as reasoning effort or context window size. Each item has an id and value. Use only parameters supported by the selected model—call GET /v1/models to discover the valid id/params combinations.

`name` string (optional) — Display name for the agent. Maximum 100 characters. When omitted, Grok Build auto-derives a name from the prompt.

`env` object (optional) — Execution environment target. Use a named cloud environment, or route to a pool or machine you host. Mutually exclusive with explicit repos when selecting a named managed environment.

`env.type` string (required if \`env\` provided) — Execution environment type. cloud uses managed VMs; pool and machine route to your own workers.

`env.name` string (optional) — Named managed environment, pool, or machine name. For env.type: "pool", this is the pool name (defaults to default when omitted). An unknown pool name returns 400 instead of queueing forever. Name an any-repo pool to send more than one entry in repos.

`repos` array (optional) — Repository configuration. Mutually exclusive with a named cloud environment. Omit both repos and env to start a no-repo agent. You can also omit repos when env.type is pool to target an any-repo pool. Maximum 500 repositories.

On self-hosted targets, only a named any-repo pool takes more than one repository. `machine`, the `default` pool, and repo-backed pools take one; sending more returns `400 validation_error` with the message "My Machines and repo-bound pools accept one repo in repos. To start an agent with several repos, set env.name to an any-repo pool."

`repos[0].url` string (required) — Repository URL on any connected source control provider (for example, https://github.com/your-org/your-repo or https://gitlab.example.com/your-group/your-repo). Required on every repo entry, including when prUrl is provided.

`repos[0].startingRef` string (optional) — Branch name or full 40-character commit SHA to use as the starting point. Ignored when prUrl is provided.

`repos[0].prUrl` string (optional) — Pull request URL, called a merge request URL on GitLab. When provided, the agent works on that request's repository and branches; startingRef is ignored. url must still be set on the same repos entry.

`workOnCurrentBranch` boolean (optional, default: false) — When false (the default), Grok Build pushes commits to a new auto-generated branch (cursor/...) based on repos\[0].startingRef (or the PR base ref when prUrl is set). When true, Grok Build pushes directly to that starting ref—for a non-PR create, that's the branch you passed in startingRef; for a prUrl create, that's the PR's head branch. The branch the agent pushed shows up in the agent's git.branches\[].

`autoCreatePR` boolean (optional) — Whether Grok Build should open a pull request when the run completes.

`skipReviewerRequest` boolean (optional) — Whether to skip requesting the user as a reviewer when Grok Build opens a PR. Only applies when autoCreatePR is true.

`envVars` object (optional) — Session-scoped environment variables for the cloud agent. Values are encrypted at rest, injected into the agent's shell, and deleted with the agent. Maximum 50 entries. Each name is 1 to 255 characters of ASCII letters, digits, and underscores, doesn't start with a digit, can't start with CURSOR\_, and can't contain CURSOR\_SANDBOX in any letter case. Each value is non-empty and at most 4096 UTF-8 bytes. Cannot be combined with a client-supplied agentId.

On self-hosted targets, `envVars` reach only pool workers that run with `--sync-dashboard-secrets` while a team admin has **Secret sync** on. `machine` targets and other pool workers run without them. See [Environments on Self-Hosted Machines](/build/agents-window/cloud-agent/self-hosted#environments-on-self-hosted-machines).

**Beta:** `envVars` is rolling out. If it isn't enabled for your account yet, the field is silently ignored on create rather than failing the request—verify the values are present by inspecting the agent shell on a first run before relying on them in production.

`mcpServers` array (optional) — Inline MCP server definitions available to the agent. Maximum 50 servers. Remote servers support headers or OAuth auth; stdio servers run inside the cloud VM and can receive env. Server names must be unique.

`mcpServers[0].name` string (required) — The MCP server name exposed to the agent.

`mcpServers[0].type` string (optional) — Transport type: http, sse, or stdio. Defaults to http for remote servers with url, and stdio for servers with command.

`mcpServers[0].url` string (required for remote MCP) — HTTP or HTTPS URL for a remote MCP server. URLs with username or password are not allowed.

`mcpServers[0].command` string (required for stdio MCP) — Command to start a stdio MCP server inside the cloud agent VM. Use args and env for arguments and runtime secrets.

`customSubagents` array (optional) — Define custom subagents the main agent can delegate to during the run. Maximum 20 subagents. Each entry requires name, description, and prompt, plus an optional model (model ID string, ModelSelection object, or "inherit"). Names must be unique and cannot collide with built-ins (explore, debug, shell, computerUse, etc.).

`mode` string (optional, default: agent) — Initial conversation mode for the agent's first run. plan explores and drafts a plan before coding (Plan mode); agent implements changes directly.

`agentId` string (optional) — Client-supplied agent identifier in the form bc-\<uuid>. Useful for idempotent create flows—re-POSTing the same agentId returns 409 agent\_id\_conflict rather than creating a duplicate. Cannot be combined with envVars; omit agentId so the server mints one when you need session secrets.

```bash
curl --request POST \
  --url https://api.cursor.com/v1/agents \
  -u YOUR_API_KEY: \
  --header 'Content-Type: application/json' \
  --data '{
    "prompt": {
      "text": "Add a README with setup instructions"
    },
    "model": {
      "id": "composer-2",
      "params": [
        { "id": "fast", "value": "true" }
      ]
    },
    "repos": [
      {
        "url": "https://github.com/your-org/your-repo",
        "startingRef": "main"
      }
    ],
    "mcpServers": [
      {
        "name": "linear",
        "type": "http",
        "url": "https://mcp.linear.app/sse",
        "headers": {
          "Authorization": "Bearer YOUR_LINEAR_API_KEY"
        }
      },
      {
        "name": "github",
        "type": "stdio",
        "command": "npx",
        "args": ["-y", "@modelcontextprotocol/server-github"],
        "env": {
          "GITHUB_TOKEN": "YOUR_GITHUB_TOKEN"
        }
      }
    ],
    "autoCreatePR": true
  }'
```

Self-hosted GitLab repository:

```bash
curl --request POST \
  --url https://api.cursor.com/v1/agents \
  -u YOUR_API_KEY: \
  --header 'Content-Type: application/json' \
  --data '{
    "prompt": {
      "text": "Add a README with setup instructions"
    },
    "repos": [
      {
        "url": "https://gitlab.example.com/your-group/your-repo",
        "startingRef": "main"
      }
    ]
  }'
```

Worker pool (including any-repo):

```bash
curl --request POST \
  --url https://api.cursor.com/v1/agents \
  -u YOUR_API_KEY: \
  --header 'Content-Type: application/json' \
  --data '{
    "prompt": {
      "text": "Clone the payments service and add a health check"
    },
    "env": {
      "type": "pool",
      "name": "sandbox"
    }
  }'
```

Any-repo pool with several repos:

```bash
curl --request POST \
  --url https://api.cursor.com/v1/agents \
  -u YOUR_API_KEY: \
  --header 'Content-Type: application/json' \
  --data '{
    "prompt": {
      "text": "Update the API client and the web app together"
    },
    "env": {
      "type": "pool",
      "name": "my-pool"
    },
    "repos": [
      {
        "url": "https://github.com/your-org/your-api",
        "startingRef": "main"
      },
      {
        "url": "https://github.com/your-org/your-web-app",
        "startingRef": "main"
      }
    ]
  }'
```

**Response:**

```json
{
  "agent": {
    "id": "bc-00000000-0000-0000-0000-000000000001",
    "name": "Add README with setup instructions",
    "status": "ACTIVE",
    "env": {
      "type": "cloud"
    },
    "repos": [
      {
        "url": "https://github.com/your-org/your-repo",
        "startingRef": "main"
      }
    ],
    "workOnCurrentBranch": false,
    "autoCreatePR": true,
    "url": "https://cursor.com/agents/bc-00000000-0000-0000-0000-000000000001",
    "createdAt": "2026-04-13T18:30:00.000Z",
    "updatedAt": "2026-04-13T18:30:00.000Z",
    "latestRunId": "run-00000000-0000-0000-0000-000000000001"
  },
  "run": {
    "id": "run-00000000-0000-0000-0000-000000000001",
    "agentId": "bc-00000000-0000-0000-0000-000000000001",
    "status": "CREATING",
    "createdAt": "2026-04-13T18:30:00.000Z",
    "updatedAt": "2026-04-13T18:30:00.000Z"
  }
}
```

### List agents

**GET /v1/agents**

List agents for the authenticated user, newest first.

#### Query parameters

`limit` number (optional) — Number of agents to return. Default: 20, Max: 100.

`cursor` string (optional) — Pagination cursor from nextCursor on the previous response.

`prUrl` string (optional) — Filter agents by pull request URL, called a merge request URL on GitLab.

`includeArchived` boolean (optional, default: true) — Whether to include archived agents in the response.

> [!NOTE]
>
> List items only include the durable identity fields. Call `GET /v1/agents/{id}` to load the full record (`repos`, `workOnCurrentBranch`, `autoCreatePR`, etc.).

> [!NOTE]
>
> `nextCursor` is **omitted** from the response when there are no more pages—it is not returned as `null`. Treat its absence as "no more results".

```bash
curl --request GET \
  --url 'https://api.cursor.com/v1/agents?limit=20' \
  -u YOUR_API_KEY:
```

**Response:**

```json
{
  "items": [
    {
      "id": "bc-00000000-0000-0000-0000-000000000001",
      "name": "Add README with setup instructions",
      "status": "ACTIVE",
      "env": {
        "type": "cloud"
      },
      "url": "https://cursor.com/agents/bc-00000000-0000-0000-0000-000000000001",
      "createdAt": "2026-04-13T18:30:00.000Z",
      "updatedAt": "2026-04-13T18:45:00.000Z",
      "latestRunId": "run-00000000-0000-0000-0000-000000000001"
    }
  ],
  "nextCursor": "bc-00000000-0000-0000-0000-000000000002"
}
```

### Get an agent

Retrieve durable metadata for an agent. Execution status lives on runs—fetch `latestRunId` and call [Get A Run](#get-a-run) to read run state.

#### Path parameters

`id` string — Unique identifier for the agent (for example, bc-00000000-0000-0000-0000-000000000001).

#### Response fields

`status` string — Agent lifecycle status. Controllers use it to decide whether a machine must stay up:

* `ACTIVE`: A turn is running, waiting on background work, or about to start. Keep the agent's machine up.
* `IDLE`: The last turn finished and follow-ups are accepted. The agent's machine may be [hibernated or snapshotted](/build/agents-window/cloud-agent/self-hosted/pool#hibernation). Runs that ended in a recoverable error also report `IDLE`; run-level error detail stays on [Get A Run](#get-a-run).
* `ARCHIVED`: The agent was archived or expired. Terminal; claims end and workspace state can be deleted.

```bash
curl --request GET \
  --url https://api.cursor.com/v1/agents/bc-00000000-0000-0000-0000-000000000001 \
  -u YOUR_API_KEY:
```

**Response:**

```json
{
  "id": "bc-00000000-0000-0000-0000-000000000001",
  "name": "Add README with setup instructions",
  "status": "ACTIVE",
  "env": {
    "type": "cloud"
  },
  "repos": [
    {
      "url": "https://github.com/your-org/your-repo",
      "startingRef": "main"
    }
  ],
  "workOnCurrentBranch": false,
  "autoCreatePR": true,
  "url": "https://cursor.com/agents/bc-00000000-0000-0000-0000-000000000001",
  "createdAt": "2026-04-13T18:30:00.000Z",
  "updatedAt": "2026-04-13T18:30:00.000Z",
  "latestRunId": "run-00000000-0000-0000-0000-000000000001"
}
```

### Send a follow-up or steer

Send a follow-up prompt to an existing active agent. Without `delivery`, the prompt starts a new run that uses the agent's current conversation and workspace state.

> [!NOTE]
>
> Only one run can be active per agent. Without `delivery`, calling this while another run is `CREATING`, `RUNNING`, or `WAITING_FOR_BACKGROUND_WORK` returns `409 agent_busy`. To add the prompt to the running agent instead, [steer](#steering) it with `delivery: "steer"`. Otherwise, wait for the existing run to terminate, or cancel it.

This endpoint returns `400 validation_error` when the agent is a subagent that only its parent agent can drive, with the message "Follow-ups and steers to subagents are not supported. Send them to the parent agent." Send the follow-up or steer to the parent agent instead.

#### Path parameters

`id` string — Unique identifier for the agent (for example, bc-00000000-0000-0000-0000-000000000001).

#### Request body

`prompt` object (required) — The follow-up prompt, including optional images.

`prompt.text` string (required) — The follow-up instruction text.

`prompt.images` array (optional) — Image inputs for the follow-up. Each entry must include either data (base64-encoded bytes with a required mimeType) or url. Maximum 5 images, 15 MB each. Supported MIME types: image/png, image/jpeg, image/gif, image/webp.

`mcpServers` array (optional) — Inline MCP server definitions for this follow-up run. When provided, these replace any create-time inline MCP servers for this run. Omit to keep the agent's current MCP configuration.

`mode` string (optional) — Conversation mode override for this follow-up run: agent or plan. Omit to keep the conversation's current mode from prior runs.

`delivery` string (optional) — steer sends the prompt into the agent's running turn instead of starting a new run. A steer requires prompt and delivery: "steer" and accepts no other top-level fields, so sending model, mcpServers, envVars, or mode with it returns 400 validation\_error. Omit delivery for an ordinary follow-up. See Steering.

#### Steering

A steer adds a prompt to an agent while it works, instead of being refused with `409 agent_busy`. You can send one whether or not a run is active. The response is `202` with a `delivery` field:

* `steered`: The agent's running turn accepted the prompt. The response includes `runId`, the run that accepted the steer, which was running when the API got it. The prompt reaches that run at its next safe step unless the run ends first, in which case the prompt starts the agent's next run. `runId` is omitted when the agent had no active run.
* `queued`: No running turn could take the prompt, so it becomes the agent's next follow-up. That includes a steer that lands immediately after the agent's run changed. A `queued` response never includes `runId`.

A steer body with any top-level field besides `prompt` and `delivery` returns `400 validation_error` with a message that names the fields, such as `"model" is not allowed with delivery "steer"` or `"model", "mode" are not allowed with delivery "steer"`. A `delivery` other than `steer` also returns `400 validation_error`. Grok Build checks the body first, so these errors happen even when steering isn't available for your account. A steer that Grok Build refuses also returns `400 validation_error`. If steering isn't available for your account, a valid steer returns `403 feature_unavailable`.

A steer that fails with a server or network error may still have reached the agent. Grok Build treats a retry as a new prompt, so retrying can deliver the prompt twice.

```bash
curl --request POST \
  --url https://api.cursor.com/v1/agents/bc-00000000-0000-0000-0000-000000000001/runs \
  -u YOUR_API_KEY: \
  --header 'Content-Type: application/json' \
  --data '{
    "prompt": {
      "text": "Also add troubleshooting steps"
    },
    "mcpServers": [
      {
        "name": "docs",
        "type": "http",
        "url": "https://example.com/mcp"
      }
    ]
  }'
```

**Response:**

```json
{
  "run": {
    "id": "run-00000000-0000-0000-0000-000000000002",
    "agentId": "bc-00000000-0000-0000-0000-000000000001",
    "status": "CREATING",
    "createdAt": "2026-04-13T18:50:00.000Z",
    "updatedAt": "2026-04-13T18:50:00.000Z"
  }
}
```

Steer a running agent:

```bash
curl --request POST \
  --url https://api.cursor.com/v1/agents/bc-00000000-0000-0000-0000-000000000001/runs \
  -u YOUR_API_KEY: \
  --header 'Content-Type: application/json' \
  --data '{
    "prompt": {
      "text": "Also cover the error path"
    },
    "delivery": "steer"
  }'
```

**Response:** `202`

```json
{
  "delivery": "steered",
  "runId": "run-00000000-0000-0000-0000-000000000002"
}
```

If no running turn can take the prompt, the same request returns:

```json
{
  "delivery": "queued"
}
```

### List runs

List runs for an agent, newest first.

#### Path parameters

`id` string — Unique identifier for the agent.

#### Query parameters

`limit` number (optional) — Number of runs to return. Default: 20, Max: 100.

`cursor` string (optional) — Pagination cursor from nextCursor on the previous response.

```bash
curl --request GET \
  --url 'https://api.cursor.com/v1/agents/bc-00000000-0000-0000-0000-000000000001/runs?limit=20' \
  -u YOUR_API_KEY:
```

**Response:**

```json
{
  "items": [
    {
      "id": "run-00000000-0000-0000-0000-000000000002",
      "agentId": "bc-00000000-0000-0000-0000-000000000001",
      "status": "RUNNING",
      "createdAt": "2026-04-13T18:50:00.000Z",
      "updatedAt": "2026-04-13T18:51:00.000Z",
      "git": {
        "branches": [
          {
            "repoUrl": "github.com/your-org/your-repo",
            "branch": "cursor/add-readme-a1b2"
          }
        ]
      }
    }
  ]
}
```

### Get a run

Retrieve status, timestamps, and (for terminal runs) the final result, duration, and pushed branches for a specific run.

#### Path parameters

`id` string — Unique identifier for the agent.

`runId` string — Unique identifier for the run (for example, run-00000000-0000-0000-0000-000000000001).

#### Response fields

The base run fields (`id`, `agentId`, `status`, `createdAt`, `updatedAt`) are always present. `status` is `CREATING`, `RUNNING`, or `WAITING_FOR_BACKGROUND_WORK` while the run is active, and `FINISHED`, `ERROR`, `CANCELLED`, or `EXPIRED` once it ends. The following are populated as soon as data is available:

`durationMs` integer (terminal runs) — Wall-clock duration of the run in milliseconds, computed once the run reaches FINISHED, ERROR, CANCELLED, or EXPIRED.

`result` string (terminal runs) — Final assistant reply text for a terminated run. For a Project coordinator, it's the last message the coordinator sent in the run.

`git` object (when a branch has been pushed) — The agent's current pushed branches and pull requests. git.branches\[] contains \{ repoUrl, branch?, prUrl? } entries—one per branch the agent has pushed (stacked agents produce multiple).

**Per-agent state, not per-run.** Every run on the same agent returns the same `git` snapshot. Use the agent's `latestRunId` or the SSE stream to attribute work to a specific run.

`repoUrl` is returned without the scheme (for example, `github.com/your-org/your-repo`)—different from request `repos[].url`, which keeps the `https://` prefix.

```bash
curl --request GET \
  --url https://api.cursor.com/v1/agents/bc-00000000-0000-0000-0000-000000000001/runs/run-00000000-0000-0000-0000-000000000001 \
  -u YOUR_API_KEY:
```

**Response:**

```json
{
  "id": "run-00000000-0000-0000-0000-000000000001",
  "agentId": "bc-00000000-0000-0000-0000-000000000001",
  "status": "FINISHED",
  "createdAt": "2026-04-13T18:30:00.000Z",
  "updatedAt": "2026-04-13T18:45:00.000Z",
  "durationMs": 12357,
  "result": "Added README.md with installation instructions and usage examples.",
  "git": {
    "branches": [
      {
        "repoUrl": "github.com/your-org/your-repo",
        "branch": "cursor/add-readme-a1b2",
        "prUrl": "https://github.com/your-org/your-repo/pull/123"
      }
    ]
  }
}
```

### Stream a run

Stream Server-Sent Events (SSE) for one run. The stream is scoped to the requested run and does not replay prior runs.

#### Event types

* `status`: run status update. Payload: `{ runId, status }`.
* `assistant`: assistant text delta. Payload: `{ text }`.
* `thinking`: thinking text delta. Payload: `{ text }`.
* `tool_call`: tool call status update. Payload: `{ callId, name, status, args?, result?, truncated? }`.
* `interaction_update`: optional richer event emitted alongside the simplified events above. Payload matches the `InteractionUpdate` shape consumed by the [TypeScript SDK](/build/agents-window/sdk/typescript), with subtypes like `text-delta`, `tool-call-started` / `tool-call-completed`, `step-started` / `step-completed`, and `turn-ended`. If you only need plain text and tool calls, handle the simplified events and ignore `interaction_update`. If you want the full SDK-shape stream, handle `interaction_update` and ignore the simplified events.
* `heartbeat`: keepalive event. Payload: `{}`.
* `result`: terminal run status. Payload: `{ runId, status, text?, durationMs?, git? }`. `text` is the final assistant reply, `durationMs` is the wall-clock run duration in milliseconds, and `git` mirrors `Run.git` (the agent's current pushed branches, not only this run's).
* `error`: stream error. Payload: `{ code, message }`.
* `done`: stream complete. Payload: `{}`.

A [Project](#projects) coordinator replies with messages instead of plain assistant text. Each message it sends arrives as one `assistant` event with the whole message, and its working notes and `send_message` tool calls are left out. The `result` event's `text` is the last message it sent in the run.

#### Tool call payloads

`tool_call` events use a stable envelope around tool-specific inputs and outputs:

```typescript
type JsonValue =
  | string
  | number
  | boolean
  | null
  | JsonValue[]
  | { [key: string]: JsonValue };

interface ToolCallEventData {
  callId: string;
  name: string;
  status: "running" | "completed";
  args?: JsonValue;
  result?: JsonValue;
  truncated?: {
    args?: true;
    result?: true;
  };
}
```

`callId` identifies one tool invocation across updates. `name` is the public tool name, such as `read_file`, `run_terminal_cmd`, or `mcp`. `args` and `result` are tool-specific JSON values. If `args` or `result` is too large to include in the stream, Grok Build omits that field and sets the matching `truncated` flag.

#### Resuming a stream

Most events include an `id` line—an opaque string you should not parse (current format looks like `1713033006000-0`, but treat it as opaque). The leading `status` event has no `id`—it is a sticky framing event that is re-sent at the top of every reconnect.

To resume after a disconnect, reconnect with `Last-Event-ID` set to the most recent received event id. The event id must belong to the requested run; otherwise the request returns `400 invalid_last_event_id`. After a successful resume, expect another `status` event before the resumed range begins.

#### Retention

Stream responses include the `X-Cursor-Stream-Retention-Seconds` header. After the retention window elapses, this endpoint may return `410 stream_expired`. Treat that as a signal to read terminal state via [Get A Run](#get-a-run) instead of retrying the stream.

```bash
curl --request GET \
  --url https://api.cursor.com/v1/agents/bc-00000000-0000-0000-0000-000000000001/runs/run-00000000-0000-0000-0000-000000000001/stream \
  -u YOUR_API_KEY: \
  --header 'Accept: text/event-stream'
```

**Example stream:**

```text
event: status
data: {"runId":"run-00000000-0000-0000-0000-000000000001","status":"RUNNING"}

id: 1713033000000-0
event: assistant
data: {"text":"I'll update the README now."}

id: 1713033005000-0
event: tool_call
data: {"callId":"call-1","name":"read_file","status":"running","args":{"path":"README.md"}}

id: 1713033006000-0
event: tool_call
data: {"callId":"call-1","name":"read_file","status":"completed","args":{"path":"README.md"},"result":{"success":{"content":"# Project","totalLines":1,"fileSize":9,"path":"README.md"}}}

id: 1713033010000-0
event: result
data: {"runId":"run-00000000-0000-0000-0000-000000000001","status":"FINISHED","text":"Added README.md with installation instructions.","durationMs":12357,"git":{"branches":[{"repoUrl":"github.com/your-org/your-repo","branch":"cursor/add-readme-a1b2"}]}}

id: 1713033010000-0
event: done
data: {}
```

### Stream an agent

Stream Server-Sent Events (SSE) for an agent across all of its runs. Unlike [Stream A Run](#stream-a-run), the stream stays open when a run ends. It also carries runs you didn't start, such as the turns a [Project](#projects) coordinator takes when its agents report back. It closes when you disconnect or the agent is archived.

Without `Last-Event-ID`, the stream starts where the agent's newest run started, so connecting right after [Send A Follow-Up Or Steer](#send-a-follow-up-or-steer) shows that whole run. An agent with no run inside the retention window streams from the moment you connect.

> [!NOTE]
> Beta
>
> The agent stream is in beta and may change before general availability.

#### Path parameters

`id` string — Unique identifier for the agent.

#### Query parameters

`lastEventId` string (optional) — The same value as the Last-Event-ID header, for clients that can't set headers. The header wins when you send both.

#### Event types

The agent stream sends the same events as [Stream A Run](#stream-a-run), with two differences:

* `status`: status of the agent's current run. Payload: `{ agentId, status }`. A status change, including `FINISHED` at the end of a run, doesn't close the stream.
* There is no `result` event. Read a run's final state with [Get A Run](#get-a-run).

As on [Stream A Run](#stream-a-run), each message a Project coordinator sends arrives as one `assistant` event with the whole message, and its working notes and `send_message` tool calls are left out.

#### Resuming a stream

Most events include an `id` line, an opaque string you should not parse. The leading `status` event has no `id`. To resume after a disconnect, reconnect with `Last-Event-ID` set to the most recent received event id. An id this agent's stream didn't send returns `400 invalid_last_event_id`.

Grok Build closes open agent streams when it deploys, with no final event. Reconnect with `Last-Event-ID`, and the stream continues after the last event you received.

#### Ending a stream

* When the agent is archived, the stream sends `status` with `CANCELLED`, then `done`, and closes. Opening a stream for an archived agent returns `409 agent_archived`.
* When the stream fails, it sends `error` and then `done`.

#### Retention

Stream responses include the `X-Cursor-Stream-Retention-Seconds` header. A `Last-Event-ID` older than the retention window returns `410 stream_expired`. Reconnect without `Last-Event-ID` to start from the agent's newest run.

#### Limits

By default, one caller can keep 50 agent streams open at once. Opening another returns `429 too_many_open_streams`. Opening streams allows 60 requests a minute and 600 an hour.

```bash
curl --request GET \
  --url https://api.cursor.com/v1/agents/bc-00000000-0000-0000-0000-000000000001/stream \
  -u YOUR_API_KEY: \
  --header 'Accept: text/event-stream'
```

**Example stream:**

```text
event: status
data: {"agentId":"bc-00000000-0000-0000-0000-000000000001","status":"RUNNING"}

id: 1713033000000-0
event: assistant
data: {"text":"I'll update the README now."}

id: 1713033010000-0
event: status
data: {"agentId":"bc-00000000-0000-0000-0000-000000000001","status":"FINISHED"}

event: heartbeat
data: {}

id: 1713033300000-0
event: status
data: {"agentId":"bc-00000000-0000-0000-0000-000000000001","status":"RUNNING"}

id: 1713033302000-0
event: assistant
data: {"text":"Also adding a section on running the tests."}
```

### Cancel a run

Cancel the active run for an agent. Cancellation is terminal—the run transitions to `CANCELLED` and cannot be resumed. To continue the conversation, create a new run on the same agent.

> [!NOTE]
>
> Cancelling a run that is already in a terminal state, or one that was never active, returns `409 run_not_cancellable`.

#### Path parameters

`id` string — Unique identifier for the agent.

`runId` string — Unique identifier for the run to cancel.

```bash
curl --request POST \
  --url https://api.cursor.com/v1/agents/bc-00000000-0000-0000-0000-000000000001/runs/run-00000000-0000-0000-0000-000000000001/cancel \
  -u YOUR_API_KEY:
```

**Response:**

```json
{
  "id": "run-00000000-0000-0000-0000-000000000001"
}
```

### Get agent usage

Retrieve token usage for an agent, broken down per run. The response lists usage for each of the agent's runs and totals usage for the agent, including its Task subagents and side chats. Token usage matches the `tokenUsage` reported by the team [usage events](/build/agents-window/account/teams/admin-api#get-usage-events-data) endpoint.

#### Path parameters

`id` string — Unique identifier for the agent (for example, bc-00000000-0000-0000-0000-000000000001).

#### Query parameters

`runId` string (optional) — Scope the response to a single run (for example, run-00000000-0000-0000-0000-000000000001). Omit to return usage for every run on the agent. An unknown runId returns 404 run\_not\_found.

#### Response fields

`totalUsage` object — Token usage for the request. Without runId, it also counts usage from the agent's Task subagents and side chats, and usage not tied to a run, so it can be larger than the sum of runs. With runId, it covers that run, plus the Task subagent, side chat, and other usage not tied to a run from when the run started until the agent's next run started. The first run to start also gets such usage from before it started, and a run that never started gets none. The run's entry in runs includes the same usage. Contains the same fields as each run's usage object.

`runs` array — Per-run usage, one entry per run (or a single entry when runId is set). Each object contains:

* `id` *string* - Run identifier (for example, `run-00000000-0000-0000-0000-000000000001`).
* `usageUuid` *string (optional)* - Internal usage identifier for the run. Omitted when the run has no recorded usage yet.
* `usage` *object* - Token usage for this run:
  * `inputTokens` *number* - Input tokens consumed.
  * `outputTokens` *number* - Output tokens generated.
  * `cacheWriteTokens` *number* - Tokens written to cache.
  * `cacheReadTokens` *number* - Tokens read from cache.
  * `totalTokens` *number* - Sum of the four token counts above.

> [!NOTE]
>
> Runs without any recorded token usage report zeros across all fields. A run that hasn't produced usage yet still appears in `runs` so you can track it over time.

```bash
# All runs on the agent
curl --request GET \
  --url https://api.cursor.com/v1/agents/bc-00000000-0000-0000-0000-000000000001/usage \
  -u YOUR_API_KEY:

# A single run
curl --request GET \
  --url 'https://api.cursor.com/v1/agents/bc-00000000-0000-0000-0000-000000000001/usage?runId=run-00000000-0000-0000-0000-000000000001' \
  -u YOUR_API_KEY:
```

**Response:**

```json
{
  "totalUsage": {
    "inputTokens": 12480,
    "outputTokens": 3110,
    "cacheWriteTokens": 18200,
    "cacheReadTokens": 42600,
    "totalTokens": 76390
  },
  "runs": [
    {
      "id": "run-00000000-0000-0000-0000-000000000002",
      "usageUuid": "00000000-0000-0000-0000-000000000002",
      "usage": {
        "inputTokens": 6320,
        "outputTokens": 1450,
        "cacheWriteTokens": 7100,
        "cacheReadTokens": 21300,
        "totalTokens": 36170
      }
    },
    {
      "id": "run-00000000-0000-0000-0000-000000000001",
      "usageUuid": "00000000-0000-0000-0000-000000000001",
      "usage": {
        "inputTokens": 6160,
        "outputTokens": 1660,
        "cacheWriteTokens": 11100,
        "cacheReadTokens": 21300,
        "totalTokens": 40220
      }
    }
  ]
}
```

## Artifacts

Artifacts are agent-scoped because the workspace persists across runs.

### List artifacts

List artifacts produced by an agent. Each artifact's `path` is relative to the workspace's `artifacts/` directory.

> [!NOTE]
>
> Pass the `path` value returned here directly to [Download An Artifact](#download-an-artifact). v1 paths are relative; absolute v0 paths (`/opt/cursor/artifacts/...`) are not accepted.

#### Path parameters

`id` string — Unique identifier for the agent.

```bash
curl --request GET \
  --url https://api.cursor.com/v1/agents/bc-00000000-0000-0000-0000-000000000001/artifacts \
  -u YOUR_API_KEY:
```

**Response:**

```json
{
  "items": [
    {
      "path": "artifacts/screenshot.png",
      "sizeBytes": 12345,
      "updatedAt": "2026-04-13T18:45:00.000Z"
    }
  ]
}
```

### Download an artifact

Retrieve a temporary 15-minute presigned S3 URL for a specific artifact.

#### Path parameters

`id` string — Unique identifier for the agent.

#### Query parameters

`path` string — Relative artifact path returned by List Artifacts (for example, artifacts/screenshot.png). Must be under artifacts/.

```bash
curl --request GET \
  --url 'https://api.cursor.com/v1/agents/bc-00000000-0000-0000-0000-000000000001/artifacts/download?path=artifacts/screenshot.png' \
  -u YOUR_API_KEY:
```

**Response:**

```json
{
  "url": "https://cloud-agent-artifacts.s3.us-east-1.amazonaws.com/...",
  "expiresAt": "2026-04-13T19:00:00.000Z"
}
```

## Agent lifecycle

### Archive an agent

Archive an agent. Archived agents remain readable but cannot accept new runs until unarchived. Use this for reversible "soft delete" flows.

> [!NOTE]
>
> Archive is idempotent—re-archiving an already-archived agent returns `200` with no change. You don't need to check current state before calling.

#### Path parameters

`id` string — Unique identifier for the agent.

```bash
curl --request POST \
  --url https://api.cursor.com/v1/agents/bc-00000000-0000-0000-0000-000000000001/archive \
  -u YOUR_API_KEY:
```

**Response:**

```json
{
  "id": "bc-00000000-0000-0000-0000-000000000001"
}
```

### Unarchive an agent

Unarchive an agent so it can accept new runs again.

> [!NOTE]
>
> Unarchive is idempotent—calling it on an already-active agent returns `200` with no change.

#### Path parameters

`id` string — Unique identifier for the agent.

```bash
curl --request POST \
  --url https://api.cursor.com/v1/agents/bc-00000000-0000-0000-0000-000000000001/unarchive \
  -u YOUR_API_KEY:
```

**Response:**

```json
{
  "id": "bc-00000000-0000-0000-0000-000000000001"
}
```

### Delete an agent permanently

Permanently delete an agent. This action is irreversible. Use [Archive](#archive-an-agent) for reversible removal.

#### Path parameters

`id` string — Unique identifier for the agent.

```bash
curl --request DELETE \
  --url https://api.cursor.com/v1/agents/bc-00000000-0000-0000-0000-000000000001 \
  -u YOUR_API_KEY:
```

**Response:**

```json
{
  "id": "bc-00000000-0000-0000-0000-000000000001"
}
```

## Projects

[Projects](/build/agents-window/agent/projects) take on larger bodies of work: a coordinator agent plans the work and delegates it to other agents. Use these endpoints to create Projects, read the Projects you own or have joined, list the agents your coordinator started, and update or archive the Projects you own.

> [!NOTE]
> Beta
>
> The Projects endpoints are in beta and may change before general availability.

* **Use a user API key.** Projects belong to people. Creating a Project with a service account API key returns `403 user_required`, and [List Projects](#list-projects) returns no Projects for one.
* **Only the owner changes a Project.** Teammates who joined a [multiplayer Project](/build/agents-window/agent/projects#multiplayer-projects) can read it and list their own coordinator's agents. Updating, archiving, and unarchiving a Project you don't own returns `403 owner_required`.
* **A team admin can turn Projects off.** Creating a Project on that team then returns `403 projects_disabled`, and the team's Projects return `404 project_not_found`.

#### Working with a project

A Project's coordinator is an agent. Its ID is the Project's `coordinatorAgentId`, and you talk to it with the agent endpoints:

* **Read its replies** with [Stream An Agent](#stream-an-agent) on `coordinatorAgentId`. Each message the coordinator sends arrives as one `assistant` event. The stream stays open across the coordinator's runs, including the ones it starts when its agents report back. Connect right after [Create A Project](#create-a-project) to see the first run.
* **Send it a message** with [Send A Follow-Up Or Steer](#send-a-follow-up-or-steer) on `coordinatorAgentId`. While the coordinator is working, a follow-up returns `409 agent_busy`. Send `"delivery": "steer"` to hand the message to the running turn, or to queue it as the next follow-up.
* **Follow the work it delegated** with [List Project Agents](#list-project-agents), and stream any of those agents the same way.

The run endpoints carry the same replies for one run: [Stream A Run](#stream-a-run) sends each message as an `assistant` event, and a run's `result` from [Get A Run](#get-a-run) is the last message the coordinator sent in it. The agent stream is the simpler choice because one connection covers every run. In a Project you joined, `coordinatorAgentId` is your own coordinator, and the same endpoints apply.

#### Errors

Errors from these endpoints use the same body as the rest of this API, `{ "error": { "code": "...", "message": "..." } }`. Branch on `code`; the `message` wording can change. Any of these endpoints can return:

* `403 feature_unavailable` - Your account doesn't have API access.
* `403 plan_required` - Your account is on the free plan.
* `429 rate_limit_exceeded` - Too many requests. Creating a Project allows 30 a minute and 300 an hour. Getting a Project allows 300 a minute and 6,000 an hour. Listing Projects or a Project's agents allows 200 a minute and 4,000 an hour. Updating, archiving, and unarchiving allow 100 a minute and 1,000 an hour. The `Retry-After` header says when to try again.
* `500 internal_error` - Something went wrong on Grok Build's side.

Each endpoint below lists its own errors.

### Create a project

**POST /v1/projects**

Create a Project and immediately enqueue its initial run. The response returns both the durable `project` and the initial `run`, which starts the Project's coordinator agent. With a `prompt`, that run works on your prompt. To message the coordinator and read its replies, see [Working With A Project](#working-with-a-project).

#### Request body

`prompt` object (optional) — The task prompt for the coordinator, including optional images. When omitted, the coordinator opens the Project with a greeting and waits for your first message.

`prompt.text` string (required if \`prompt\` provided) — The instruction text for the coordinator.

`prompt.images` array (optional) — Image inputs for the prompt. Each entry must include either data (base64-encoded bytes with a required mimeType) or url (an http or https URL that Grok Build fetches). Maximum 5 images, 15 MB each. Supported MIME types: image/png, image/jpeg, image/gif, image/webp.

`model` object (optional) — Model selection for the coordinator. Omit this field to use the configured default. When omitted, Grok Build resolves your user default model, then your team default model, then a system default.

`model.id` string (required if \`model\` provided) — An explicit model ID returned by GET /v1/models (for example, claude-4-sonnet-thinking).

`model.params` array (optional) — Per-model parameters to apply to the run, such as reasoning effort or context window size. Each item has an id and value. Use only parameters supported by the selected model. Call GET /v1/models to discover the valid id/params combinations.

`name` string (optional) — Display name for the Project. Maximum 100 characters.

`env` object (optional) — Execution environment target, with the same fields as in Create An Agent. Use a named cloud environment, or route to a pool or machine you host. Mutually exclusive with explicit repos when selecting a named managed environment.

`repos` array (optional) — Repository configuration, with the same fields and limits as in Create An Agent. Mutually exclusive with a named cloud environment. Omit both repos and env to start a no-repo Project.

`appearance` object (optional) — The Project's icon and color. Send both fields, or leave appearance out.

* `icon` *string* - An icon name of 1 to 64 letters, numbers, or hyphens, such as `rocket`.
* `color` *string* - One of `default`, `green`, `cyan`, `blue`, `purple`, `magenta`, `orange`, `yellow`, `red`, or `brand`.

`files` array (optional) — Files to write into the Project's shared context before the coordinator's first run. The coordinator and every other agent in the Project can read them. Maximum 50 files, 256 KiB each, and 2 MiB in total. The 201 response then includes files, with each written file's path, sizeBytes, and etag. Cannot be combined with a client-supplied projectId; omit projectId so the server mints one when you send files.

* `path` *string* - Where the file goes in the store, such as `docs/brief.md`. At most 512 UTF-8 bytes, and unique within the request. Blank paths (empty or only whitespace) are refused, as are paths that start or end with `/`, have an empty, `.`, or `..` segment, or contain a backslash or control character. Grok Build reserves the top-level `inbox/` and `artifacts/` folders and any folder or file name starting with `.cursor`, so paths there are refused too.
* `content` *string* - The file's text, stored as UTF-8. Send exactly one of `content` and `contentBase64`.
* `contentBase64` *string* - The file's bytes, base64-encoded, for binary files such as images.
* `mimeType` *string (optional)* - The file's media type, such as `text/markdown`. Defaults to `text/plain; charset=utf-8` for `content` and `application/octet-stream` for `contentBase64`.

**Beta:** `files` is rolling out. If it isn't enabled for your account yet, a request with `files` returns `400 files_not_supported`.

`projectId` string (optional) — Client-supplied Project identifier in the form bc-\<uuid>. Useful for idempotent create flows; re-POSTing the same projectId returns 409 project\_id\_conflict rather than creating a duplicate. A Project's ID is also its coordinator agent's ID, so an ID that any agent already uses returns the same error. Cannot be combined with files; omit projectId so the server mints one when you send files.

Besides the shared errors, this endpoint returns `400 validation_error` for an invalid body, including any field not listed above and `files` sent with a `projectId`; `400 files_not_supported` when `files` isn't enabled for your account; `400 missing_body` for a request with no body; `403 user_required` for a service account API key; `403 projects_disabled` when your team turned Projects off; `403 storage_not_allowed` for a request with `files` when your privacy settings don't let Grok Build store data; and `409 project_id_conflict` for a `projectId` already in use. It can also return the errors [Create An Agent](#create-an-agent) returns for `prompt`, `model`, `env`, and `repos`.

```bash
curl --request POST \
  --url https://api.cursor.com/v1/projects \
  -u YOUR_API_KEY: \
  --header 'Content-Type: application/json' \
  --data '{
    "prompt": {
      "text": "Move checkout from the legacy payments client to the new one"
    },
    "name": "Payments migration",
    "model": {
      "id": "composer-2"
    },
    "repos": [
      {
        "url": "https://github.com/your-org/your-repo",
        "startingRef": "main"
      }
    ],
    "appearance": {
      "icon": "rocket",
      "color": "blue"
    }
  }'
```

**Response:**

```json
{
  "project": {
    "id": "bc-00000000-0000-0000-0000-000000000001",
    "name": "Payments migration",
    "status": "ACTIVE",
    "appearance": {
      "icon": "rocket",
      "color": "blue"
    },
    "coordinatorAgentId": "bc-00000000-0000-0000-0000-000000000001",
    "createdAt": "2026-04-13T18:30:00.000Z",
    "updatedAt": "2026-04-13T18:30:00.000Z",
    "url": "https://cursor.com/agents/bc-00000000-0000-0000-0000-000000000001"
  },
  "run": {
    "id": "run-00000000-0000-0000-0000-000000000001",
    "agentId": "bc-00000000-0000-0000-0000-000000000001",
    "status": "CREATING",
    "createdAt": "2026-04-13T18:30:00.000Z",
    "updatedAt": "2026-04-13T18:30:00.000Z"
  }
}
```

### List projects

**GET /v1/projects**

List the Projects you own or have joined, newest first.

#### Query parameters

`limit` number (optional) — Number of Projects to return. Default: 20, Max: 100.

`cursor` string (optional) — Pagination cursor from nextCursor on the previous response.

`includeArchived` boolean (optional, default: true) — Whether to include archived Projects in the response.

> [!NOTE]
>
> Projects are ordered by when your own coordinator in each one started: when you created the Project, or when you joined it. A page can hold fewer than `limit` Projects, or none, while `nextCursor` is still set. Keep paging until `nextCursor` is absent.

> [!NOTE]
>
> `nextCursor` is **omitted** from the response when there are no more pages; it is not returned as `null`. Treat its absence as "no more results".

Besides the shared errors, this endpoint returns `400 validation_error` for a `limit` outside 1 to 100, any other query parameter, or a `cursor` it didn't return.

```bash
curl --request GET \
  --url 'https://api.cursor.com/v1/projects?limit=20' \
  -u YOUR_API_KEY:
```

**Response:**

```json
{
  "items": [
    {
      "id": "bc-00000000-0000-0000-0000-000000000001",
      "name": "Payments migration",
      "status": "ACTIVE",
      "appearance": {
        "icon": "rocket",
        "color": "blue"
      },
      "coordinatorAgentId": "bc-00000000-0000-0000-0000-000000000001",
      "createdAt": "2026-04-13T18:30:00.000Z",
      "updatedAt": "2026-04-13T18:45:00.000Z",
      "url": "https://cursor.com/agents/bc-00000000-0000-0000-0000-000000000001"
    }
  ],
  "nextCursor": "g3Jt9kQpZx2LwVh7Rb0sNe4u"
}
```

### Get a project

Retrieve durable metadata for a Project. To follow its work, list your coordinator's agents with [List Project Agents](#list-project-agents).

#### Path parameters

`id` string — Unique identifier for the Project (for example, bc-00000000-0000-0000-0000-000000000001). The ID of your own coordinator in a Project you joined also works.

#### Response fields

`id` string — Unique Project identifier. It's also the ID of the owner's coordinator agent.

`name` string (optional) — Display name. Omitted when no name has been set.

`status` string — Project lifecycle status:

* `ACTIVE` - The Project is in use.
* `ARCHIVED` - The Project was archived, or its owner's coordinator was stopped.

`appearance` object (optional) — The Project's icon and color. Omitted when the Project has none.

`coordinatorAgentId` string (optional) — Your own coordinator agent in the Project: the Project's id when you own it, or the coordinator Grok Build started when you joined. Omitted when you joined the Project and your coordinator there was archived or stopped.

`url` string — URL to view the Project in the Grok Build web app.

`createdAt`, `updatedAt` string

When the Project was created and last updated, in ISO 8601 format.

Besides the shared errors, this endpoint returns `400 validation_error` when `id` isn't in the form `bc-<uuid>` and `404 project_not_found` when you can't see the Project.

```bash
curl --request GET \
  --url https://api.cursor.com/v1/projects/bc-00000000-0000-0000-0000-000000000001 \
  -u YOUR_API_KEY:
```

**Response:**

```json
{
  "id": "bc-00000000-0000-0000-0000-000000000001",
  "name": "Payments migration",
  "status": "ACTIVE",
  "appearance": {
    "icon": "rocket",
    "color": "blue"
  },
  "coordinatorAgentId": "bc-00000000-0000-0000-0000-000000000001",
  "createdAt": "2026-04-13T18:30:00.000Z",
  "updatedAt": "2026-04-13T18:45:00.000Z",
  "url": "https://cursor.com/agents/bc-00000000-0000-0000-0000-000000000001"
}
```

### List project agents

List the agents your coordinator in a Project started, newest first. Each item has the fields [Get An Agent](#get-an-agent) returns.

#### Path parameters

`id` string — Unique identifier for the Project.

#### Query parameters

`limit` number (optional) — Number of agents to return. Default: 20, Max: 100.

`cursor` string (optional) — Pagination cursor from nextCursor on the previous response.

> [!NOTE]
>
> The list covers your own coordinator's agents, up to its 1,000 newest, and leaves out agents you can't read. It's empty when you joined the Project and your coordinator there was archived or stopped.

> [!NOTE]
>
> `nextCursor` is **omitted** from the response when there are no more pages; it is not returned as `null`. Treat its absence as "no more results".

Besides the shared errors, this endpoint returns `400 validation_error` when `id` isn't in the form `bc-<uuid>`, for a `limit` outside 1 to 100, any other query parameter, or a `cursor` it didn't return, and `404 project_not_found` when you can't see the Project.

```bash
curl --request GET \
  --url 'https://api.cursor.com/v1/projects/bc-00000000-0000-0000-0000-000000000001/agents?limit=20' \
  -u YOUR_API_KEY:
```

**Response:**

```json
{
  "items": [
    {
      "id": "bc-00000000-0000-0000-0000-000000000002",
      "name": "Move refunds to the new payments client",
      "status": "ACTIVE",
      "env": {
        "type": "cloud"
      },
      "repos": [
        {
          "url": "https://github.com/your-org/your-repo",
          "startingRef": "main"
        }
      ],
      "workOnCurrentBranch": false,
      "autoCreatePR": true,
      "url": "https://cursor.com/agents/bc-00000000-0000-0000-0000-000000000002",
      "createdAt": "2026-04-13T18:40:00.000Z",
      "updatedAt": "2026-04-13T18:45:00.000Z",
      "latestRunId": "run-00000000-0000-0000-0000-000000000002"
    }
  ],
  "nextCursor": "bc-00000000-0000-0000-0000-000000000002"
}
```

### Update a project

Rename a Project, change its appearance, or both. Only the Project's owner can update it. The response is `204` with no body.

#### Path parameters

`id` string — Unique identifier for the Project.

#### Request body

`name` string (optional) — New display name. Maximum 100 characters.

`appearance` object (optional) — New icon, color, or both, with the same values as in Create A Project. Send one field to change it and keep the other. A Project without an appearance needs both.

Send at least one of `name` or `appearance`. Besides the shared errors, this endpoint returns `400 validation_error` for an invalid body, including an empty one or any field not listed above; `400 missing_body` for a request with no body; `403 owner_required` when you don't own the Project; `404 project_not_found` when you can't see it; and `409 project_archived` when it's archived.

```bash
curl --request PATCH \
  --url https://api.cursor.com/v1/projects/bc-00000000-0000-0000-0000-000000000001 \
  -u YOUR_API_KEY: \
  --header 'Content-Type: application/json' \
  --data '{
    "name": "Payments migration, phase 2",
    "appearance": {
      "color": "green"
    }
  }'
```

**Response:** `204 No Content`

### Archive a project

Archive a Project. Archived Projects remain readable but cannot be updated until unarchived. Use this for reversible "soft delete" flows. Only the Project's owner can archive it.

> [!NOTE]
>
> Archive is idempotent; re-archiving an already-archived Project returns `200` with no change. You don't need to check current state before calling.

#### Path parameters

`id` string — Unique identifier for the Project.

Besides the shared errors, this endpoint returns `400 validation_error` when `id` isn't in the form `bc-<uuid>`, `403 owner_required` when you don't own the Project, and `404 project_not_found` when you can't see it.

```bash
curl --request POST \
  --url https://api.cursor.com/v1/projects/bc-00000000-0000-0000-0000-000000000001/archive \
  -u YOUR_API_KEY:
```

**Response:**

```json
{
  "id": "bc-00000000-0000-0000-0000-000000000001"
}
```

### Unarchive a project

Unarchive a Project so it can be updated again. Only the Project's owner can unarchive it.

> [!NOTE]
>
> Unarchive is idempotent; calling it on an already-active Project returns `200` with no change.

#### Path parameters

`id` string — Unique identifier for the Project.

Besides the shared errors, this endpoint returns `400 validation_error` when `id` isn't in the form `bc-<uuid>`, `403 owner_required` when you don't own the Project, and `404 project_not_found` when you can't see it.

```bash
curl --request POST \
  --url https://api.cursor.com/v1/projects/bc-00000000-0000-0000-0000-000000000001/unarchive \
  -u YOUR_API_KEY:
```

**Response:**

```json
{
  "id": "bc-00000000-0000-0000-0000-000000000001"
}
```

## Environments

Environments are the saved [Cloud Agent environments](/build/agents-window/cloud-agent/setup) that agents run in: the repositories and `environment.json` configuration you manage in the [Cloud Agents dashboard](https://grok.com/dashboard/cloud-agents). Use these endpoints to script the same work.

### Create an environment

**POST /v1/environments**

Create a saved environment. The response is `201` with the new environment.

If the owner already has an environment with the same `name`, the request returns `409 environment_name_conflict`. The error can include the existing environment's ID in `environmentId`.

#### Request body

`owner` string (required) — personal to create an environment for the API key's user, or team to create one for the team.

`name` string (required) — Display name, up to 255 characters. It must differ from the names of the owner's other environments.

`repos` array (required) — Repositories for the environment. Each entry has a url (for example, https://github.com/your-org/your-repo). Maximum 500 repositories. Send an empty array for an environment without repositories. A repository Grok Build can't reach through your source control integration returns 400 repository\_access.

`environmentJson` string (required) — The environment's environment.json, as a JSON-encoded string. It uses the same schema as a .cursor/environment.json file. An invalid configuration returns 400 validation\_error.

#### Response fields

`id` string — Environment ID.

`name` string — Display name.

`owner` string — personal for an environment that belongs to one user, or team for an environment shared with the team.

`repos` array — Repositories in the environment. Each entry has a url.

`createdAt`, `updatedAt` string

When the environment was created and last updated (ISO 8601).

```bash
curl --request POST \
  --url https://api.cursor.com/v1/environments \
  -u YOUR_API_KEY: \
  --header 'Content-Type: application/json' \
  --data '{
    "owner": "team",
    "name": "Web app",
    "repos": [
      { "url": "https://github.com/your-org/your-web-app" },
      { "url": "https://github.com/your-org/your-api" }
    ],
    "environmentJson": "{\"install\": \"pnpm install\", \"start\": \"sudo service docker start\"}"
  }'
```

**Response:**

```json
{
  "id": "8f14e45f-ceea-4e6b-9c3a-1d2e3f4a5b6c",
  "name": "Web app",
  "owner": "team",
  "repos": [
    { "url": "https://github.com/your-org/your-web-app" },
    { "url": "https://github.com/your-org/your-api" }
  ],
  "createdAt": "2026-09-30T21:40:00.000Z",
  "updatedAt": "2026-09-30T21:40:00.000Z"
}
```

### List environments

**GET /v1/environments**

List the saved environments your API key can access, most recently updated first. Without `userId`, the list includes your personal environments and your team's environments. Team admins can list another current member's personal environments only by passing that member's `userId`.

Team admins and service account API keys see every team environment. Other callers see a team environment only when they can access all of its repositories. A service account API key limited to specific repositories, and user-scoped tokens minted with it, only list environments that have repositories, all within that limit. Drafts and deleted environments aren't included.

Filters combine, so the list keeps only environments that match every filter you send. An invalid filter value returns `400 validation_error`.

#### Query parameters

`query` string (optional) — Only environments whose name contains this text, ignoring case. 1 to 255 characters.

`owner` string (optional) — personal or team, to list only environments with that owner.

`named` boolean (optional) — true for only environments with a name, or false for only environments without one.

`repo` string (optional, repeatable) — Only environments that include this repository, such as github.com/acme/api. Repeat it, up to 100 times, to list environments that include any of the repositories.

`userId` string (optional) — Only one user's personal environments. Pass the numeric userId from API Key Info, or the user\_ ID from the Admin API's team members list. Your own ID lists your personal environments. A team admin's user API key can also pass a current team member's ID, and gets that member's personal environments that have at least one repository, all of which the admin can read. A valid ID for a user you aren't allowed to list returns items: \[] with no nextCursor, not an error. Combining userId with owner=team returns 400 validation\_error.

`limit` number (optional) — Number of environments to return. Default: 20, Max: 100.

`cursor` string (optional) — Pagination cursor from nextCursor on the previous response. Send the same filters with each cursor.

#### Response fields

`items` array — Environments, with the same fields as Get An Environment except environmentJson, versionId, and buildSettings. Call Get An Environment to load an environment's configuration and build settings.

`nextCursor` string (optional) — Pagination cursor for the next page. Omitted when there are no more pages.

> [!NOTE]
>
> A page can come back with fewer items than `limit`, or with none when `userId` names another member. Keep requesting pages until `nextCursor` is absent. It's **omitted** from the response, not returned as `null`, when there are no more pages.

Callers other than team admins and service account API keys see team environments only after Grok Build checks their access to the repositories, and those checks can run out of time. A response can then leave out team environments it hasn't verified yet, or stop before the end of the list. Those environments show up in later requests.

The list is ordered by last update, so an environment that changes during a walk moves to the front. A later page can then leave it out and repeat another environment.

```bash
curl --request GET \
  --url 'https://api.cursor.com/v1/environments?repo=github.com/your-org/your-web-app&repo=github.com/your-org/your-api' \
  -u YOUR_API_KEY:
```

**Response:**

```json
{
  "items": [
    {
      "id": "8f14e45f-ceea-4e6b-9c3a-1d2e3f4a5b6c",
      "name": "Web app",
      "owner": "team",
      "repos": [
        { "url": "https://github.com/your-org/your-web-app" },
        { "url": "https://github.com/your-org/your-api" }
      ],
      "createdAt": "2026-09-01T16:20:00.000Z",
      "updatedAt": "2026-09-29T21:05:00.000Z"
    }
  ],
  "nextCursor": "MjA"
}
```

### Get an environment

Retrieve a saved environment, its latest saved configuration, and its build settings.

#### Path parameters

`id` string — Environment ID (for example, 8f14e45f-ceea-4e6b-9c3a-1d2e3f4a5b6c).

#### Response fields

The fields [Create An Environment](#create-an-environment) returns, plus:

`repoFile` object (optional) — Set when the environment reads its configuration from a file in a repository, and points at that file: the repository url and the file path.

`environmentJson` string (optional) — The environment's latest saved configuration, its environment.json, as a JSON-encoded string.

`versionId` string (optional) — ID of the latest saved environment version. Omitted when no version has been saved.

`buildSettings` object — The environment's Build settings:

* `pullLatestCode` *string* - Whether agents that start on the default branch pull its latest code. `when_stale`, the default, pulls when the active Build is older than `stalenessThresholdHours`. `never` uses the commit the Build recorded. `always` is a legacy value you can read but not set.
* `stalenessThresholdHours` *integer or null* - Hours, from 0 to 8,760, before the active Build counts as stale. `0` pulls on every start. `null` means the default, 24.
* `installTimeoutMinutes` *integer or null* - Minutes, from 5 to 300, that a Build's install step can run. `null` means the default, 90.

```bash
curl --request GET \
  --url https://api.cursor.com/v1/environments/8f14e45f-ceea-4e6b-9c3a-1d2e3f4a5b6c \
  -u YOUR_API_KEY:
```

**Response:**

```json
{
  "id": "8f14e45f-ceea-4e6b-9c3a-1d2e3f4a5b6c",
  "name": "Web app",
  "owner": "team",
  "repos": [
    { "url": "https://github.com/your-org/your-web-app" },
    { "url": "https://github.com/your-org/your-api" }
  ],
  "environmentJson": "{\"install\": \"pnpm install\", \"start\": \"sudo service docker start\"}",
  "versionId": "c9f0f895-fb98-4b91-8f3e-2a1b0c9d8e7f",
  "buildSettings": {
    "pullLatestCode": "when_stale",
    "stalenessThresholdHours": null,
    "installTimeoutMinutes": 120
  },
  "createdAt": "2026-09-01T16:20:00.000Z",
  "updatedAt": "2026-09-29T21:05:00.000Z"
}
```

### Update an environment

Rename an environment, replace its configuration, replace its repositories, or any combination. A request applies every field it sends together, so either all of them change or none do. Change [build settings](#get-an-environment) in a request of their own. The response is `204` with no body.

Renaming an environment to a name its owner already uses returns `409 environment_name_conflict`.

#### Path parameters

`id` string — Environment ID.

#### Request body

`name` string (optional) — New display name, up to 255 characters. It must differ from the names of the owner's other environments.

`environmentJson` string (optional) — Replacement environment.json, as a JSON-encoded string. It replaces the whole configuration and uses the same schema as a .cursor/environment.json file. An invalid configuration returns 400 validation\_error. If the environment reads its configuration from a file in its only repository, the request returns 409 repo\_file\_environment\_locked.

`repos` array (optional) — The environment's full list of repositories. It replaces the current list, so include every repository to keep. Each entry has a url, and the list follows the same rules as in Create An Environment. Send environmentJson with it: a repository change saves the whole configuration, so repos without environmentJson returns 400 validation\_error. To keep the current configuration, send the environmentJson from Get An Environment. See Repository Changes for which environments can change their repositories.

`buildSettings` object (optional) — New values for any of the buildSettings fields Get An Environment returns. Fields you leave out stay unchanged, and null resets a field to its default: when\_stale, 24, or 90. Send buildSettings on its own, because a request that also sends name, environmentJson, or repos returns 400 validation\_error. Setting pullLatestCode to always returns 400 validation\_error too. To move an environment off always, send pullLatestCode: "when\_stale" with stalenessThresholdHours.

#### Repository changes

Only environments with two or more repositories can change them, and they must keep at least two. Sending the current list unchanged doesn't count as a change.

* An environment without repositories can't add any, and a single-repository environment can't change its repository. Both return `409 environment_repo_edit_blocked`. To work in different repositories, create a new environment.
* A multi-repository environment can add, remove, and swap repositories. A list with fewer than two returns `409 environment_repo_edit_blocked`.

When an environment reads its configuration from a file in a repository, [Get An Environment](#get-an-environment) returns that file in `repoFile`. Changing its repositories keeps the file as the configuration source, with these limits:

* Keep the `repoFile.url` repository in `repos`. A list without it returns `409 repo_file_repo_removed`. Grok Build compares repositories, not exact strings, so a trailing `.git` or slash, a missing `https://`, a leading `www.`, or different letter case on GitHub still match. If the list names that repository more than once in different forms, Grok Build keeps the first entry and drops the others. For Bitbucket Server, send the URL as Get An Environment returns it. A clone URL doesn't match.
* An environment whose only repository holds its configuration file is locked to that file. Any request with `repos` returns `409 repo_file_environment_locked`, even with the current list.
* When Grok Build can't read an environment's stored repositories, a request with `repos` returns `400 stored_repos_unreadable`.

```bash
curl --request PATCH \
  --url https://api.cursor.com/v1/environments/8f14e45f-ceea-4e6b-9c3a-1d2e3f4a5b6c \
  -u YOUR_API_KEY: \
  --header 'Content-Type: application/json' \
  --data '{
    "name": "Web app (staging)",
    "environmentJson": "{\"install\": \"pnpm install --frozen-lockfile\", \"start\": \"sudo service docker start\"}"
  }'
```

**Response:** `204 No Content`

Replace the repositories and keep the current configuration:

```bash
curl --request PATCH \
  --url https://api.cursor.com/v1/environments/8f14e45f-ceea-4e6b-9c3a-1d2e3f4a5b6c \
  -u YOUR_API_KEY: \
  --header 'Content-Type: application/json' \
  --data '{
    "repos": [
      { "url": "https://github.com/your-org/your-web-app" },
      { "url": "https://github.com/your-org/your-api" },
      { "url": "https://github.com/your-org/your-design-system" }
    ],
    "environmentJson": "{\"install\": \"pnpm install\", \"start\": \"sudo service docker start\"}"
  }'
```

**Response:** `204 No Content`

Change build settings:

```bash
curl --request PATCH \
  --url https://api.cursor.com/v1/environments/8f14e45f-ceea-4e6b-9c3a-1d2e3f4a5b6c \
  -u YOUR_API_KEY: \
  --header 'Content-Type: application/json' \
  --data '{
    "buildSettings": {
      "pullLatestCode": "when_stale",
      "stalenessThresholdHours": 12,
      "installTimeoutMinutes": null
    }
  }'
```

**Response:** `204 No Content`

### Delete an environment

Permanently delete a saved environment. This action is irreversible.

#### Path parameters

`id` string — Environment ID.

```bash
curl --request DELETE \
  --url https://api.cursor.com/v1/environments/8f14e45f-ceea-4e6b-9c3a-1d2e3f4a5b6c \
  -u YOUR_API_KEY:
```

**Response:**

```json
{
  "id": "8f14e45f-ceea-4e6b-9c3a-1d2e3f4a5b6c"
}
```

### List environment history

List the changes to an environment, newest first. These are the events its History tab in the [Cloud Agents dashboard](https://grok.com/dashboard/cloud-agents) shows.

#### Path parameters

`id` string — Environment ID.

#### Query parameters

`limit` number (optional) — Number of events to return. Default: 20, Max: 100.

`cursor` string (optional) — Pagination cursor from nextCursor on the previous response.

#### Response fields

`items` array — History events, newest first, with the fields below.

`nextCursor` string (optional) — Pagination cursor for the next page. Omitted when there are no more events.

#### Event fields

`id` string — Event ID.

`createdAt` string — When the change was made (ISO 8601).

`kind` string — created, updated, deleted, backfilled, or changed.

`title`, `description` string

The event's summary and details, as the History tab shows them.

`source` string (optional) — Where the change came from: dashboard, setup\_flow, restore, api, agent\_run, repo\_file, or request\_override.

`current` boolean — true for the event that saved the environment's current configuration.

`environmentJson` string (optional) — The environment.json the event saved, as a JSON-encoded string.

```bash
curl --request GET \
  --url 'https://api.cursor.com/v1/environments/8f14e45f-ceea-4e6b-9c3a-1d2e3f4a5b6c/history?limit=2' \
  -u YOUR_API_KEY:
```

**Response:**

```json
{
  "items": [
    {
      "id": "3b7e1f2a-9c4d-4e8b-a1f6-5d2c8e9b0a17",
      "createdAt": "2026-09-29T21:05:00.000Z",
      "kind": "updated",
      "title": "Team environment updated",
      "description": "Install script changed.",
      "source": "api",
      "current": true,
      "environmentJson": "{\"install\": \"pnpm install\", \"start\": \"sudo service docker start\"}"
    },
    {
      "id": "e4a9c2d1-6b3f-4a7e-9d8c-1f0b2a3c4d5e",
      "createdAt": "2026-09-01T16:20:00.000Z",
      "kind": "created",
      "title": "Team environment created",
      "description": "Team environment created.",
      "source": "dashboard",
      "current": false,
      "environmentJson": "{\"install\": \"npm install\"}"
    }
  ],
  "nextCursor": "e4a9c2d1-6b3f-4a7e-9d8c-1f0b2a3c4d5e"
}
```

### List environment builds

List an environment's [Builds](/build/agents-window/cloud-agent/builds), newest first. Filter them by status or creation time.

#### Path parameters

`id` string — Environment ID.

#### Query parameters

`status` string (optional) — Only Builds with this status: IN\_PROGRESS, SUCCEEDED, FAILED, CANCELLED, or SKIPPED.

`createdAfter` string (optional) — Only Builds created at or after this time. Use an ISO 8601 timestamp with Z or a UTC offset and at most millisecond precision, such as 2026-09-29T00:00:00Z.

`createdBefore` string (optional) — Only Builds created before this time, in the same format. It must be later than createdAfter.

`limit` number (optional) — Number of Builds to return. Default: 10, Max: 100.

`cursor` string (optional) — Pagination cursor from nextCursor on the previous response. Send the same filters with it.

#### Response fields

`items` array — Up to limit Builds, newest first. Each has the fields Get An Environment Build returns.

`nextCursor` string (optional) — Pagination cursor for the next page. Omitted when there are no more Builds.

```bash
curl --request GET \
  --url 'https://api.cursor.com/v1/environments/8f14e45f-ceea-4e6b-9c3a-1d2e3f4a5b6c/builds?createdAfter=2026-09-29T00:00:00Z&limit=2' \
  -u YOUR_API_KEY:
```

**Response:**

```json
{
  "items": [
    {
      "id": "bld-20260930-3c59dc04-8a1d-4b6e-9f2a-7e5d1c0b9a8f",
      "environmentId": "8f14e45f-ceea-4e6b-9c3a-1d2e3f4a5b6c",
      "status": "SUCCEEDED",
      "trigger": "RECURRING",
      "source": "SYSTEM",
      "draft": false,
      "requestedRefs": [],
      "repoCommits": [
        {
          "repoUrl": "https://github.com/your-org/your-web-app",
          "commitSha": "06b7d943cd0e7ea353ca932d5cdea8987b8e8105"
        },
        {
          "repoUrl": "https://github.com/your-org/your-api",
          "commitSha": "1dcf04d09d11d33343ae4758346ce1b61de676ed"
        }
      ],
      "snapshotState": "ACTIVE",
      "createdAt": "2026-09-30T09:00:00.000Z",
      "updatedAt": "2026-09-30T09:12:00.000Z",
      "completedAt": "2026-09-30T09:12:00.000Z"
    },
    {
      "id": "bld-20260929-a87ff679-a2f3-4e1c-8f5b-0c3d2e1f4a5b",
      "environmentId": "8f14e45f-ceea-4e6b-9c3a-1d2e3f4a5b6c",
      "status": "FAILED",
      "trigger": "CONFIG_CHANGE",
      "source": "SYSTEM",
      "draft": false,
      "failure": { "type": "TERMINAL_FAILURE", "code": "environment_json_invalid" },
      "requestedRefs": [],
      "repoCommits": [],
      "createdAt": "2026-09-29T21:05:00.000Z",
      "updatedAt": "2026-09-29T21:06:00.000Z",
      "completedAt": "2026-09-29T21:06:00.000Z"
    }
  ]
}
```

### Start an environment build

Start a [Build](/build/agents-window/cloud-agent/builds) of an environment, like **Trigger build** in the dashboard. The response is `202` with the new Build's `id`. Reading the Build right away can briefly return `404`.

Access follows [Update An Environment](#update-an-environment), with two differences:

* **A draft Build on a team environment needs only read access.** When a team limits environment edits to admins, members can still start drafts, but only admins can start non-draft Builds. Other members get `403 team_admin_required`. That setting doesn't limit service account API keys.
* **An API key limited to certain repositories can't start Builds**, and neither can a user-scoped token it minted. They get `404 environment_not_found` when the environment has no repositories or any repository outside the limit, and `403 key_not_supported` otherwise.

A team service account API key with no repository limit can start Builds of its own team's environments. The key needs the `agent` scope, and one without it gets `401 unauthorized`. A member's personal environment or another team's environment returns `404 environment_not_found`.

Too many requests, or too many Builds already in progress for the environment, return `429 rate_limit_exceeded`. A `503 upstream_error` means Grok Build couldn't confirm whether the Build started. Don't retry automatically, because another request can start a second Build. Check [List Environment Builds](#list-environment-builds) before deciding what to do.

#### Path parameters

`id` string — Environment ID.

#### Request body

Optional. Send no body, or `{}`, for a non-draft Build of every repository's default branch.

`draft` boolean (optional) — true for a draft Build, which agents don't start from until it's activated. Default: false, a Build that agents start from once it succeeds.

`refs` array (optional) — Branches to build instead of the default branches. Each entry has a repoUrl, one of the environment's repositories, and a ref, the branch name. Repositories without an entry build their default branch, and a ref that names the default branch counts as no entry. Any other branch requires draft: true. Without it, and for a repository that isn't in the environment or a second ref for the same repository, the request returns 400 validation\_error. Grok Build doesn't check that the branch exists, so a missing branch fails the Build, not the request.

#### Response fields

`id` string — ID of the new Build.

`environmentId` string — Environment ID.

```bash
curl --request POST \
  --url https://api.cursor.com/v1/environments/8f14e45f-ceea-4e6b-9c3a-1d2e3f4a5b6c/builds \
  -u YOUR_API_KEY:
```

**Response:** `202`

```json
{
  "id": "bld-20261020-0f2a6c1e-3b7d-4e59-9a41-8c2d7e6f5a10",
  "environmentId": "8f14e45f-ceea-4e6b-9c3a-1d2e3f4a5b6c"
}
```

Start a draft Build of a feature branch:

```bash
curl --request POST \
  --url https://api.cursor.com/v1/environments/8f14e45f-ceea-4e6b-9c3a-1d2e3f4a5b6c/builds \
  -u YOUR_API_KEY: \
  --header 'Content-Type: application/json' \
  --data '{
    "draft": true,
    "refs": [
      { "repoUrl": "https://github.com/your-org/your-web-app", "ref": "feature/new-checkout" }
    ]
  }'
```

### Get an environment build

Retrieve one of an environment's Builds. A build ID that isn't one of the environment's Builds returns `404 build_not_found`.

#### Path parameters

`id` string — Environment ID.

`buildId` string — Build ID (for example, bld-20260930-3c59dc04-8a1d-4b6e-9f2a-7e5d1c0b9a8f).

#### Response fields

`id` string — Build ID.

`environmentId` string — ID of the environment the Build belongs to.

`status` string — IN\_PROGRESS, SUCCEEDED, FAILED, CANCELLED, or SKIPPED. A skipped Build found nothing to rebuild.

`trigger` string — What started the Build: RECURRING for a scheduled Build, CONFIG\_CHANGE after a configuration or secrets change, or MANUAL for one started on request.

`source` string — Where the Build was started from: SYSTEM (Grok Build on its own), WEBSITE (the dashboard), API, or AGENT (a cloud agent).

`draft` boolean — true for a draft Build. Agents don't start from a draft Build until it's activated.

`failure` object (optional) — Why a failed Build failed. type is INSTALL\_FAILED when the install command failed, or TERMINAL\_FAILURE for other failures. code, when present, is a machine-readable cause such as environment\_json\_invalid. Other codes include:

* `bitbucket_server_not_enabled` - The environment includes a Bitbucket Server repository, which Cloud Agents can't use on this team.
* `origin_not_enabled` - The environment includes an [Origin](/build/agents-window/origin) repository, which Cloud Agents can't use on this team.
* `repo_url_invalid` - A repository URL in the environment isn't in a supported format.
* `snapshot_installation_missing` - Grok Build couldn't find the source control app installation that grants access to the environment's repository.
* `dockerfile_contents_not_enabled` - The environment sets `build.dockerfileContents`, which isn't available for your team.

Grok Build can add codes over time. Treat a code you don't recognize as a generic failure.

`requestedRefs` array — Each entry has a repository's repoUrl and the branch, tag, or commit (ref) the Build was asked to use instead of its default branch. Repositories without an entry use their default branch.

`repoCommits` array — Repository commits returned for the Build, when available. Each entry has repoUrl and commitSha. In both arrays, an API key limited to certain repositories sees only entries inside its limit.

`snapshotState` string (optional) — State of the Build's snapshot: ACTIVE, REAP\_REQUESTED, or DELETED. Omitted if the Build didn't create a snapshot.

`createdAt`, `updatedAt` string

When the Build was created and last updated (ISO 8601).

`completedAt` string (optional) — When the Build finished (ISO 8601). Omitted while it's in progress.

```bash
curl --request GET \
  --url https://api.cursor.com/v1/environments/8f14e45f-ceea-4e6b-9c3a-1d2e3f4a5b6c/builds/bld-20260930-3c59dc04-8a1d-4b6e-9f2a-7e5d1c0b9a8f \
  -u YOUR_API_KEY:
```

**Response:**

```json
{
  "id": "bld-20260930-3c59dc04-8a1d-4b6e-9f2a-7e5d1c0b9a8f",
  "environmentId": "8f14e45f-ceea-4e6b-9c3a-1d2e3f4a5b6c",
  "status": "SUCCEEDED",
  "trigger": "RECURRING",
  "source": "SYSTEM",
  "draft": false,
  "requestedRefs": [],
  "repoCommits": [
    {
      "repoUrl": "https://github.com/your-org/your-web-app",
      "commitSha": "06b7d943cd0e7ea353ca932d5cdea8987b8e8105"
    },
    {
      "repoUrl": "https://github.com/your-org/your-api",
      "commitSha": "1dcf04d09d11d33343ae4758346ce1b61de676ed"
    }
  ],
  "snapshotState": "ACTIVE",
  "createdAt": "2026-09-30T09:00:00.000Z",
  "updatedAt": "2026-09-30T09:12:00.000Z",
  "completedAt": "2026-09-30T09:12:00.000Z"
}
```

### Get the active build

Find out what an agent you start on this environment boots from: one of its Builds, or Grok Build's default image.

#### Path parameters

`id` string — Environment ID.

#### Response fields

`type` string — build when the agent starts from a Build, or universal\_image when it starts on Grok Build's default image.

`buildId` string (optional) — ID of the Build the agent starts from. Set when type is build.

```bash
curl --request GET \
  --url https://api.cursor.com/v1/environments/8f14e45f-ceea-4e6b-9c3a-1d2e3f4a5b6c/builds/active \
  -u YOUR_API_KEY:
```

**Response:**

```json
{
  "type": "build",
  "buildId": "bld-20260930-3c59dc04-8a1d-4b6e-9f2a-7e5d1c0b9a8f"
}
```

## Secrets

Secrets are the environment variables Grok Build gives cloud agents, the values you also manage in the **Secrets** tab of the [Cloud Agents dashboard](https://grok.com/dashboard/cloud-agents). The secrets endpoints cover the secrets that belong to one environment, the secrets that belong to your team, and your personal secrets. To choose a type for a secret, see [Secret protection](/build/agents-window/cloud-agent/security-network#secret-protection).

* **Responses never include values.** They list names, types, and repositories.
* **A name can have versions for different repositories.** An environment, a team, or a user can hold one name several times, each version for repositories the others don't cover. Each version is listed separately and has its own `id`.
* **Use a user API key, an agent-scoped service account API key, or a user-scoped token.** Each works within one team: a user API key in its user's default team, a user-scoped token in the team that minted it, and a service account API key in its own team. User-scoped tokens come from [Create A User-Scoped Worker Token](#create-a-user-scoped-worker-token). Team API keys and automation webhook API keys aren't supported, and API keys that start with `grok_` get `403 key_not_supported`.

#### Secret versions

Every secrets endpoint describes a version of a secret with these fields. No response includes a secret's value.

`id` string — Opaque version ID, such as secv\_3qKx9mT2bV7nR1cW5yZ8aQ. A version keeps its id through changes to its value, type, or repositories.

`name` string — The environment variable name agents see, such as NPM\_TOKEN.

`type` string — runtime\_secret for a Runtime Secret, environment\_variable for an Environment Variable, or build\_secret for a Build Secret.

`repos` array of strings — The only repositories that get this version, such as github.com/acme/api, or an empty array when every repository gets it. Repositories are listed the way Grok Build stores them: lowercase and sorted, with repository URLs reduced to host/owner/repo.

`createdAt` string — When the version was created, in ISO 8601 format.

#### Which value an agent gets

When one name is set in several places, an agent gets the value from the most specific place: values passed when the agent starts, such as `envVars` on [Create An Agent](#create-an-agent), then the environment's secrets, then the user's personal secrets, then the team's secrets. A name set at one level hides that name at every level below it.

#### Changing secrets

* **Changes reach agents that start afterward.** Running agents keep the values they started with. Agents that start from a [Build](/build/agents-window/cloud-agent/builds) get the change once a newer Build of their environment finishes.
* **Reads can lag behind writes.** Right after a change, a request can miss it. Leave a moment between writes to the same name, and pass `?id=` to pick a version.

### List secrets

**GET /v1/secrets**

List every Cloud Agents secret your API key can list in one paginated list. Each item is a [secret version](#secret-versions), with the `id` its owner's own list shows and an `owner`. No item includes a value.

Without `scope` or `environmentId`, the list includes:

* **The team's secrets**, as [List Team Secrets](#list-team-secrets) lists them, for an API key with no repository limit.
* **Your personal secrets**, for a user API key or user-scoped token with no repository limit.
* **The secrets of your team's environments** and, with a user API key or user-scoped token, of your personal environments. An API key limited to certain repositories gets only environments whose repositories all sit inside its limit.
* **Other members' secrets, for team admins.** A team admin using their own user API key without `repo` also gets the other members' personal secrets and their personal environments' secrets.

Items aren't sorted by name, and other members' secrets come after the rest. A page can hold fewer than `limit` items, or none, and still have a `nextCursor`. Keep paging until it's `null`, and send the same filters with each `cursor`.

#### Query parameters

`scope` string (optional) — team, user, members, or environment. team lists only the team's secrets, refused as List Team Secrets refuses it. user lists only your personal secrets: a key that doesn't act for a user, such as a service account API key, gets 403 user\_required, and a key limited to certain repositories gets 403 repository\_access. members lists your personal secrets and, for an explicit team admin using their own user API key or session, every other current member's personal secrets after them, but none of their personal environments' secrets. For everyone else, it returns the same response or refusal as user. environment lists only environment secrets.

`environmentId` string (optional) — List only this environment's secrets, refused as List Environment Secrets refuses it. Can't be combined with scope=team, scope=user, or scope=members; those combinations return 400 validation\_error.

`name` string (optional) — Only versions with this name, ignoring case.

`repo` string (optional) — Only the versions an agent on this repository gets, such as github.com/acme/api: versions for that repository and versions for every repository. Combining it with scope=members returns 400 validation\_error.

`limit` number (optional) — Maximum items per page, from 1 to 100. Defaults to 100.

`cursor` string (optional) — nextCursor from the previous page.

#### Response fields

`items` array — Secret versions, each with an owner. Every item has repos, including other members' versions, and \[] means every repository gets the version. On another member's version, repos can name repositories you can't access.

`items[].owner` object — Who holds the version. type is team, user, or environment. An environment owner includes environmentId. A user owner and a personal environment include user.email, which is null when the user has no email on file.

`nextCursor` string or null — Pagination cursor for the next page, or null on the last page.

```bash
curl --request GET \
  --url 'https://api.cursor.com/v1/secrets?limit=100' \
  -u YOUR_API_KEY:
```

**Response:**

```json
{
  "items": [
    {
      "id": "secv_Hn2kT8wQ5vC1xZ4mB7rP0g",
      "name": "GITHUB_PACKAGES_TOKEN",
      "type": "runtime_secret",
      "repos": [],
      "createdAt": "2026-09-28T10:12:34.000Z",
      "owner": { "type": "team" }
    },
    {
      "id": "secv_3qKx9mT2bV7nR1cW5yZ8aQ",
      "name": "NPM_TOKEN",
      "type": "runtime_secret",
      "repos": ["github.com/acme/api"],
      "createdAt": "2026-10-01T09:15:42.000Z",
      "owner": {
        "type": "environment",
        "environmentId": "8f14e45f-ceea-4e6b-9c3a-1d2e3f4a5b6c"
      }
    },
    {
      "id": "secv_Tb4mK7qW2xN9pR5vC8sJ1e",
      "name": "OPENAI_API_KEY",
      "type": "runtime_secret",
      "repos": [],
      "createdAt": "2026-10-04T13:05:27.000Z",
      "owner": { "type": "user", "user": { "email": "ada@acme.com" } }
    }
  ],
  "nextCursor": null
}
```

### List environment secrets

List an environment's Cloud Agents secrets. Each item is a [secret version](#secret-versions), and no item includes a value. Items are sorted by name, so the versions of one name sit together.

Who can list an environment's secrets:

* **A user API key or user-scoped token** can list its user's personal environments and its team's environments. Any team member can list a team environment's secrets.
* **A service account API key** can list its team's environments.
* **An API key limited to certain repositories**, or a user-scoped token it minted, can list only environments that have repositories, all inside its limit.
* **Everyone else** gets `404 environment_not_found`, including a team admin on a member's personal environment.

The list isn't paginated yet, so `nextCursor` is always `null`. Follow `nextCursor` until it's `null`, so your client keeps working when pages arrive.

#### Path parameters

`id` string — Environment ID.

#### Response fields

`items` array — The environment's secret versions. A name with versions for different repositories appears once per version.

`nextCursor` string or null — Pagination cursor for the next page. Always null for now.

```bash
curl --request GET \
  --url https://api.cursor.com/v1/environments/8f14e45f-ceea-4e6b-9c3a-1d2e3f4a5b6c/secrets \
  -u YOUR_API_KEY:
```

**Response:**

```json
{
  "items": [
    {
      "id": "secv_Qm7pW2xK9cT4vB1nY6hR3w",
      "name": "DOCKER_TOKEN",
      "type": "build_secret",
      "repos": [],
      "createdAt": "2026-09-30T14:02:11.000Z"
    },
    {
      "id": "secv_3qKx9mT2bV7nR1cW5yZ8aQ",
      "name": "NPM_TOKEN",
      "type": "runtime_secret",
      "repos": ["github.com/acme/api"],
      "createdAt": "2026-10-01T09:15:42.000Z"
    },
    {
      "id": "secv_Lw0pE4sJ6hD9fG2kU8tY1g",
      "name": "NPM_TOKEN",
      "type": "runtime_secret",
      "repos": ["github.com/acme/web"],
      "createdAt": "2026-10-02T11:20:05.000Z"
    },
    {
      "id": "secv_Zr5cN8vM1qL4wX7tA2sD9g",
      "name": "SENTRY_ENVIRONMENT",
      "type": "environment_variable",
      "repos": [],
      "createdAt": "2026-10-03T16:45:00.000Z"
    }
  ],
  "nextCursor": null
}
```

### Set an environment secret

Create an environment secret, rotate its value, or change its type or repositories. Every request sends the value, and the response is the [secret version](#secret-versions) without it.

Which version the request changes:

* **With `?id=`**, it changes the version with that `id`. An `id` that isn't a version of this name in this environment returns `404 secret_not_found`.
* **Without `?id=`**, a name with no version gets one, and the response is `201`. A name with one version has it changed in place, and the response is `200`. A name with several versions returns `409 secret_name_ambiguous`, listing each version's `id` and `repos`, so you can pass one as `?id=`.

A `PUT` never adds a second version to a name that already has one. To give a name a version for other repositories, use the dashboard.

When you omit `type` or `repos`, the version keeps its current one, so rotating a value never changes its type or widens its repositories. Send `repos: []` to give the version every repository. New `repos` that overlap another version of the name return `409 secret_scope_conflict`. An environment holds at most 1,000 secrets, and creating one more returns `409 secret_limit_reached`.

Build secrets can't be set through the API yet: `type: "build_secret"` returns `400 validation_error`, and so does a change to an existing Build Secret. `DELETE` still removes one.

Who can set an environment's secrets:

* **A user API key or user-scoped token** can set secrets on its user's personal environments and its team's environments.
* **A service account API key** can set secrets on its team's environments.
* **An API key limited to certain repositories**, or a user-scoped token it minted, can set secrets only on environments that have repositories, all inside its limit.
* **When your team lets only admins change secrets**, only team admins can set a team environment's secrets. Everyone else, service account API keys included, gets `403 team_admin_required`.
* **Everyone else** gets `404 environment_not_found`.

Each change is recorded as a [`cloud_agent_secret` event](/build/agents-window/enterprise/compliance-and-monitoring#event-types) with the secret's name and repositories but not its value, as the same change in the dashboard is.

#### Path parameters

`id` string — Environment ID.

`name` string — Secret name, as agents see it: letters, digits, and underscores, not starting with a digit, and at most 255 characters. Names that contain CURSOR\_SANDBOX are reserved, and so are HTTP\_PROXY, HTTPS\_PROXY, and ALL\_PROXY in any letter case.

Names that differ only in letter case count as the same name. Creating `npm_token` when `NPM_TOKEN` exists returns `409 secret_name_conflict`.

#### Query parameters

`id` string (optional) — The id of the version to change, from the environment's secrets list (GET /v1/environments/\{id}/secrets) or from a 409 secret\_name\_ambiguous response.

#### Request body

`value` string (required) — The secret's value, 1 to 4,096 bytes of UTF-8 text.

`type` string (optional) — runtime\_secret or environment\_variable. A new version defaults to runtime\_secret. A change without type keeps the version's type.

`repos` array of strings (optional) — The only repositories that get this version, up to 100. An empty array, or omitting repos on a new version, gives it every repository. A change without repos keeps the version's repositories.

Each entry names a repository: `acme/api`, a URL such as `https://github.com/acme/api.git` or `git@github.com:acme/api.git`, or another host's path such as `gitlab.com/group/subgroup/project`.

#### Response fields

The [secret version](#secret-versions) the request created or changed. When the new version isn't readable yet, a `201` leaves out `id` and `createdAt`.

```bash
curl --request PUT \
  --url https://api.cursor.com/v1/environments/8f14e45f-ceea-4e6b-9c3a-1d2e3f4a5b6c/secrets/NPM_TOKEN \
  -u YOUR_API_KEY: \
  --header 'Content-Type: application/json' \
  --data '{
    "value": "npm_example_token",
    "repos": ["github.com/acme/api"]
  }'
```

**Response:** `201`

```json
{
  "id": "secv_3qKx9mT2bV7nR1cW5yZ8aQ",
  "name": "NPM_TOKEN",
  "type": "runtime_secret",
  "repos": ["github.com/acme/api"],
  "createdAt": "2026-10-04T14:02:11.000Z"
}
```

Rotate the value. The response is `200` with the same `id`, `type`, `repos`, and `createdAt`:

```bash
curl --request PUT \
  --url https://api.cursor.com/v1/environments/8f14e45f-ceea-4e6b-9c3a-1d2e3f4a5b6c/secrets/NPM_TOKEN \
  -u YOUR_API_KEY: \
  --header 'Content-Type: application/json' \
  --data '{"value": "npm_rotated_token"}'
```

### Delete an environment secret

Delete one version of an environment secret. This action is irreversible. Every type can be deleted, Build Secrets included.

Which version the request deletes:

* **With `?id=`**, it deletes the version with that `id`. An `id` that isn't a version of this name in this environment returns `404 secret_not_found`.
* **Without `?id=`**, a name with one version has it deleted. A name with no version returns `404 secret_not_found`, and a name with several versions returns `409 secret_name_ambiguous`, listing each version's `id` and `repos`, and deletes nothing.

`{name}` must match a listed name exactly, letter case included, so a request for `NPM_TOKEN` never deletes `npm_token`. URL-encode characters a path can't carry.

Who can delete an environment's secrets follows the same rules as setting them: a user API key or user-scoped token on its user's personal environments and its team's environments, a service account API key on its team's environments, and an API key limited to certain repositories only on environments that have repositories, all inside its limit. Everyone else gets `404 environment_not_found`. When your team lets only admins change secrets, everyone but team admins gets `403 team_admin_required`, service account API keys included.

Each delete is recorded as a [`cloud_agent_secret` event](/build/agents-window/enterprise/compliance-and-monitoring#event-types) with the action `delete`, as a delete in the dashboard is. Agents that start afterward stop getting this version.

#### Path parameters

`id` string — Environment ID.

`name` string — Secret name, exactly as the environment's secrets list (GET /v1/environments/\{id}/secrets) shows it.

#### Query parameters

`id` string (optional) — The id of the version to delete, from the environment's secrets list or from a 409 secret\_name\_ambiguous response.

#### Response fields

`name` string — Name of the deleted secret.

```bash
curl --request DELETE \
  --url https://api.cursor.com/v1/environments/8f14e45f-ceea-4e6b-9c3a-1d2e3f4a5b6c/secrets/NPM_TOKEN \
  -u YOUR_API_KEY:
```

**Response:**

```json
{
  "name": "NPM_TOKEN"
}
```

Delete one version of a name that has several:

```bash
curl --request DELETE \
  --url 'https://api.cursor.com/v1/environments/8f14e45f-ceea-4e6b-9c3a-1d2e3f4a5b6c/secrets/NPM_TOKEN?id=secv_Lw0pE4sJ6hD9fG2kU8tY1g' \
  -u YOUR_API_KEY:
```

### List team secrets

**GET /v1/team/secrets**

List the Cloud Agents secrets of the team your API key works in. Each item is a [secret version](#secret-versions), and no item includes a value. Personal secrets, environment secrets, and other teams' secrets aren't included.

Who can list team secrets:

* **Any member of the team** can list them with a user API key or user-scoped token, even when the team lets only admins change secrets.
* **A service account API key** lists its own team.
* **An API key limited to certain repositories**, or a user-scoped token it minted, gets `403 repository_access`, because team secrets reach every repository.
* **An API key that isn't working in a team**, or a caller without a seat on the team, gets `403 team_membership_required`.

Without `limit` or `cursor`, the response holds every team secret version, sorted by name, then repositories, then creation time, so the versions of one name sit together, and `nextCursor` is `null`. Send either parameter to page through the versions in secret-version creation order. Pass each page's `nextCursor` back as `cursor` until it's `null`. Pages are read live rather than from a snapshot, so secrets created or deleted during a walk can change what later pages show.

Cursors use the same format as [List Secrets](#list-secrets), so for the same team, a cursor from `GET /v1/secrets?scope=team` continues here, and the reverse. Pass `nextCursor` back only to the same team's list. Cursors aren't tied to a team, caller, scope, or filters, so another list's cursor can silently skip versions or end the list early. A cursor from the part of a team admin's List Secrets walk that lists other members' secrets returns `400 validation_error` here.

A `limit` that isn't a whole number from 1 to 100, a repeated `limit` or `cursor`, a cursor the API didn't return, or any other query parameter returns `400 validation_error`.

#### Query parameters

`limit` number (optional) — Maximum items per page, from 1 to 100. Defaults to 100 when you send only cursor.

`cursor` string (optional) — nextCursor from the previous page.

#### Response fields

`items` array — The team's secret versions on this page. A name with versions for different repositories appears once per version.

`nextCursor` string or null — Pagination cursor for the next page, or null after the last page. Always null without limit or cursor.

```bash
curl --request GET \
  --url https://api.cursor.com/v1/team/secrets \
  -u YOUR_API_KEY:
```

**Response:**

```json
{
  "items": [
    {
      "id": "secv_Hn2kT8wQ5vC1xZ4mB7rP0g",
      "name": "GITHUB_PACKAGES_TOKEN",
      "type": "runtime_secret",
      "repos": [],
      "createdAt": "2026-09-28T10:12:34.000Z"
    },
    {
      "id": "secv_Ye6sF3jL9pV2nK5tD8uW1A",
      "name": "SENTRY_DSN",
      "type": "environment_variable",
      "repos": ["github.com/acme/web"],
      "createdAt": "2026-10-02T08:30:00.000Z"
    }
  ],
  "nextCursor": null
}
```

Page through the list, two versions at a time:

```bash
curl --request GET \
  --url 'https://api.cursor.com/v1/team/secrets?limit=2' \
  -u YOUR_API_KEY:
```

**Response:**

```json
{
  "items": [
    {
      "id": "secv_4Fq9Lm2Xc7Rt1Bn8Kd3Vh0",
      "name": "NPM_TOKEN",
      "type": "runtime_secret",
      "repos": [],
      "createdAt": "2026-09-30T17:02:11.000Z"
    },
    {
      "id": "secv_Pz6Wy1Ja5Qe9Ns3Gu7Ck2M",
      "name": "DATABASE_URL",
      "type": "environment_variable",
      "repos": ["github.com/acme/api"],
      "createdAt": "2026-10-01T09:14:52.000Z"
    }
  ],
  "nextCursor": "Tg9xR2pLbW5vcFFyc3R1dnd4eXo0NTY3ODkwYWJjZGVmZ2hp"
}
```

Then request the next page with that cursor:

```bash
curl --request GET \
  --url 'https://api.cursor.com/v1/team/secrets?limit=2&cursor=Tg9xR2pLbW5vcFFyc3R1dnd4eXo0NTY3ODkwYWJjZGVmZ2hp' \
  -u YOUR_API_KEY:
```

### Set a team secret

Create a secret for the team your API key works in, rotate its value, or change its type or repositories. Every request sends the value, and the response is the [secret version](#secret-versions) without it. Team secrets reach every agent on the team unless a more specific value hides them, as described in [Which Value An Agent Gets](#which-value-an-agent-gets).

Which version the request changes:

* **With `?id=`**, it changes the version with that `id`, from the team's secrets list (`GET /v1/team/secrets`). An `id` that isn't a version of this name in your team returns `404 secret_not_found`.
* **Without `?id=`**, a name with no version gets one, and the response is `201`. A name with one version has it changed in place, and the response is `200`. A name with several versions returns `409 secret_name_ambiguous`, listing each version's `id` and `repos`, so you can pass one as `?id=`.

A `PUT` never adds a second version to a name that already has one. To give a name a version for other repositories, use the dashboard.

When you omit `type` or `repos`, the version keeps its current one, so rotating a value never changes its type or widens its repositories. Send `repos: []` to give the version every repository. New `repos` that overlap another version of the name return `409 secret_scope_conflict`, and so does `repos: []` while the name has other versions. A team holds at most 1,000 secrets, and creating one more returns `409 secret_limit_reached`.

Build secrets can't be set through the API yet: `type: "build_secret"` returns `400 validation_error`, and so does a change to an existing Build Secret.

Who can set team secrets:

* **Any member of the team** can, with a user API key or user-scoped token, unless the team lets only admins change secrets. Then everyone but team admins gets `403 team_admin_required`, service account API keys included.
* **A service account API key** sets its own team's secrets.
* **An API key limited to certain repositories**, or a user-scoped token it minted, gets `403 repository_access`, because team secrets reach every repository.
* **An API key that isn't working in a team**, or a caller without a seat on the team, gets `403 team_membership_required`.

Each change is recorded in your team's audit log as a [`cloud_agent_secret` event](/build/agents-window/enterprise/compliance-and-monitoring#event-types) with the secret's name and repositories but not its value, as the same change in the dashboard is.

#### Path parameters

`name` string — Secret name, as agents see it: letters, digits, and underscores, not starting with a digit, and at most 255 characters. Names that contain CURSOR\_SANDBOX are reserved, and so are HTTP\_PROXY, HTTPS\_PROXY, and ALL\_PROXY in any letter case.

Names that differ only in letter case count as the same name. Creating `npm_token` when the team has `NPM_TOKEN` returns `409 secret_name_conflict`.

#### Query parameters

`id` string (optional) — The id of the version to change, from the team's secrets list or from a 409 secret\_name\_ambiguous response.

#### Request body

`value` string (required) — The secret's value, 1 to 4,096 bytes of UTF-8 text.

`type` string (optional) — runtime\_secret or environment\_variable. A new version defaults to runtime\_secret. A change without type keeps the version's type.

`repos` array of strings (optional) — The only repositories that get this version, up to 100. An empty array, or omitting repos on a new version, gives it every repository. A change without repos keeps the version's repositories.

Each entry names a repository: `acme/api`, a URL such as `https://github.com/acme/api.git` or `git@github.com:acme/api.git`, or another host's path such as `gitlab.com/group/subgroup/project`.

#### Response fields

The [secret version](#secret-versions) the request created or changed. When the new version isn't readable yet, a `201` leaves out `id` and `createdAt`.

```bash
curl --request PUT \
  --url https://api.cursor.com/v1/team/secrets/NPM_TOKEN \
  -u YOUR_API_KEY: \
  --header 'Content-Type: application/json' \
  --data '{
    "value": "npm_example_token",
    "repos": ["github.com/acme/api"]
  }'
```

**Response:** `201`

```json
{
  "id": "secv_Ub4rJ7nD2kX9qM5wL1sE8Q",
  "name": "NPM_TOKEN",
  "type": "runtime_secret",
  "repos": ["github.com/acme/api"],
  "createdAt": "2026-10-04T14:02:11.000Z"
}
```

Change one version of a name that has several, using its `id` from the team's secrets list:

```bash
curl --request PUT \
  --url 'https://api.cursor.com/v1/team/secrets/NPM_TOKEN?id=secv_Ub4rJ7nD2kX9qM5wL1sE8Q' \
  -u YOUR_API_KEY: \
  --header 'Content-Type: application/json' \
  --data '{"value": "npm_rotated_token"}'
```

### Delete a team secret

Delete one version of a secret from the team your API key works in. This action is irreversible. Every type can be deleted, Build Secrets included.

Which version the request deletes:

* **With `?id=`**, it deletes the version with that `id`, from the team's secrets list (`GET /v1/team/secrets`). An `id` that isn't a version of this name in your team returns `404 secret_not_found`.
* **Without `?id=`**, a name with one version has it deleted. A name with no version returns `404 secret_not_found`, and a name with several versions returns `409 secret_name_ambiguous`, listing each version's `id` and `repos`, and deletes nothing.

`{name}` must match a listed name exactly, letter case included, so a request for `NPM_TOKEN` never deletes `npm_token`. URL-encode characters a path can't carry.

Who can delete team secrets follows the same rules as setting them: any member of the team with a user API key or user-scoped token, and the team's service account API keys. When the team lets only admins change secrets, everyone but team admins gets `403 team_admin_required`, service account API keys included. An API key limited to certain repositories gets `403 repository_access`, and an API key that isn't working in a team, or a caller without a seat on the team, gets `403 team_membership_required`.

Each delete is recorded in your team's audit log as a [`cloud_agent_secret` event](/build/agents-window/enterprise/compliance-and-monitoring#event-types) with the action `delete`, as a delete in the dashboard is. Agents that start afterward stop getting this version.

#### Path parameters

`name` string — Secret name, exactly as the team's secrets list shows it.

#### Query parameters

`id` string (optional) — The id of the version to delete, from the team's secrets list or from a 409 secret\_name\_ambiguous response.

#### Response fields

`name` string — Name of the deleted secret.

```bash
curl --request DELETE \
  --url https://api.cursor.com/v1/team/secrets/NPM_TOKEN \
  -u YOUR_API_KEY:
```

**Response:**

```json
{
  "name": "NPM_TOKEN"
}
```

### Set a personal secret

Create a personal secret for the user your API key acts for, rotate its value, or change its type or repositories. Every request sends the value, and the response is the [secret version](#secret-versions) without it.

Which version the request changes:

* **With `?id=`**, it changes the version with that `id`, from your personal secrets list (`GET /v1/secrets?scope=user`). An `id` that isn't a version of this name among your personal secrets returns `404 secret_not_found`.
* **Without `?id=`**, a name with no version gets one, and the response is `201`. A name with one version has it changed in place, and the response is `200`. A name with several versions returns `409 secret_name_ambiguous`, listing each version's `id` and `repos`, so you can pass one as `?id=`.

A `PUT` never adds a second version to a name that already has one. To give a name a version for other repositories, use the dashboard.

When you omit `type` or `repos`, the version keeps its current one, so rotating a value never changes its type or widens its repositories. Send `repos: []` to give the version every repository. New `repos` that overlap another version of the name return `409 secret_scope_conflict`, and so does `repos: []` while the name has other versions. A user holds at most 1,000 personal secrets, and creating one more returns `409 secret_limit_reached`.

Build Secrets can't be set or changed; either returns `400 validation_error`. `DELETE` can remove one.

Who can set personal secrets:

* **A user API key or user-scoped token** sets its own user's personal secrets. Team admins can't set other members' personal secrets.
* **A service account API key** gets `403 user_required`, because it doesn't act for a user.
* **A user-scoped token minted by an API key limited to certain repositories** gets `403 repository_access`, because personal secrets reach every repository.
* **When the team your API key works in has turned off personal secrets**, setting one returns `403 personal_secrets_disabled`. [Deleting one](#delete-a-personal-secret) still works.

#### Path parameters

`name` string — Secret name, as agents see it: letters, digits, and underscores, not starting with a digit, and at most 255 characters. Names that contain CURSOR\_SANDBOX are reserved, and so are HTTP\_PROXY, HTTPS\_PROXY, and ALL\_PROXY in any letter case.

Names that differ only in letter case count as the same name. Creating `npm_token` when you have `NPM_TOKEN` returns `409 secret_name_conflict`.

#### Query parameters

`id` string (optional) — The id of the version to change, from your personal secrets list or from a 409 secret\_name\_ambiguous response.

#### Request body

`value` string (required) — The secret's value, 1 to 4,096 bytes of UTF-8 text.

`type` string (optional) — runtime\_secret or environment\_variable. A new version defaults to runtime\_secret. A change without type keeps the version's type.

`repos` array of strings (optional) — The only repositories that get this version, up to 100. An empty array, or omitting repos on a new version, gives it every repository. A change without repos keeps the version's repositories.

Each entry names a repository: `acme/api`, a URL such as `https://github.com/acme/api.git` or `git@github.com:acme/api.git`, or another host's path such as `gitlab.com/group/subgroup/project`.

#### Response fields

The [secret version](#secret-versions) the request created or changed. A `201` can leave out `id` and `createdAt`.

```bash
curl --request PUT \
  --url https://api.cursor.com/v1/me/secrets/NPM_TOKEN \
  -u YOUR_API_KEY: \
  --header 'Content-Type: application/json' \
  --data '{"value": "npm_example_token"}'
```

**Response:** `201`

```json
{
  "id": "secv_Pk6nV3yH8rT1wQ4zM9cX2b",
  "name": "NPM_TOKEN",
  "type": "runtime_secret",
  "repos": [],
  "createdAt": "2026-10-04T14:02:11.000Z"
}
```

Change one version of a name that has several, using its `id` from your personal secrets list:

```bash
curl --request PUT \
  --url 'https://api.cursor.com/v1/me/secrets/NPM_TOKEN?id=secv_Pk6nV3yH8rT1wQ4zM9cX2b' \
  -u YOUR_API_KEY: \
  --header 'Content-Type: application/json' \
  --data '{"value": "npm_rotated_token"}'
```

### Delete a personal secret

Delete one version of a personal secret of the user your API key acts for. This action is irreversible. Agents that start afterward stop getting this version.

Which version the request deletes:

* **With `?id=`**, it deletes the version with that `id`, from your personal secrets list (`GET /v1/secrets?scope=user`). An `id` that isn't a version of this name among your personal secrets returns `404 secret_not_found`.
* **Without `?id=`**, a name with one version has it deleted. A name with no version returns `404 secret_not_found`, and a name with several versions returns `409 secret_name_ambiguous`, listing each version's `id` and `repos`, and deletes nothing.

`{name}` must match a listed name exactly, letter case included, so a request for `NPM_TOKEN` never deletes `npm_token`.

Who can delete personal secrets follows the same rules as setting them: a user API key or user-scoped token deletes only its own user's personal secrets. A service account API key gets `403 user_required`, and a user-scoped token minted by an API key limited to certain repositories gets `403 repository_access`.

#### Path parameters

`name` string — Secret name, exactly as your personal secrets list shows it.

#### Query parameters

`id` string (optional) — The id of the version to delete, from your personal secrets list or from a 409 secret\_name\_ambiguous response.

#### Response fields

`name` string — Name of the deleted secret.

```bash
curl --request DELETE \
  --url https://api.cursor.com/v1/me/secrets/NPM_TOKEN \
  -u YOUR_API_KEY:
```

**Response:**

```json
{
  "name": "NPM_TOKEN"
}
```

## Automations

[Automations](/build/agents-window/cloud-agent/automations) run Cloud Agents on a schedule or when something happens in a connected tool. These endpoints read the automations your API key can see and change an automation's model. Create, edit, and delete automations in the [Automations dashboard](https://cursor.com/automations). To start a run from your own code, call the automation's [webhook](/build/agents-window/cloud-agent/automations#webhook-triggers).

* **Use a user API key or a team API key with an automations permission.** A team API key, one that starts with `grok_`, needs **View automations** (`team.automations.read`) to list and get automations, and **Manage automations** (`team.automations.manage`) to change them. Neither includes the other, and **Run Cloud Agents** (`cloud-agents:*`) doesn't reach these endpoints. A team key missing the permission an endpoint needs gets `403 permission_required`. Other team service account API keys, and API keys created for an automation's webhook, get `403 key_not_supported`.
* **A team API key works only inside its own team.** It acts as the team's service account. It sees the team's shared automations (`TEAM`, `TEAM_VISIBLE`, `TEAM_EDITABLE`, and `TEAM_EDITABLE_USER`) and never a member's private (`USER`) automations, which return `404 automation_not_found`. It can change only `TEAM` and `TEAM_EDITABLE` automations, which run as the team's service account. `TEAM_VISIBLE` and `TEAM_EDITABLE_USER` automations run as the member who created them, so changing one returns `403 role_forbidden`.
* **You see what the dashboard shows you.** You see your own automations and your team's shared automations. A team admin also sees teammates' private automations, but only with the admin's own API key, not a user-scoped token. With that key, an admin can [change the model](#change-an-automations-model) on teammates' automations, but nothing else. A user-scoped token sees only the team it was created for. An automation you can't see returns `404 automation_not_found`.
* **Cloud automations only.** Built-in automations, such as Security Reviewer, are listed with their `managedType` and can't be changed through the API. Project routines aren't listed.

#### The automation object

`id` string — Automation ID, a UUID.

`name` string — Display name.

`description` string — Description, or an empty string.

`enabled` boolean — Whether the automation's triggers start runs.

`scope` string — Who can see and edit the automation: USER for a private automation, or one of the team sharing levels TEAM, TEAM\_VISIBLE, TEAM\_EDITABLE, and TEAM\_EDITABLE\_USER.

`ownerUserId` number or null — The user who owns the automation, or null when no user owns it.

`teamId` number or null — The team the automation belongs to, or null for a personal automation.

`managedType` string — MANUAL for an automation someone created. Built-in automations have their own value: SECURITY\_REVIEWER, VULNERABILITY\_SCANNER, PR\_APPROVAL, or PROACTIVITY.

`authoringMode` string — Where the automation is edited, as in a config file's managed-by: ANY for the dashboard or a deploy, UI for the dashboard, or DEPLOY when a config-as-code deploy owns it.

`hidden` boolean — Whether the dashboard hides the automation from its list.

`modelSelection` object or null — The model the automation runs with, or null when it picks one at run time. Automations always run in Max Mode, so it has no Max Mode setting:

* `modelId` *string* - A model `id` from [List Models](#list-models).
* `parameters` *array* - The model's parameter values, each an `id` and a `value`.

`workflow` object — What the automation does: its triggers, actions, prompts, gitConfig, agentOptions, memoryEnabled, and disabledDefaultTools, plus managedEffortLevel on built-in automations, in the same JSON form that automation config files use. A field with no value is left out. Fields the server manages aren't included, and the model appears only in modelSelection.

`url` string — The automation's page in the dashboard.

`createdAt`, `updatedAt` string

When the automation was created and last changed, in ISO 8601 format.

#### Errors

Errors from these endpoints use the same body as the rest of this API, `{ "error": { "code": "...", "message": "..." } }`. Branch on `code`; the `message` wording can change. Any of the three endpoints can return:

* `403 feature_unavailable` - Your account doesn't have API access.
* `403 plan_required` - Your account is on the free plan.
* `403 permission_required` - A team API key without the permission the endpoint needs: View automations for list and get, Manage automations for changing the model.
* `403 key_not_supported` - A team service account API key that doesn't start with `grok_`, or an API key created for an automation's webhook.
* `429 rate_limit_exceeded` - Too many requests. List and get allow 60 a minute and 1,200 an hour; changing a model allows 20 a minute and 200 an hour. The `Retry-After` header says when to try again.
* `500 internal_error` - Something went wrong on Grok Build's side.

Each endpoint below lists its own errors.

### List automations

**GET /v1/automations**

List the automations your API key can see, newest first: your personal automations, or one team's.

#### Query parameters

`scope` string — personal for your personal automations, or team for one team's automations.

`teamId` number (required with \`scope=team\` for a user API key) — The team to list. You must be a member, or the request returns 403 team\_membership\_required. Sending teamId with scope=personal returns 400 validation\_error. A team API key lists its own team: it can leave teamId out, and any other team returns 403 team\_membership\_required. It can't list personal automations; scope=personal returns 403 user\_required.

`limit` number (optional) — Number of automations to return. Default: 20, Max: 100.

`cursor` string (optional) — Pagination cursor from nextCursor on the previous response. Send the same scope and teamId with each cursor.

#### Response fields

`items` array — Automation objects.

`nextCursor` string (optional) — Pass as cursor to get the next page. Omitted on the last page.

Besides the shared errors, this endpoint returns `400 validation_error` for a missing or unknown `scope`, `scope=team` without `teamId`, a `limit` outside 1 to 100, any other query parameter, or a `cursor` it didn't return for this list; `403 team_membership_required` when you aren't on `teamId`; and `503 scan_limit_exceeded` when the team has too many automations you can't see to fill a page.

```bash
curl --request GET \
  --url 'https://api.cursor.com/v1/automations?scope=team&teamId=456&limit=20' \
  -u YOUR_API_KEY:
```

**Response:**

```json
{
  "items": [
    {
      "id": "7f3c2a1b-4d5e-4f6a-8b9c-0d1e2f3a4b5c",
      "name": "Nightly dependency audit",
      "description": "Opens a PR when a dependency has a known vulnerability.",
      "enabled": true,
      "scope": "TEAM",
      "ownerUserId": 123,
      "teamId": 456,
      "managedType": "MANUAL",
      "authoringMode": "ANY",
      "hidden": false,
      "modelSelection": {
        "modelId": "claude-4.6-sonnet",
        "parameters": [{ "id": "thinking", "value": "true" }]
      },
      "workflow": {
        "triggers": [{ "cron": { "cron": "0 9 * * *" } }],
        "actions": [{ "gitPr": {} }],
        "prompts": [{ "prompt": "Audit dependencies for known vulnerabilities." }],
        "gitConfig": { "repo": "https://github.com/your-org/your-repo", "branch": "main" }
      },
      "url": "https://cursor.com/automations/7f3c2a1b-4d5e-4f6a-8b9c-0d1e2f3a4b5c",
      "createdAt": "2026-10-28T18:00:00.000Z",
      "updatedAt": "2026-10-29T09:12:00.000Z"
    }
  ],
  "nextCursor": "7f3c2a1b-4d5e-4f6a-8b9c-0d1e2f3a4b5c"
}
```

### Get an automation

Retrieve one [automation](#the-automation-object).

#### Path parameters

`id` string — Automation ID, the UUID at the end of its dashboard URL.

Besides the shared errors, this endpoint returns `400 validation_error` when `id` isn't a UUID and `404 automation_not_found` when you can't see the automation.

```bash
curl --request GET \
  --url https://api.cursor.com/v1/automations/7f3c2a1b-4d5e-4f6a-8b9c-0d1e2f3a4b5c \
  -u YOUR_API_KEY:
```

**Response:** an [automation object](#the-automation-object), as in [List Automations](#list-automations).

### Change an automation's model

Set the model an automation runs with. Nothing else about the automation changes, including its schedule. The response is the updated [automation](#the-automation-object).

Who can change an automation's model:

* **A user API key or user-scoped token** changes an automation when the dashboard would let its user edit it, such as an automation the user owns.
* **A team API key with Manage automations** changes its team's `TEAM` and `TEAM_EDITABLE` automations. On a `TEAM_VISIBLE` or `TEAM_EDITABLE_USER` automation, it gets `403 role_forbidden`.
* **Other members' automations, for team admins.** A team admin using their own user API key can also change the model on other members' automations, including private ones. The model is the only field they can change, and each change is recorded in the team's [audit log](/build/agents-window/enterprise/compliance-and-monitoring#audit-logs).
* **Everyone else** gets `403 role_forbidden`.

Built-in automations return `409 managed_automation`, and automations a config-as-code deploy owns return `409 deploy_managed`; change those in their spec instead.

#### Path parameters

`id` string — Automation ID.

#### Request body

`modelSelection` object — The model to use. The body takes no other fields.

* `modelId` *string* - A model `id` from [List Models](#list-models).
* `parameters` *array (optional)* - Parameter values, each an `id` and a `value`. To use a model variant, send the variant's `params`. Leave it out for the model's default Max Mode variant.

The selection must match a model and variant that [List Models](#list-models) returns for your key, and your team's model settings must allow it. Otherwise the request returns `400 validation_error` with the reason. Automations always run in Max Mode, so the selection is saved in Max Mode: a variant whose `isMaxMode` isn't `true`, or a model without Max Mode, returns `400 validation_error`, and so does a `maxMode` field in `modelSelection`. A model given as a single string, such as `{ "model": "composer-2-fast" }`, or any other field in the body also returns `400 validation_error`, and a request with no body returns `400 missing_body`. An automation you can't see returns `404 automation_not_found`.

```bash
curl --request PATCH \
  --url https://api.cursor.com/v1/automations/7f3c2a1b-4d5e-4f6a-8b9c-0d1e2f3a4b5c \
  -u YOUR_API_KEY: \
  -H 'Content-Type: application/json' \
  --data '{
    "modelSelection": {
      "modelId": "composer-2",
      "parameters": [{ "id": "fast", "value": "true" }]
    }
  }'
```

**Response:** the updated [automation object](#the-automation-object), with the new `modelSelection`.

## Worker tokens

### Create a user-scoped worker token

**POST /v1/sub-tokens**

Create a one-hour user-scoped token for a worker to run as an active team member.

Requires an agent-scoped team service account API key. User-scoped tokens can't mint other user-scoped tokens.

> [!NOTE]
>
> The returned token expires after 1 hour and cannot refresh itself. Mint a new token with the service account API key when you need to refresh a running worker.

#### Request body

Specify exactly one of the following to identify the target user:

`forUserEmail` string (optional) — Active team member email. Case-insensitive.

`forUserId` integer (optional) — Active team member's numeric Grok Build user ID.

By email:

```bash
curl --request POST \
  --url https://api.cursor.com/v1/sub-tokens \
  --header "Authorization: Bearer $CURSOR_SERVICE_ACCOUNT_API_KEY" \
  --header "Content-Type: application/json" \
  --data '{
    "forUserEmail": "alice@company.com"
  }'
```

By user ID:

```bash
curl --request POST \
  --url https://api.cursor.com/v1/sub-tokens \
  --header "Authorization: Bearer $CURSOR_SERVICE_ACCOUNT_API_KEY" \
  --header "Content-Type: application/json" \
  --data '{
    "forUserId": 42
  }'
```

**Response:**

```json
{
  "accessToken": "eyJ...",
  "expiresAt": "2026-04-24T19:00:00.000Z",
  "userId": 42,
  "teamId": 456
}
```

## Workers and pools

Monitor worker utilization and build autoscaling for your pools. Durable pools stay registered after the last worker disconnects, so you can scale to zero and bring capacity back when [pending requests](#list-pending-pool-requests) appear.

The endpoint paths keep the older `private-workers` name; they refer to the same [Self-Hosted Machines workers](/build/agents-window/cloud-agent/self-hosted).

Authenticate with an API key via Basic auth or Bearer token. The pool controller endpoints (pending requests, claims, and session tokens) require a team service account API key with the `agent` scope. The other endpoints also accept a user API key.

### List workers

**GET /v0/private-workers**

List pool workers for the authenticated service account's team, newest first.

#### Query parameters

`status` string (optional, default: \`all\`) — Filter by worker status. One of all, in\_use, or idle.

`scope` string (optional, default: \`all\`) — Filter by worker scope. One of all, team\_pool, or personal.

`limit` integer (optional, default: 50) — Results per page. Range: 1 to 100.

`pageToken` string (optional) — Pagination cursor. Pass the nextPageToken from the previous response.

#### Response fields

`workers` array — Connected workers. Each entry includes:

* `workerId` *string*: Unique worker identifier. Auto-generated ids are UUIDs; workers started with `CURSOR_AGENT_WORKER_ID` report that custom id instead.
* `isInUse` *boolean*: Whether the worker currently has an assigned agent.
* `repoOwner`, `repoName` *string*—Primary repository metadata when the worker registered a git remote. Empty strings for any-repo workers.
* `repoUrl` *string (optional)*: Primary repository URL. Omitted for any-repo workers.
* `workspaceRootPath` *string*: Primary workspace path on the worker.
* `connectedAtMs` *integer*: Connection time in Unix milliseconds.
* `userId` *integer*: Owning user id. `0` for workers authenticated with a service account key.
* `teamId` *integer (optional)*—Team id for team pool workers.
* `serviceAccountId` *string (optional)*: Service account that authenticated the worker.
* `activeBcId` *string (optional)*: Id of the agent currently running on the worker, when in use.
* `name` *string (optional)*: Worker display name (`--name`, defaults to the machine hostname).

`totalCount` integer — Total workers matching the filter, across all pages.

`nextPageToken` string (optional) — Pagination cursor for pageToken. Omitted when there are no more pages.

```bash
curl --request GET \
  --url "https://api.cursor.com/v0/private-workers?status=idle&scope=team_pool&limit=50" \
  -u "$CURSOR_API_KEY:"
```

**Response:**

```json
{
  "workers": [
    {
      "workerId": "a8574fe8-248e-424a-a078-7584a2b93724",
      "repoOwner": "acme",
      "repoName": "payments-service",
      "repoUrl": "https://github.com/acme/payments-service",
      "workspaceRootPath": "/home/agent/payments-service",
      "connectedAtMs": 1737306880000,
      "userId": 0,
      "teamId": 456,
      "serviceAccountId": "sa_abc123",
      "isInUse": false,
      "name": "gpu-worker-1"
    }
  ],
  "totalCount": 1
}
```

### Get worker summary

**GET /v0/private-workers/summary**

Return connected and in-use worker counts for the authenticated user and their team. Use this to trigger scaling decisions when utilization is high.

```bash
curl --request GET \
  --url "https://api.cursor.com/v0/private-workers/summary" \
  -u "$CURSOR_API_KEY:"
```

**Example scaling check:**

```typescript
const summary = await response.json();
const team = summary.teamSummary;
if (team && team.totalConnected > 0) {
  const utilization = team.inUse / team.totalConnected;
  if (utilization >= 0.9) {
    // Scale up: provision additional workers
  }
}
```

### Get worker by ID

Retrieve a single pool worker by its ID.

#### Path parameters

`id` string — Unique identifier for the worker (for example, pw\_123).

```bash
curl --request GET \
  --url "https://api.cursor.com/v0/private-workers/pw_123" \
  -u "$CURSOR_API_KEY:"
```

### List workers by ID

**GET /v0/private-workers?workerIds=**

Read up to 100 workers in one call. Pool controllers use this to check which of their workers are still connected without calling [Get Worker By ID](#get-worker-by-id) once per worker.

This endpoint accepts personal user API keys as well as team service account keys. A service account key needs the `agent` scope; one without it gets `401`.

The call answers in full or fails; it never returns part of the answer. A `503` means the lookup is temporarily unavailable. Try again later, and don't treat the requested workers as gone.

#### Query parameters

`workerIds` string (required) — Comma-separated worker IDs. A repeated workerIds key adds more IDs. Send 1 to 100 IDs, each at most 64 characters. Duplicates are collapsed, and a blank entry returns 400.

`workerIds` can't be combined with `status`, `scope`, `limit`, or `pageToken`. That returns `400`.

#### Response fields

`workers` array — Workers found, in request order. Each entry has the same fields as List Workers.

`notFoundWorkerIds` string\[] — Requested IDs with no matching worker, in request order. A worker that isn't connected and a worker your key can't see both appear here.

`observedAtMs` integer — Server time, in Unix milliseconds, taken before worker state was read.

Every distinct requested ID appears exactly once, in either `workers` or `notFoundWorkerIds`.

#### Rate limits

Each call counts once, whatever the number of IDs, against its own limit of **120 requests per minute** and **7,200 requests per hour**. Over the limit, it returns `429` with a `Retry-After` header.

```bash
curl --request GET \
  --url "https://api.cursor.com/v0/private-workers?workerIds=pw_123,pw_456" \
  -u "$CURSOR_API_KEY:"
```

**Response:**

```json
{
  "workers": [
    {
      "workerId": "pw_123",
      "repoOwner": "acme",
      "repoName": "payments-service",
      "repoUrl": "https://github.com/acme/payments-service",
      "workspaceRootPath": "/home/agent/payments-service",
      "connectedAtMs": 1737306880000,
      "userId": 0,
      "teamId": 456,
      "serviceAccountId": "sa_abc123",
      "isInUse": true,
      "activeBcId": "bc-00000000-0000-0000-0000-000000000002",
      "name": "gpu-worker-1"
    }
  ],
  "notFoundWorkerIds": ["pw_456"],
  "observedAtMs": 1737306895000
}
```

### List pools

**GET /v0/private-workers/pools**

List durable pools for the authenticated service account's team. Pools remain registered after the last worker disconnects, so you can monitor scale-to-zero fleets and decide when to provision capacity.

#### Query parameters

`scope` string (optional) — Filter by pool list scope. One of all, team\_pool, or personal.

`includeStale` boolean (optional, default: false) — When true, include pools marked stale after long inactivity.

#### Response fields

`pools` array — Registered pools. Each entry includes:

* `scope` *string*: Pool ownership scope (`user` or `team`).
* `ownerId` *integer*: Owning user or team id for the scope.
* `poolName` *string*: Pool name (for example, `default` or `gpu`).
* `connectedWorkerCount` *integer*: Workers currently connected to this pool.
* `inUseWorkerCount` *integer*: Connected workers that currently have an assigned agent. Idle capacity is `connectedWorkerCount - inUseWorkerCount`.
* `firstSeenAtMs`, `lastSeenAtMs` *integer*—First and last observation times in Unix milliseconds.
* `isStale` *boolean*: Whether the pool is marked stale after long inactivity.
* `repoOwner`, `repoName`, `repoUrl` *string (optional)*—Repository metadata when the pool is tied to a repo. Omitted for [any-repo pools](/build/agents-window/cloud-agent/self-hosted/pool#any-repo-pools).
* `workerReadyTimeoutSeconds` *integer*: Seconds a claimed request waits for this pool's offline worker to reconnect before the claim expires. `0` means follow-ups for an offline worker reacquire from the pool immediately.

```bash
curl --request GET \
  --url "https://api.cursor.com/v0/private-workers/pools?scope=team_pool&includeStale=false" \
  -u "$CURSOR_API_KEY:"
```

**Response:**

```json
{
  "pools": [
    {
      "scope": "team",
      "ownerId": 456,
      "poolName": "gpu",
      "repoOwner": "acme",
      "repoName": "payments-service",
      "repoUrl": "https://github.com/acme/payments-service",
      "connectedWorkerCount": 2,
      "inUseWorkerCount": 1,
      "firstSeenAtMs": 1737000000000,
      "lastSeenAtMs": 1737306880000,
      "isStale": false,
      "workerReadyTimeoutSeconds": 900
    },
    {
      "scope": "team",
      "ownerId": 456,
      "poolName": "sandbox",
      "connectedWorkerCount": 0,
      "inUseWorkerCount": 0,
      "firstSeenAtMs": 1737100000000,
      "lastSeenAtMs": 1737200000000,
      "isStale": false,
      "workerReadyTimeoutSeconds": 0
    }
  ]
}
```

The `sandbox` entry is any-repo: repo fields are omitted, and the pool stays selectable with zero connected workers.

### Register a pool

**POST /v0/private-workers/pools**

Register a durable pool without starting a worker. Use this to make a pool selectable before any worker connects, for example when a controller provisions capacity on demand. Starting a worker with `--pool` registers the pool implicitly; this endpoint is only needed to create the pool up front.

#### Request body

`scope` string (required) — Pool ownership scope. One of user or team.

`poolName` string (required) — Pool name to register (for example, gpu).

`repoOwner`, `repoName` string (optional)

Repository metadata when the pool is tied to a repo. Provide both together, or omit both for an any-repo pool.

`repoUrl` string (optional) — Repository URL for display. Requires repoOwner and repoName.

`workerReadyTimeoutSeconds` integer (optional, default: 0) — Seconds a claimed request waits for an offline worker from this pool to reconnect before the claim expires and the request returns to the queue. Set this when machines hibernate between turns and can be revived. With 0, follow-ups for an offline worker reacquire from the pool immediately. Must be a non-negative integer.

#### Response fields

`registered` boolean — Whether the pool was registered.

```bash
curl --request POST \
  --url "https://api.cursor.com/v0/private-workers/pools" \
  -u "$CURSOR_API_KEY:" \
  --header 'Content-Type: application/json' \
  --data '{
    "scope": "team",
    "poolName": "payments-pool",
    "repoOwner": "acme",
    "repoName": "payments-service",
    "repoUrl": "https://github.com/acme/payments-service"
  }'
```

**Response:**

```json
{
  "registered": true
}
```

### Deregister a pool

**DELETE /v0/private-workers/pools**

Deregister (soft-delete) a durable pool so it no longer appears in pool pickers or [List Pools](#list-pools). Workers currently connected to the pool are not affected. Team pools require a team admin; user pools require their owner.

#### Query parameters

`scope` string (required) — Pool ownership scope. One of user or team.

`pool_name` string (required) — Pool name to deregister.

`repo_owner` string (optional) — Repository owner when deregistering a repo-scoped pool record.

`repo_name` string (optional) — Repository name when deregistering a repo-scoped pool record. Provide repo\_owner and repo\_name together, or omit both for an any-repo pool.

```bash
curl --request DELETE \
  --url "https://api.cursor.com/v0/private-workers/pools?scope=team&pool_name=sandbox" \
  -u "$CURSOR_API_KEY:"
```

**Response:**

```json
{
  "deregistered": true
}
```

### List pending pool requests

**GET /v0/private-workers/pending-requests**

List pool requests that have not been assigned to a worker yet. Use this endpoint to scale capacity when users are waiting for an available pool worker, or pair it with [Claim A Pending Request](#claim-a-pending-request) before starting an ephemeral worker.

For pools configured with `workerReadyTimeoutSeconds`, the listing also surfaces claimed-but-offline entries: requests whose claimed worker is offline while a reconnect window is open. These entries carry `claimedWorkerId` and `wakeTimeoutMs` so a controller can [revive the machine](/build/agents-window/cloud-agent/self-hosted/pool#hibernation).

This endpoint requires a service account API key. It returns requests for the key's team and excludes My Machines requests. If the key is scoped to specific repositories, pass `repository`; the repository must be in the key's allowed scope.

The response includes a `streamCursor`. Pass it to [Watch Pending Pool Requests](#watch-pending-pool-requests) to follow queue changes in real time after this snapshot.

#### Query parameters

`limit` number (optional) — Number of pending requests to return. Default: 50, Max: 100.

`pageToken` string (optional) — Pagination cursor from the previous response. Page tokens are bound to the repository and pool filters that issued them.

`repository` string (optional) — Filter by repository URL. Required for repo-scoped service account API keys. Omit for any-repo pending requests.

`pool` string (optional) — Filter by pool name. Exact, case-sensitive match against the request's pool label. Omit to list requests for every pool on the team.

#### Response fields

`requests` array — Pending requests. Each entry includes:

* `id` *string*: Pending request / agent id (pass to [Claim](#claim-a-pending-request) or [Release A Claim](#release-a-claim) as `id`).
* `userId` *integer*: Grok Build user id that created the request.
* `userEmail` *string (optional)*: Email of the requesting user, when available. Use it to select user-affine capacity without another lookup.
* `serviceAccountId` *string (optional)*: Service account associated with the request, when present.
* `repoOwner`, `repoName`, `repoUrl` *string (optional)*—Repository metadata when the request targets a repo. Omitted for any-repo pool requests.
* `labels` *array*: Request labels as `{ key, value }` pairs (includes `repo=` and `pool=` when set).
* `createdAtMs` *integer*: Request creation time in Unix milliseconds.
* `claimedWorkerId` *string (optional)*: Present on claimed-but-offline entries: the request is claimed by this worker, which is currently offline. Start a worker with this id (`CURSOR_AGENT_WORKER_ID`) to resume the agent on its machine.
* `wakeTimeoutMs` *integer (optional)*—Milliseconds left in the reconnect window of a claimed-but-offline entry. When the window lapses, the claim expires and the request is re-advertised as an unclaimed entry.

`nextPageToken` string (optional) — Pagination cursor. Omitted when there are no more pages. To measure queue depth, paginate to completion and count the requests.

`streamCursor` string — Opaque resume position for Watch Pending Pool Requests. Every page of one logical listing repeats the same streamCursor; open the watch from it after you finish paginating. It expires five minutes after the list that issued it.

```bash
curl --request GET \
  --url "https://api.cursor.com/v0/private-workers/pending-requests?limit=50&repository=https%3A%2F%2Fgithub.com%2Facme%2Fpayments-service" \
  -u "$CURSOR_API_KEY:"
```

**Response:**

```json
{
  "requests": [
    {
      "id": "bc-00000000-0000-0000-0000-000000000002",
      "userId": 321,
      "userEmail": "owner@acme.example",
      "serviceAccountId": "sa_abc123",
      "repoOwner": "acme",
      "repoName": "payments-service",
      "repoUrl": "https://github.com/acme/payments-service",
      "labels": [
        { "key": "repo", "value": "acme/payments-service" },
        { "key": "pool", "value": "gpu" },
        { "key": "env", "value": "production" }
      ],
      "createdAtMs": 1737306880000
    }
  ],
  "nextPageToken": "eyJjcmVhdGVkQXRNcyI6MTczNzMwNjg4MDAwMH0=",
  "streamCursor": "djQuZXhhbXBsZS1vcGFxdWUtY3Vyc29y"
}
```

`repoUrl` omits embedded credentials when the original repository URL includes userinfo.

### Watch pending pool requests

**GET /v0/private-workers/pending-requests/stream**

Stream pending-request lifecycle events over Server-Sent Events (SSE) so controllers can react to queue changes without polling.

This endpoint requires a service account API key. Controllers list-then-watch: call [List Pending Pool Requests](#list-pending-pool-requests) to build your view of the queue, keep the response's `streamCursor`, then open the watch from that exact position. Use the same `repository` and `pool` filters for the list and the watch; cursors are bound to the filters that issued them.

#### Query parameters

`cursor` string (required) — The streamCursor from a list response, or the SSE id: of the last event you processed. On reconnect, a native EventSource resends that id as the Last-Event-ID header, which takes precedence over the query parameter.

`repository` string (optional) — Same semantics as List Pending Pool Requests. Required for repo-scoped service account API keys. Pagination parameters are not accepted on the stream.

`pool` string (optional) — Watch only events for this pool. Exact, case-sensitive match against the request's pool label. Must match the filter used by the list that issued the cursor. Omit to watch every pool on the team.

#### Events

The watch replays the retained transitions after the cursor, then follows live. Every event's SSE `id:` is the cursor to resume from if the connection drops.

* `created` *event*: A request entered the queue, including a claimed-but-offline request whose reconnect window lapsed and whose claim expired. Payload: the same request object as [List Pending Pool Requests](#list-pending-pool-requests).
* `claimed` *event*: A worker claimed the request, or an offline worker reconnected and resumed its claimed request. Payload: `{ id }`.
* `claimed_offline` *event*: A follow-up arrived for a request whose claimed worker is offline. Payload: the same request object as [List Pending Pool Requests](#list-pending-pool-requests), including `claimedWorkerId` and `wakeTimeoutMs`. [Revive the machine](/build/agents-window/cloud-agent/self-hosted/pool#hibernation) before the window lapses, or the claim expires and the request is re-advertised with a fresh `created` event.
* `expired` *event*: The request left the queue without being claimed. Payload: `{ id }`.
* `heartbeat` *event*: Grok Build checkpoint with no state change, sent about every 20 seconds on a quiet stream. Payload: `{}`. Heartbeats advance an idle watch's resume position but do not extend the cursor's lifetime.

#### Grok Build lifetime

Every cursor in a watch chain expires **five minutes after the list that issued it**. Heartbeats and reconnects do not extend it. When the cursor expires, or the retained event window no longer covers it, the endpoint returns HTTP `410 Gone` with `{"code": "cursor_expired"}`: re-list and watch from the fresh `streamCursor`. This is routine, not an error path. Re-list proactively on a five-minute timer with jitter instead of riding the `410`, so a fleet of controllers does not synchronize its list calls.

#### Delivery guarantees

Delivery is best-effort, and the list is the source of truth. Events are published after each transition commits, with retries, but a rare failure can drop one, and a dropped event is never redelivered. Between re-lists, treat events as low-latency hints: apply them idempotently (upsert `created` and `claimed_offline` requests, remove `claimed` and `expired` requests by `id`) and let the next list correct any drift. A `claimed` event for a request you never saw is a no-op. Claims stay atomic server-side regardless of your local view.

Do not persist cursors. A service account can hold at most four concurrent streams; use one stream per controller and fan out locally.

```bash
curl --request GET --no-buffer \
  --url "https://api.cursor.com/v0/private-workers/pending-requests/stream?cursor=$STREAM_CURSOR" \
  --header 'Accept: text/event-stream' \
  -u "$CURSOR_API_KEY:"
```

**Example stream:**

```text
: connected

event: heartbeat
id: djQuY3Vyc29yLWNoZWNrcG9pbnQ
data: {}

event: created
id: djQuY3Vyc29yLWFmdGVyLWNyZWF0ZWQ
data: {"id":"bc-00000000-0000-0000-0000-000000000002","userId":321,"userEmail":"owner@acme.example","repoOwner":"acme","repoName":"payments-service","repoUrl":"https://github.com/acme/payments-service","labels":[{"key":"pool","value":"gpu"}],"createdAtMs":1737306880000}

event: claimed
id: djQuY3Vyc29yLWFmdGVyLWNsYWltZWQ
data: {"id":"bc-00000000-0000-0000-0000-000000000002"}
```

**The controller loop:**

1. [List pending requests](#list-pending-pool-requests) to completion and replace your local view with the result. Keep the response's `streamCursor`.
2. Open the watch with `?cursor=<streamCursor>` and apply events to your local view. Track the latest event `id:` you processed.
3. On disconnect, reconnect with the latest event id as `?cursor=`, or rely on a native `EventSource`, which resends it as `Last-Event-ID` automatically.
4. On HTTP `410 Gone`, go back to step 1 and re-list.

### Claim a pending request

**POST /v0/private-workers/claim**

Reserve a pending pool request for a specific worker before that worker starts. Controllers use this to atomically assign work across replicas: read [pending requests](#list-pending-pool-requests), claim one, then start a worker with a stable worker id that matches the claim.

A second claim while a live claim exists is rejected. [Release A Claim](#release-a-claim) first, then claim a new `workerId`.

This endpoint requires a service account API key.

#### Request body

`id` string (required) — Pending request id. Same value as id from List Pending Pool Requests.

`workerId` string (required) — Worker id to reserve for the request. Start the worker with the same id via CURSOR\_AGENT\_WORKER\_ID (or the hidden --worker-id flag) so the bridge registers the claimed identity.

`sessionToken` boolean (optional, default: \`false\`) — Also mint a session token for this claim, so the worker can start without the service account key. If the token can't be minted, the claim fails and the request stays unclaimed.

`identityToken` object (optional) — Also return a claim token: a signed OIDC JWT that names the claimed agent, its owner, and workerId. If the token can't be issued, the claim fails and the request stays unclaimed.

`identityToken.audience` string (required if \`identityToken\` provided) — Audience your verifier checks, set as the JWT aud claim. Printable ASCII, up to 512 characters. Grok Build doesn't allowlist audiences.

`identityToken.nonce` string (optional) — Value echoed into the JWT nonce claim. Printable ASCII, up to 512 characters. Send a fresh value with each claim.

#### Response fields

`id`, `workerId` string

The claimed request and worker id.

`token` string (optional) — Session token that serves only this claim. Present when the request sent sessionToken: true. It stops working when the claim is released, or when the API key that minted it is deleted or expires.

`expiresAt` string (optional) — ISO 8601 timestamp, 7 days after minting. Present with token.

`identityToken.token` string (optional) — Signed claim token. Present when the request sent identityToken. Verify it before you act on it.

`identityToken.expiresAt` string (optional) — ISO 8601 timestamp, 5 minutes after minting. Matches the JWT exp claim.

```bash
curl --request POST \
  --url "https://api.cursor.com/v0/private-workers/claim" \
  -u "$CURSOR_API_KEY:" \
  --header 'Content-Type: application/json' \
  --data '{
    "id": "bc-00000000-0000-0000-0000-000000000002",
    "workerId": "pw_123"
  }'
```

**Response:**

```json
{
  "id": "bc-00000000-0000-0000-0000-000000000002",
  "workerId": "pw_123"
}
```

After a successful claim, start the worker with the reserved id:

```bash
export CURSOR_API_KEY="your-service-account-api-key"
export CURSOR_AGENT_WORKER_ID="pw_123"
cursor-agent worker --pool gpu --worker-dir /workspace start
```

If the worker can't start, [Fail A Claim](#fail-a-claim) so the agent's turn ends with your reason instead of waiting.

With a session token:

```bash
curl --request POST \
  --url "https://api.cursor.com/v0/private-workers/claim" \
  -u "$CURSOR_API_KEY:" \
  --header 'Content-Type: application/json' \
  --data '{
    "id": "bc-00000000-0000-0000-0000-000000000002",
    "workerId": "pw_123",
    "sessionToken": true
  }'
```

**Response:**

```json
{
  "id": "bc-00000000-0000-0000-0000-000000000002",
  "workerId": "pw_123",
  "token": "eyJ...",
  "expiresAt": "2026-10-02T21:00:00.000Z"
}
```

Start the worker with the token instead of the key:

```bash
printf '%s' "$TOKEN" > /run/cursor/token
export CURSOR_AGENT_WORKER_ID="pw_123"
cursor-agent worker --pool gpu --worker-dir /workspace --auth-token-file /run/cursor/token start
```

With a claim token:

```bash
curl --request POST \
  --url "https://api.cursor.com/v0/private-workers/claim" \
  -u "$CURSOR_API_KEY:" \
  --header 'Content-Type: application/json' \
  --data '{
    "id": "bc-00000000-0000-0000-0000-000000000002",
    "workerId": "pw_123",
    "identityToken": {
      "audience": "https://provisioner.example.com",
      "nonce": "3f9c1e7a-claim-pw_123"
    }
  }'
```

**Response:**

```json
{
  "id": "bc-00000000-0000-0000-0000-000000000002",
  "workerId": "pw_123",
  "identityToken": {
    "token": "eyJ...",
    "expiresAt": "2026-10-02T21:05:00.000Z"
  }
}
```

When the request sends `identityToken` and Grok Build can't issue the token, nothing is claimed. HTTP `403` means this agent isn't allowed to mint tokens; don't retry. HTTP `429` means the agent is over its budget of 30 claim tokens per minute; retry after the `Retry-After` header. HTTP `503` means token signing is unavailable; retry with backoff.

HTTP `409` returns no token, and nothing is signed. Grok Build returns it when another agent holds `workerId`, or when an earlier try of this claim committed but its response never arrived. After a lost response, [release the claim](#release-a-claim), then claim again.

### Create a session token

**POST /v0/private-workers/tokens**

Mint a [session token](/build/agents-window/cloud-agent/self-hosted/pool#session-tokens) for a claim your team already holds. Use it when a worker reconnects to an existing claim, such as a revived hibernated machine, or when a run outlasts its token. `cursor-agent worker controller --session-token` calls this for you when it wakes a hibernated machine.

The token serves only this claim. It stops working when the claim is released, or when the API key that minted it is deleted or expires.

This endpoint requires an agent-scoped service account API key from the team that holds the claim. A repository-scoped key can mint tokens only for agents on repositories in its scope.

#### Request body

`id` string (required) — Agent id the claim is for. Same value as id on Claim A Pending Request.

`workerId` string (required) — Worker id the claim binds to the agent.

```bash
curl --request POST \
  --url "https://api.cursor.com/v0/private-workers/tokens" \
  -u "$CURSOR_API_KEY:" \
  --header 'Content-Type: application/json' \
  --data '{
    "id": "bc-00000000-0000-0000-0000-000000000002",
    "workerId": "pw_123"
  }'
```

**Response:**

```json
{
  "id": "bc-00000000-0000-0000-0000-000000000002",
  "workerId": "pw_123",
  "token": "eyJ...",
  "expiresAt": "2026-10-02T21:00:00.000Z"
}
```

HTTP `404` means your team holds no claim binding that worker to that agent.

### Release a claim

Release the claim that binds an agent to its self-hosted worker so the worker can serve another agent.

When no turn is using the worker, release frees it immediately. Grok Build clears the claim and the agent's worker assignment together, returns a waiting follow-up to the pool queue as an unclaimed request, and tells the worker CLI to exit. The agent's next turn runs on another worker. A replacement worker can claim the agent as soon as release returns.

While a turn is using the worker, release returns HTTP `400` and changes nothing. A turn is using the worker when the agent's [status](#get-an-agent) is `ACTIVE`, the worker is connected, and the claim isn't waiting for a [hibernated](/build/agents-window/cloud-agent/self-hosted/pool#hibernation) machine to wake. If Grok Build can't read the worker's connection state, it counts the worker as connected. Retry after the turn ends, or [cancel the active run](#cancel-a-run) and release again.

A second [Claim A Pending Request](#claim-a-pending-request) while a live claim exists is rejected. Release first, then claim a new `workerId`.

`--idle-release-timeout` (env var `CURSOR_WORKER_IDLE_RELEASE_TIMEOUT`) makes the worker CLI exit on its own after idle.

This endpoint requires a service account API key.

#### Path parameters

`id` string — Pending request / agent id. Same value as id on Claim A Pending Request. No request body.

```bash
curl --request POST \
  --url "https://api.cursor.com/v0/private-workers/claims/bc-00000000-0000-0000-0000-000000000002/release" \
  -u "$CURSOR_API_KEY:"
```

**Response:**

```json
{
  "id": "bc-00000000-0000-0000-0000-000000000002",
  "workerId": "pw_123"
}
```

HTTP `400` means a turn is using the worker. Nothing changed. Retry after the turn ends:

```json
{
  "error": "Worker in use: The agent is mid-turn on this worker; retry after the turn ends, or stop the agent to free the worker now"
}
```

HTTP `404` means there is no live claim: already released, expired, or adopted. Do not retry a 404.

### Fail a claim

Report that you can't start the worker you claimed for an agent, for example because your infrastructure is out of quota or is missing a permission. Instead of waiting for a worker that won't connect, the agent's turn ends with your reason as its error the next time it checks for the worker.

The person who started the agent sees `Your team's self-hosted pool couldn't start a worker for this agent:` followed by your message. When the agent runs from Slack, Grok Build posts the same text in the thread with a **Try Again** button.

Once the turn has ended, Grok Build frees the claim. The agent's next turn, including a Try Again, returns to the pool queue as an unclaimed request that any worker can [claim](#claim-a-pending-request).

You can fail a claim only while a turn is waiting on it: the agent's [status](#get-an-agent) is `ACTIVE` and the claimed worker isn't connected. Otherwise the endpoint returns HTTP `400` and changes nothing. If Grok Build can't read the worker's connection state, it counts the worker as connected. To free a claim when no turn is waiting, use [Release A Claim](#release-a-claim).

If the claimed worker connects, or the claim ends, before the turn picks up your report, Grok Build discards the report.

This endpoint requires an agent-scoped service account API key from the team that holds the claim. A repository-scoped key can fail claims only for agents on repositories in its scope.

#### Path parameters

`id` string — Agent id the claim is for. Same value as id on Claim A Pending Request.

#### Request body

`message` string (required) — Plain-text reason shown to the agent's user. Grok Build removes control characters other than newlines and tabs and trims surrounding whitespace. The result must be 1 to 500 characters. Other body fields are rejected.

#### Response fields

`id`, `workerId` string

The agent and the worker the failed claim was bound to.

```bash
curl --request POST \
  --url "https://api.cursor.com/v0/private-workers/claims/bc-00000000-0000-0000-0000-000000000002/fail" \
  -u "$CURSOR_API_KEY:" \
  --header 'Content-Type: application/json' \
  --data '{
    "message": "The gpu pool has reached its limit of 20 machines. Try again in a few minutes."
  }'
```

**Response:**

```json
{
  "id": "bc-00000000-0000-0000-0000-000000000002",
  "workerId": "pw_123"
}
```

HTTP `400` with `No turn waiting` means the agent isn't `ACTIVE`. Nothing changed. Release the claim instead:

```json
{
  "error": "No turn waiting: The agent is not running, so no turn is waiting on this claim; release the claim instead"
}
```

HTTP `400` with `Worker connected` means the claimed worker is connected and serving the turn. Nothing changed:

```json
{
  "error": "Worker connected: The claimed worker is connected and serving the agent; stop the agent or release the claim after the turn ends"
}
```

HTTP `400` with neither title means the body is invalid: `message` is missing, not a string, empty, or longer than 500 characters, or the body has other fields.

HTTP `404` means the agent isn't a self-hosted agent on your team, or it holds no claim. Do not retry a 400 or 404. Retry a 5xx; reporting the same claim again is safe.

## Metadata endpoints

### API key info

**GET /v1/me**

Retrieve information about the API key being used for authentication.

#### Response fields

`apiKeyName` string — Display name of the API key.

`createdAt` string — When the API key was created (ISO 8601).

`userId` integer (user-scoped keys) — Numeric Grok Build user ID of the API key's owner. Omitted for service-account / team API keys, which aren't tied to a specific user.

`userEmail` string (user-scoped keys) — Email address of the API key's owner.

`userFirstName`, `userLastName` string (user-scoped keys)

First and last name of the API key's owner, when populated.

```bash
curl --request GET \
  --url https://api.cursor.com/v1/me \
  -u YOUR_API_KEY:
```

**Response (user-scoped key):**

```json
{
  "apiKeyName": "Production API Key",
  "userId": 42,
  "createdAt": "2026-04-13T18:30:00.000Z",
  "userEmail": "developer@example.com",
  "userFirstName": "Alex",
  "userLastName": "Rivera"
}
```

**Response (service-account key):**

```json
{
  "apiKeyName": "Production Service Account",
  "createdAt": "2026-04-13T18:30:00.000Z"
}
```

### List models

**GET /v1/models**

Returns the recommended models you can pass to the `model.id` field on [Create An Agent](#create-an-agent), along with the parameters and variants each model accepts. Model parameters use the same `model.params` shape as the [TypeScript SDK ModelSelection](/build/agents-window/sdk/typescript#modelselection).

> [!NOTE]
>
> To use the configured default model, omit `model` from the request body entirely. Grok Build resolves your user default model, then your team default model, then a system default.

#### Response fields

Each item in `items` describes one model:

`id` string — Pass this value as model.id when creating an agent.

`displayName` string — Human-readable name shown in the Grok Build UI.

`description` string (optional) — Short description of the model.

`aliases` array (optional) — Alternate IDs that resolve to the same model (for example, composer-latest).

`parameters` array (optional) — Per-model parameter definitions. Each entry has an id, optional displayName, and a values array of permitted \{ value, displayName? } entries. Use these to populate model.params on the create request.

`variants` array (optional) — Concrete id+params combinations the model accepts. Each entry has a params array (which may be empty), a displayName, an optional description, and an optional isDefault flag.

```bash
curl --request GET \
  --url https://api.cursor.com/v1/models \
  -u YOUR_API_KEY:
```

**Response:**

```json
{
  "items": [
    {
      "id": "composer-2",
      "displayName": "Composer 2",
      "aliases": ["composer-latest", "composer"],
      "parameters": [
        {
          "id": "fast",
          "displayName": "Fast",
          "values": [
            { "value": "false" },
            { "value": "true", "displayName": "Fast" }
          ]
        }
      ],
      "variants": [
        {
          "params": [{ "id": "fast", "value": "true" }],
          "displayName": "Composer 2",
          "isDefault": true
        },
        {
          "params": [{ "id": "fast", "value": "false" }],
          "displayName": "Composer 2"
        }
      ]
    },
    {
      "id": "claude-4.6-sonnet-thinking",
      "displayName": "Claude 4.6 Sonnet (Thinking)",
      "variants": [
        {
          "params": [],
          "displayName": "Claude 4.6 Sonnet (Thinking)",
          "isDefault": true
        }
      ]
    }
  ]
}
```

### List GitHub repositories

**GET /v1/repositories**

List GitHub repositories accessible to the authenticated user through Grok Build's GitHub App installation.

> [!NOTE]
>
> This endpoint returns GitHub repositories only. Repositories on GitLab, Bitbucket Cloud, and Azure DevOps are not listed here, even though you can create agents against them with [Create An Agent](#create-an-agent).
>
> GitHub Enterprise Server repositories aren't listed either. Service account API keys always get an empty list, because the endpoint reads the caller's personal GitHub connection. In both cases, create the agent with the repository URL.

> [!WARNING]
>
> **This endpoint has strict rate limits.**
>
> Limit requests to **5 per minute** and **30 per hour** for each caller. Requests with a service account API key count against the service account, and requests with a user API key count against the user.
>
> This request can take tens of seconds to respond for users with access to many repositories.
>
> Make sure to handle this information not being available gracefully.

```bash
curl --request GET \
  --url https://api.cursor.com/v1/repositories \
  -u YOUR_API_KEY:
```

**Response:**

```json
{
  "items": [
    {
      "url": "https://github.com/your-org/your-repo"
    }
  ]
}
```
