> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.athenaintel.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.athenaintel.com/_mcp/server.

# Run read-only SQL over a lakehouse namespace

POST https://api.athenaintel.com/api/v0/lakehouse-namespaces/{asset_id}/sql
Content-Type: application/json

Run one SELECT over a lakehouse namespace you can view, as yourself, and get its columns and rows. The namespace must be shared with you (VIEW on the namespace asset, in your current workspace), and the statement may read only that namespace's tables: a table of any other namespace is refused (403). The statement is one SELECT in StarRocks SQL (WITH … SELECT and UNION, INTERSECT or EXCEPT of SELECTs included); anything else is refused (403): a write or schema change, SHOW, DESCRIBE, EXPLAIN, or more than one statement. The engine returns at most 2,000 rows for one statement (`truncated` says when more matched) and cancels a statement after 60 s. The public edge closes a connection that has waited about as long, so a statement that runs that long usually ends in a closed connection rather than an answer: keep statements well under a minute. The same read Athena's SQL workbench runs, except that a member's SharePoint projection is not read here. It is a person's read: their session or API key, or staff acting as them. A credential held by a computer, a preview or an agent's session, and a person's key sent from an agent's session, is refused (403).

Reference: https://docs.athenaintel.com/api-reference/lakehouse-namespaces/execute-sql

## Authentication

- `X-API-KEY` header (required) — API Key authentication via header

## Request

### Path parameters

- `asset_id` (string, required)

### Body (application/json)

This endpoint expects a LakehouseNamespaceSqlRequestIn.

- `sql` (string, required) — One SELECT in StarRocks SQL: a plain SELECT, WITH … SELECT, or SELECTs joined by UNION, INTERSECT or EXCEPT. It may read only this namespace's tables, named `<catalog>.<namespace>.<table>`; a table of any other namespace is refused (403). Any other statement is refused (403): a write or schema change, SHOW, DESCRIBE, EXPLAIN, or more than one statement. A blank statement is refused (422).
- `max_rows` (integer, optional, nullable) — Rows to return. Defaults to 1,000; at most 10,000 may be asked for, and the lakehouse engine returns at most 2,000 for one statement. `truncated` in the answer says when more rows matched.

## Response

### 200

Successful Response

- `asset_id` (string, required) — The lakehouse namespace asset the statement read
- `columns` (list of LakehouseNamespaceSqlColumnOut, required) — The result's columns, in order
- `row_count` (integer, required) — How many rows `rows` holds
- `rows` (list of list of any, required) — The result's rows, each a list of values in `columns` order
- `truncated` (boolean, required) — True when more rows matched than were returned: the request's `max_rows`, or the engine's cap of 2,000 rows per statement

## Errors

### 400 Bad Request Error

An asset that is not a lakehouse namespace, a statement the engine could not parse (a syntax error; its message is the detail), or one too large for the engine to plan, which is never sent (common table expressions nested inside one another, such as transform models copied in as WITH clauses; its message says what to do instead)

- `any`

### 401 Unauthorized Error

No valid credential

- `any`

### 403 Forbidden Error

The namespace is not shared with you (you are a member of its workspace without VIEW on it, or your share was revoked), the statement reads another namespace's tables or is not one SELECT (a write, a schema change, SHOW, DESCRIBE, EXPLAIN or more than one statement), SQL is turned off for this environment (ENVIRONMENT_FEATURE_DISABLED), or the credential cannot call this route

- `any`

### 404 Not Found Error

No such namespace in your current workspace: the id names nothing, or an asset of a workspace you are not a member of

- `any`

### 422 Unprocessable Entity Error

Validation Error

- `detail` (list of ValidationError, optional)

### 502 Bad Gateway Error

The engine refused or failed a statement it could parse (an unknown table or column, a cancelled statement, the engine unreachable); its message is the detail

- `any`

## Types

### LakehouseNamespaceSqlColumnOut

One column of a lakehouse namespace statement's result.

- `name` (string, required) — The column's name as the statement gave it
- `type` (string, required) — The engine's type for the column (e.g. `bigint`)

### ValidationError

- `loc` (list of ValidationErrorLocItems, required)
- `msg` (string, required)
- `type` (string, required)
- `ctx` (ValidationErrorCtx, optional)
- `input` (any, optional)

### ValidationErrorLocItems

- string
- integer

### ValidationErrorCtx

## Examples

**Request**

```json
{
  "sql": "SELECT region, count(*) AS orders FROM ws_1a2b3c.sales.orders GROUP BY region ORDER BY orders DESC",
  "max_rows": 500
}
```

**Response**

```json
{
  "asset_id": "asset_9249292-d118-42d3-95b4-00eccfe0754f",
  "columns": [
    {
      "name": "region",
      "type": "varchar"
    },
    {
      "name": "orders",
      "type": "bigint"
    }
  ],
  "row_count": 2,
  "rows": [
    [
      "EMEA",
      1200
    ],
    [
      "NA",
      950
    ]
  ],
  "truncated": false
}
```

**SDK Code**

```python
import requests

url = "https://api.athenaintel.com/api/v0/lakehouse-namespaces/asset_id/sql"

payload = {
    "sql": "SELECT region, count(*) AS orders FROM ws_1a2b3c.sales.orders GROUP BY region ORDER BY orders DESC",
    "max_rows": 500
}
headers = {
    "X-API-KEY": "<apiKey>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript
const url = 'https://api.athenaintel.com/api/v0/lakehouse-namespaces/asset_id/sql';
const options = {
  method: 'POST',
  headers: {'X-API-KEY': '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"sql":"SELECT region, count(*) AS orders FROM ws_1a2b3c.sales.orders GROUP BY region ORDER BY orders DESC","max_rows":500}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.athenaintel.com/api/v0/lakehouse-namespaces/asset_id/sql"

	payload := strings.NewReader("{\n  \"sql\": \"SELECT region, count(*) AS orders FROM ws_1a2b3c.sales.orders GROUP BY region ORDER BY orders DESC\",\n  \"max_rows\": 500\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("X-API-KEY", "<apiKey>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby
require 'uri'
require 'net/http'

url = URI("https://api.athenaintel.com/api/v0/lakehouse-namespaces/asset_id/sql")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["X-API-KEY"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"sql\": \"SELECT region, count(*) AS orders FROM ws_1a2b3c.sales.orders GROUP BY region ORDER BY orders DESC\",\n  \"max_rows\": 500\n}"

response = http.request(request)
puts response.read_body
```

```java
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.athenaintel.com/api/v0/lakehouse-namespaces/asset_id/sql")
  .header("X-API-KEY", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"sql\": \"SELECT region, count(*) AS orders FROM ws_1a2b3c.sales.orders GROUP BY region ORDER BY orders DESC\",\n  \"max_rows\": 500\n}")
  .asString();
```

```php
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.athenaintel.com/api/v0/lakehouse-namespaces/asset_id/sql', [
  'body' => '{
  "sql": "SELECT region, count(*) AS orders FROM ws_1a2b3c.sales.orders GROUP BY region ORDER BY orders DESC",
  "max_rows": 500
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'X-API-KEY' => '<apiKey>',
  ],
]);

echo $response->getBody();
```

```csharp
using RestSharp;

var client = new RestClient("https://api.athenaintel.com/api/v0/lakehouse-namespaces/asset_id/sql");
var request = new RestRequest(Method.POST);
request.AddHeader("X-API-KEY", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"sql\": \"SELECT region, count(*) AS orders FROM ws_1a2b3c.sales.orders GROUP BY region ORDER BY orders DESC\",\n  \"max_rows\": 500\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "X-API-KEY": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = [
  "sql": "SELECT region, count(*) AS orders FROM ws_1a2b3c.sales.orders GROUP BY region ORDER BY orders DESC",
  "max_rows": 500
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.athenaintel.com/api/v0/lakehouse-namespaces/asset_id/sql")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```