Skip to contentSkip to page list

Docs

Run a LangWatchQL query

Executes one read-only LangWatchQL SELECT over the analytics views and returns typed columns, rows, execution statistics and diagnostics. The query runs as a restricted database identity scoped to the projects this key can read.

POST/api/v1/query
Request and response examples
request.py
import osimport requests​origin = "https://app.langwatch.ai"path = "/api/v1/query"api_key = os.environ["LANGWATCH_API_KEY"]headers = {    "X-Auth-Token": api_key,    "Content-Type": "application/json",}payload = {}​response = requests.post(    origin + path,    headers=headers,    json=payload,)print(response.json())

The query ran. Columns, rows, execution statistics and diagnostics, scoped to the projects the key can read, or to the one project projectId names.

application/json · Generated from schema

{  "columns": [    {      "name": "string",      "type": "string"    }  ],  "rows": [    {}  ],  "statistics": {    "elapsedMs": 0,    "rowsRead": 0,    "bytesRead": 0,    "rowsReturned": 0  },  "diagnostics": [    {      "code": "MULTI_PROJECT_RESULT",      "message": "string",      "meta": {}    }  ],  "followsTimeWindow": false,  "followsGranularity": false,  "granularitySeconds": 0,  "coarsenedFromSeconds": 0,  "completeness": {    "state": "complete",    "unit": "string",    "total": 0,    "fields": [      {        "field": "string",        "label": "string",        "present": 0      }    ],    "buckets": [      {        "start": "string",        "n": 0      }    ],    "unpriced": {      "count": 0,      "models": [        "string"      ]    }  },  "params": {}}
api-reference/query/run-a-langwatchql-query

Authorization

X-Auth-Tokenstringheaderrequired

Project API key for sending traces and accessing project-scoped resources. Format: sk-lw-... (no underscore). Obtain one by creating a project via the Admin API or the LangWatch UI.

Request body

application/json · Required

sqlstringrequired
At least 1 characterUp to 50000 characters
parametersobject
timeWindowobject
startstring | number | string (date-time)required
endstring | number | string (date-time)required
granularitySecondsnumber
Option 1number
Option 2number
Option 3number
Option 4number
Option 5number
projectIdstring

Reads this one project, which the key must hold analytics:view on. Send projectId or projects, not both.

At least 1 character
projectsstring | string[]

The projects to read, each one the key holds analytics:view on, or the string "all" for every project the key can read. A key that reaches several projects must name them or send "all"; a key that reads one project defaults to it. When the statement declares {dashboard_context_projects:Array(String)}, params.dashboard_context_projects lists what was read.

Option 1string
Option 2string[]
sourcesstring[]

The trace origins {dashboard_context_sources:Array(String)} is bound to; application when absent. The placeholder does not filter by itself: the statement keeps its rows with a predicate such as WHERE Source IN {dashboard_context_sources:Array(String)}. A statement that never uses the placeholder counts every origin.

Responses

200

The query ran. Columns, rows, execution statistics and diagnostics, scoped to the projects the key can read, or to the one project projectId names.

application/json

columnsobject[]required
namestringrequired
typestringrequired
rowsobject[]required
statisticsobjectrequired
elapsedMsnumberrequired
rowsReadnumberrequired
bytesReadnumberrequired
rowsReturnednumberrequired
diagnosticsobject[]required
codestringrequired
One of"MULTI_PROJECT_RESULT""POSSIBLE_FANOUT""UNBOUNDED_TIME_RANGE""MISSING_TIME_BUCKETS""INCOMPLETE_COMPARISON_PERIOD""APP_FUNCTION_VALUE_TRUNCATED""APP_FUNCTION_UNRESOLVED_KEYS""APP_FUNCTION_RESULT_TRUNCATED""INSTANT_EVAL_SKIPPED""SHARE_WINDOW_LIMITED""SOURCES_IGNORED""GRANULARITY_COARSENED"
messagestringrequired
metaobject
followsTimeWindowbooleanrequired
followsGranularitybooleanrequired
granularitySecondsnumber
coarsenedFromSecondsnumber
completenessobject
statestringrequired
One of"complete""partial""missing""no_traffic"
unitstringrequired
totalnumberrequired
fieldsobject[]required
bucketsobject[]
unpricedobject
paramsobject
400

Bad Request

application/json

typestringrequired
codestringrequired
messagestringrequired
retryablebooleanrequired
metaobject
trace_idstring
span_idstring
traceobject
traceIdstring
spanIdstring
traceUrlstring
logsUrlstring
tipsstring[]
docs_urlstring
faultstring
One of"customer""platform""provider""presumed_platform"
reasonsany[]
401

Unauthorized

application/json

typestringrequired
codestringrequired
messagestringrequired
retryablebooleanrequired
metaobject
trace_idstring
span_idstring
traceobject
traceIdstring
spanIdstring
traceUrlstring
logsUrlstring
tipsstring[]
docs_urlstring
faultstring
One of"customer""platform""provider""presumed_platform"
reasonsany[]
403

Forbidden

application/json

typestringrequired
codestringrequired
messagestringrequired
retryablebooleanrequired
metaobject
trace_idstring
span_idstring
traceobject
traceIdstring
spanIdstring
traceUrlstring
logsUrlstring
tipsstring[]
docs_urlstring
faultstring
One of"customer""platform""provider""presumed_platform"
reasonsany[]
404

Not Found

application/json

typestringrequired
codestringrequired
messagestringrequired
retryablebooleanrequired
metaobject
trace_idstring
span_idstring
traceobject
traceIdstring
spanIdstring
traceUrlstring
logsUrlstring
tipsstring[]
docs_urlstring
faultstring
One of"customer""platform""provider""presumed_platform"
reasonsany[]
422

Unprocessable Entity

application/json

typestringrequired
codestringrequired
messagestringrequired
retryablebooleanrequired
metaobject
trace_idstring
span_idstring
traceobject
traceIdstring
spanIdstring
traceUrlstring
logsUrlstring
tipsstring[]
docs_urlstring
faultstring
One of"customer""platform""provider""presumed_platform"
reasonsany[]
500

Internal Server Error

application/json

typestringrequired
codestringrequired
messagestringrequired
retryablebooleanrequired
metaobject
trace_idstring
span_idstring
traceobject
traceIdstring
spanIdstring
traceUrlstring
logsUrlstring
tipsstring[]
docs_urlstring
faultstring
One of"customer""platform""provider""presumed_platform"
reasonsany[]

Documentation