---
title: "Start a Caveman Code session"
method: POST
path: "/code/sessions"
---

# Start a Caveman Code session

`POST /code/sessions`

## Request

- Base URL: `https://api.caveman.so/api/v1`
- URL: `https://api.caveman.so/api/v1/code/sessions`
- Auth: one of:
  - OAuth 2
    - Authorization code: `/api/v1/oauth/authorize`
    - Token URL: `/api/v1/oauth/token` scopes: `code:write`
  - HTTP bearer
  - API key in cookie `cave_access`
  - API key in cookie `__Secure-cave_identity.session_token`

POST /api/v1/code/sessions on the Caveman Cloud control plane. Requires the code:write scope. Not exposed to autonomous agents: The Agents API is driven by a service account's code:run key, or by a person in the Code app and console. An agent connection works inside a Code session and never starts, lists or drives Code sessions or agents from a control-plane connection.

## Request body

- object
  - `request_id` string, required: Idempotent per caller: a retry returns the session the first call started.
  - `agent` union
    - string, uuid
    - object
      - `id` string, uuid, required
      - `version` integer
  - `repo` string, required: owner/name: the repository the session's computer checks out.
  - `base_branch` string
  - `task` string, required: The first user message.
  - `title` string
  - `engine` 'caveman' | 'claude-agent' | 'codex'
  - `model` string: A model id or a class: fast, base, frontier or auto.
  - `budget_usd` number
  - `computer` object
    - `size` string
  - `files` string[]
  - `memory_stores` object[]
    - `id` string, required
    - `access` 'read_write' | 'read_only'
  - `metadata` object

## Response `201`

The session

- CodeSession: A Caveman Code session: the session, the workspace it runs in and what started it.
  - `id` string, uuid, required
  - `organization_id` string, uuid
  - `workspace_id` string, uuid, required
  - `computer_id` string, uuid, nullable
  - `origin` 'person' | 'api' | 'automation', required
  - `service_account_id` string, uuid, nullable
  - `agent` object, nullable
    - `id` string, uuid, required
    - `version` integer, required
  - `repo` string
  - `branch` string
  - `engine` string
  - `model` string
  - `title` string
  - `status` 'starting' | 'running' | 'requires_action' | 'idle' | 'terminated', required
  - `stop_reason` 'end_turn' | 'requires_action' | 'budget_reached' | 'error' | 'interrupted' | 'null', nullable
  - `usage` object, required
    - `input_tokens` integer, required
    - `output_tokens` integer, required
    - `cache_read_tokens` integer, required
    - `cost_usd` number, required: Measured: the sum of the calls that carried a cost.
    - `cost_priced` boolean, required: False once a call with tokens carried no cost (a subscription login, or a model with no price): cost_usd is then only the priced part.
  - `pull_requests` object[], required
    - `url` string, required
    - `state` string, required
  - `created_at` string, date-time, required
  - `updated_at` string, date-time, required
  - `ended_at` string, date-time, nullable
  - `metadata` object, required

## Other responses

- `400`: Invalid request.
- `401`: A person's sign-in or a code:run key is required.
- `403`: The role, the key's scope, or an inactive service account (cave_code_service_account_inactive) refuses.
- `409`: Paused (cave_code_paused), archived agent, no Cloud computers here, or the computer limit.
- `2XX`: Successful response. Exact status depends on synchronous or durable delivery outcome.
- `4XX`: Structured failure. `error.code` is stable; `error.request_id` is echoed in the x-cave-request-id header.
- `5XX`: Structured failure. `error.code` is stable; `error.request_id` is echoed in the x-cave-request-id header.

---

[API](https://skmtc.dev/caveman/apis/caveman-cloud-api.md) - [All operations](https://skmtc.dev/caveman/apis/caveman-cloud-api/llms.txt) - [OpenAPI document](https://skmtc.dev/caveman/apis/caveman-cloud-api/revisions/508312d01cfc?raw)
