---
title: "POST /projects/{projectId}/sql"
method: POST
path: "/projects/{projectId}/sql"
---

# POST /projects/{projectId}/sql

`POST /projects/{projectId}/sql`

## Request

- Base URL: `https://api.caveman.so/api/v1`
- URL: `https://api.caveman.so/api/v1/projects/{projectId}/sql`
- Auth: one of:
  - OAuth 2
    - Authorization code: `/api/v1/oauth/authorize`
    - Token URL: `/api/v1/oauth/token` scopes: `trace:read_metadata`
  - HTTP bearer
  - API key in cookie `cave_access`
  - API key in cookie `__Secure-cave_identity.session_token`

POST /api/v1/projects/{projectId}/sql on the Caveman Cloud control plane. Requires the trace:read_metadata scope. Exposed to autonomous agents as the query action of the caveman_sql tool (read access). One read-only ClickHouse SELECT over the bound project's SQL tables (requests, spans, tool_events, evals, logs, errors, events). The database pins the tenant and the window. Read sql.schema first. Per-person columns need billing:read; payload columns need payload:read and trace:read_payload. Results are bounded, never paged by re-running.

## Request body

- object
  - `sql` string, required: One ClickHouse SELECT over the SQL tables that sql.schema lists. Bind values as {name:Type} placeholders.
  - `params` object: Values for the {name:Type} placeholders; names may not start with cave_ or param_.
  - `window` string: Look back from now, 1h to 90d. Send window or from/to; neither reads the last 7 days.
  - `from` string: UTC start, RFC3339 or YYYY-MM-DD; at most 90 days before to.
  - `to` string: UTC end, RFC3339 or YYYY-MM-DD; defaults to now.

## Response `2XX`

Successful response. Exact status depends on synchronous or durable delivery outcome.

## Other responses

- `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)
