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

# Command line interface (CLI)

> Run Chowder from your terminal.

Use `chowder sql` to query data from your terminal or a script. Use the same SQL readers and AI column functions as in Python. Results go to stdout.

## Run a query

Follow [Installation](https://docs.chowder.ai/installation.md#install-the-cli) to set up Chowder, then run a query:

```bash theme={"theme":"css-variables","languages":{"custom":["/languages/chowder-sql.json"]}}
chowder --help
chowder sql "SELECT 42 AS answer;"
```

Read the first five pages of a hosted document:

```bash theme={"theme":"css-variables","languages":{"custom":["/languages/chowder-sql.json"]}}
chowder sql "
SELECT
    source,
    page_number,
    content
FROM read_documents('hf://buckets/chowderai/chowder-demo/pdf/data/att-management-discussion-and-analysis-2020.pdf')
LIMIT 5;
"
```

Local AI processing may download model artifacts on first use. See [Data sources](https://docs.chowder.ai/guides/data-sources.md) for local paths, object storage, and other supported sources.

## Read SQL from a file or stdin

Save a query in `query.sql`, then export its results:

```chowder-sql query.sql theme={"theme":"css-variables","languages":{"custom":["/languages/chowder-sql.json"]}}
SELECT
    source,
    page_number,
    content
FROM read_documents('hf://buckets/chowderai/chowder-demo/pdf/data/att-management-discussion-and-analysis-2020.pdf')
LIMIT 5;
```

```bash theme={"theme":"css-variables","languages":{"custom":["/languages/chowder-sql.json"]}}
chowder sql --file query.sql --format jsonl > pages.jsonl
```

You can pipe SQL into the command or explicitly read stdin with `--file -`:

```bash theme={"theme":"css-variables","languages":{"custom":["/languages/chowder-sql.json"]}}
echo 'SELECT 42 AS answer;' | chowder sql
cat query.sql | chowder sql --file - --format csv > pages.csv
```

Choose one input: inline SQL, `--file`, or stdin. SQL input must not be empty.

## Choose an output format

The default is `table` when stdout is a terminal and `jsonl` otherwise. Set `--format` explicitly in scripts.

| Format | Output |
| - | - |
| `table` | Terminal preview of up to 100 rows and 80 characters per cell |
| `json` | One JSON array of row objects |
| `jsonl` | One JSON row object per line |
| `csv` | A header row followed by CSV records |

JSON, JSONL, and CSV emit all rows produced by the query. Table previews can shorten long values; use a machine-readable format for complete values. Use SQL `LIMIT` to bound the query rather than relying on the preview cap.

```bash theme={"theme":"css-variables","languages":{"custom":["/languages/chowder-sql.json"]}}
chowder sql "SELECT 42 AS answer;" --format json
```

The JSON result is:

```json theme={"theme":"css-variables","languages":{"custom":["/languages/chowder-sql.json"]}}
[{"answer": 42}]
```

JSON and JSONL require unique column names. Use SQL aliases to give columns unique names.

Nested structs and lists retain their structure in JSON output. CSV encodes them as JSON within a cell and writes nulls as empty cells. Binary values use base64 strings. Dates, times, timestamps, decimals, and non-finite floats use strings; durations use ISO 8601 strings.

## Set paths and caching

Use `--directory` (or `-C`) to choose the working directory for relative paths. Use `--cache-dir` to choose the result cache directory:

```bash theme={"theme":"css-variables","languages":{"custom":["/languages/chowder-sql.json"]}}
chowder sql --directory /path/to/project --file query.sql --cache-dir .chowder-cache
```

The command changes directory before reading the SQL file or opening the engine. In this example, `query.sql`, `.chowder-cache`, and relative data paths resolve from `/path/to/project`.

Each `chowder sql` command creates an engine and closes it on exit. Session views do not carry over to a later command. See [Caching](https://docs.chowder.ai/concepts/caching.md) for result reuse across engines.

## Use remote AI compute

Set the engine's environment variables before launching the command:

```bash theme={"theme":"css-variables","languages":{"custom":["/languages/chowder-sql.json"]}}
export CHOWDER_REMOTE=1
export CHOWDER_API_URL="your-api-url"
export CHOWDER_API_TOKEN="your-api-token"
chowder sql --file query.sql --format jsonl
```

Set `CHOWDER_API_URL` to the endpoint from your Cloud dashboard or self-hosted server operator. A URL and token alone do not enable remote compute. SQL planning and relational execution stay in the CLI process. See [Connect to remote AI compute](https://docs.chowder.ai/guides/remote-compute.md) for endpoint settings and [Chowder Cloud](https://docs.chowder.ai/cloud/quickstart.md) for account setup.

## Handle command failures

The CLI writes query results to stdout and errors to stderr. Scripts can check the exit status:

| Status | Meaning |
| - | - |
| `0` | Success, including help and version output |
| `1` | Query, file, or execution error |
| `2` | Invalid command arguments or missing or empty SQL input |
| `130` | Interrupted or cancelled execution |

A query can fail after streaming some output. Check the exit status before treating an export as complete.

Run `chowder --version` to check the installed version, or `chowder <command> --help` for a command's options. To let an AI agent run queries, see [Local MCP server](https://docs.chowder.ai/guides/mcp.md).


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