Skip to contentSkip to page list

Docs

npx langwatch

Trace any coding agent · Setup guide →

LangWatchQL

Read-only SQL over your traces, spans, evaluations, simulations and coding-agent sessions, from the REST API, the CLI or an MCP client.

On this page

What is LangWatchQL

LangWatchQL is the ClickHouse SQL dialect that LangWatch accepts over its analytics views. You send one SELECT statement, optionally with a WITH clause, and you get back columns and rows. The database runs it with readonly = 1, so a statement cannot change your data.

Name a view without a database, for example traces or trace_metrics_by_minute, as the examples in this guide do. A bare name resolves to the database your deployment serves, so the same statement runs on LangWatch Cloud and on a self-hosted deployment. Your deployment's own prefix also works (langwatch.traces on LangWatch Cloud), but any other prefix is refused.

A self-hosted deployment serves the database named in its CLICKHOUSE_URL. LangWatchQL is unavailable when CLICKHOUSE_URL has no database in it. The full list, with every column and the permission it needs, is in the Query API reference, and GET /api/v1/query/schema returns the list your key can query today.

What is LangWatchQL for

Use LangWatchQL for a join across views, a percentile on one group of traces, rows exported to a file, or a question an agent asks from code. Dashboards read their data with LangWatchQL too: each widget runs named LangWatchQL statements.

For finding individual traces with their spans and evaluations, use the trace filter instead. Querying your data compares the two languages.

How do I run a query

You can send the same statement from REST, the CLI or MCP, and each one needs the analytics:view permission. REST and the CLI sign in with an API key, while the hosted MCP server also accepts OAuth sign-in. See MCP.

POST /api/v1/query takes the statement in the sql field and answers with columns, rows, statistics and diagnostics.

example.shBash
curl -X POST https://app.langwatch.ai/api/v1/query \  -H "X-Auth-Token: $LANGWATCH_API_KEY" \  -H "Content-Type: application/json" \  -d '{"sql": "SELECT TraceId, TraceName, OccurredAt, TotalDurationMs FROM traces WHERE OccurredAt >= subtractDays(now(), 1) AND ContainsErrorStatus ORDER BY OccurredAt DESC LIMIT 100"}'

A key that reaches several projects must name them: send projects, a list of ids or "all", or projectId for one. Without it the request is refused with 422 projects_required. Request fields, auth headers and status codes are in Run a LangWatchQL query.

Where to go next

Your first queries

One worked query for each main view

Read and judge conversations

Pull transcripts and model calls into a result, and ask a question of each one

Limits and cost

Row cap, timeouts, rate limits per plan and what is charged

Common questions

The error messages you can get and how to fix each one

Documentation