---
title: "Execute Query For Context Agent"
method: POST
path: "/api/context-agent/execute-query"
tags: ["Chat"]
---

# Execute Query For Context Agent

`POST /api/context-agent/execute-query`

## Request

- Base URL: `https://app.getdot.ai` (the document declares no server; this is the origin it was published from)
- URL: `https://app.getdot.ai/api/context-agent/execute-query`
- Auth: one of:
  - API key in header `X-API-KEY`
  - API key in cookie `Authorization`
  - OAuth 2 (password, token URL `/api/auth/token`)

Execute a read-only SQL or native Malloy query for Context Agent as CSV.

This endpoint is designed for Context Agent to run ad-hoc analysis queries.
The client saves the returned content inside its own sandbox, and a summary
is provided for LLM context.

Security:
- Admin-only SQL; modelers may query governed Malloy sources
- SQL must be SELECT-only; Malloy must run the authorized catalog source
- Row-level security automatically applied
- Configurable row limit (default 10,000)

Returns:
    - csv_content: CSV text for the authenticated client to save locally
    - summary: Data summary for LLM (row count, columns, sample values)
    - row_count: Number of rows returned
    - column_count: Number of columns
    - execution_time_ms: Query execution time

## Request body

- BodyExecuteQueryForContextAgentApiContextAgentExecuteQueryPost
  - `query` string, required
  - `table_name` string, required
  - `max_rows` integer

## Response `200`

Successful Response

- unknown

## Other responses

- `422`: Validation Error

---

[API](https://skmtc.dev/getdot/apis/dot-api-2.md) · [All operations](https://skmtc.dev/getdot/apis/dot-api-2/llms.txt) · [OpenAPI document](https://skmtc.dev/getdot/apis/dot-api-2/revisions/d26fe7163a7f?raw)
