> ## Documentation Index
> Fetch the complete documentation index at: https://docs.corsair.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# API

> API reference for ClickHouse: every `clickhouse.api.*` operation with input and output types.

Every `clickhouse.api.*` operation is listed below with parameter shapes and return types from the plugin Zod schemas.

> [!NOTE]
>
> **New to Corsair?** See [API access](https://docs.corsair.dev/concepts/api.md), [authentication](https://docs.corsair.dev/concepts/auth.md), and [error handling](https://docs.corsair.dev/concepts/error-handling).

## Play

### get

`play.get`

Fetch the ClickHouse Play web UI HTML (Monaco editor + query UI).

**Risk:** `read`

```ts theme={null}
await corsair.clickhouse.api.play.get({});
```

**Input:** *empty object*

**Output**

| Name | Type | Required | Description |
| - | - | - | - |
| `url` | `string` | Yes | The Play UI URL |
| `html` | `string` | Yes | Play UI HTML page (Monaco editor + query UI) |
| `sizeBytes` | `number` | Yes | — |

***

## Query

### execute

`query.execute`

Execute a SQL query against the tenant ClickHouse instance and return the result rows. Arbitrary SQL is accepted — destructive statements require explicit permission.

**Risk:** `destructive` · **Irreversible**

```ts theme={null}
await corsair.clickhouse.api.query.execute({});
```

**Input**

| Name | Type | Required | Description |
| - | - | - | - |
| `sql` | `string` | Yes | SQL query to execute against ClickHouse |
| `database` | `string` | No | Default database context (sent as ?database=) |
| `limit` | `number` | No | Maximum rows to return; appended as LIMIT when not present in SQL |

**Output**

| Name | Type | Required | Description |
| - | - | - | - |
| `rows` | `object[]` | Yes | JSONEachRow objects; column names map to native JSON values |
| `rowCount` | `number` | Yes | — |

> [accordion] rows full type
>
> ```ts theme={null}
> {
> }[]
> ```

***

### listDatabases

`query.listDatabases`

List all databases on the tenant ClickHouse instance.

**Risk:** `read`

```ts theme={null}
await corsair.clickhouse.api.query.listDatabases({});
```

**Input:** *empty object*

**Output**

| Name | Type | Required | Description |
| - | - | - | - |
| `databases` | `object[]` | Yes | — |

> [accordion] databases full type
>
> ```ts theme={null}
> {
>   name: string,
>   engine: string
> }[]
> ```

***

### listTables

`query.listTables`

List tables in a ClickHouse database with their engine and approximate size.

**Risk:** `read`

```ts theme={null}
await corsair.clickhouse.api.query.listTables({});
```

**Input**

| Name | Type | Required | Description |
| - | - | - | - |
| `database` | `string` | Yes | Database to list tables from |
| `limit` | `number` | No | Maximum tables to return |
| `offset` | `number` | No | Tables to skip before returning rows |

**Output**

| Name | Type | Required | Description |
| - | - | - | - |
| `database` | `string` | Yes | — |
| `tables` | `object[]` | Yes | — |
| `count` | `number` | Yes | Number of tables returned |

> [accordion] tables full type
>
> ```ts theme={null}
> {
>   name: string,
>   engine?: string,
>   totalRows?: number | string | null,
>   totalBytes?: number | string | null
> }[]
> ```

***

## Schema

### getDatabase

`schema.getDatabase`

Get schema overview for a ClickHouse database; optionally include column definitions for each table.

**Risk:** `read`

```ts theme={null}
await corsair.clickhouse.api.schema.getDatabase({});
```

**Input**

| Name | Type | Required | Description |
| - | - | - | - |
| `database` | `string` | Yes | Database to introspect |
| `includeColumns` | `boolean` | No | When true, also fetch column definitions for each table |
| `limit` | `number` | No | — |
| `offset` | `number` | No | — |

**Output**

| Name | Type | Required | Description |
| - | - | - | - |
| `database` | `string` | Yes | — |
| `tables` | `object[]` | Yes | — |
| `count` | `number` | Yes | — |

> [accordion] tables full type
>
> ```ts theme={null}
> {
>   name: string,
>   engine?: string,
>   totalRows?: number | string | null,
>   totalBytes?: number | string | null,
>   columns?: {
>     name: string,
>     type: string,
>     position?: number | string | null,
>     comment?: string,
>     defaultExpression?: string
>   }[]
> }[]
> ```

***

### getTable

`schema.getTable`

Get column-level schema for a ClickHouse table, optionally with sample rows.

**Risk:** `read`

```ts theme={null}
await corsair.clickhouse.api.schema.getTable({});
```

**Input**

| Name | Type | Required | Description |
| - | - | - | - |
| `database` | `string` | Yes | Database the table belongs to |
| `table` | `string` | Yes | Table to introspect |
| `includeSample` | `boolean` | No | When true, include up to `sampleSize` rows from the table |
| `sampleSize` | `number` | No | Sample row count when includeSample is true; defaults to 5 |

**Output**

| Name | Type | Required | Description |
| - | - | - | - |
| `database` | `string` | Yes | — |
| `table` | `string` | Yes | — |
| `engine` | `string` | No | — |
| `totalRows` | `number \| string \| null` | No | — |
| `columns` | `object[]` | Yes | — |
| `sampleRows` | `Record<string, any>[]` | No | Sample rows; only present when includeSample is true |

> [accordion] columns full type
>
> ```ts theme={null}
> {
>   name: string,
>   type: string,
>   position?: number | string | null,
>   comment?: string,
>   defaultExpression?: string
> }[]
> ```

***


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.