Skip to main content
The /btql endpoint runs SQL over your logs, experiments, and datasets. Use this API endpoint to send a query request, and Braintrust runs the query synchronously and returns the rows in the response.
You can run the same SQL interactively in the SQL sandbox, or from your terminal with bt sql.

Base URL

The base URL depends on your organization’s data plane region: Authenticate every request with your API key in the Authorization header. The examples below use the US base URL.

Query data

Send a POST /btql request with a SQL query in the body. Data-source functions like project_logs() and experiment() accept an object name or its ID. See Querying by name for details. Braintrust runs the query synchronously and returns the results in a single response.
To run the same query from your terminal, use bt sql:

Request body

Send a JSON body with the query and options.
For correct day boundaries, set tz_offset to match your timezone. For example, use 480 for US Pacific Standard Time.
Request

Response

For fmt: "json", the response is an object with a data array of row objects. Each row’s fields match the columns your query selects.
Response
Use jsonl to stream one row per line, or parquet for a binary column format suited to large exports. When results overflow the synchronous response size, the response includes a cursor in the x-bt-cursor header. Send it back as cursor to fetch the next page. See Pagination below for details.

Pagination

For large result sets, the response returns a pagination cursor in the x-bt-cursor header. To fetch the next page, resend the query with that cursor and repeat until the header comes back empty. The cursor applies to the query itself, so how you pass it depends on the query format:
  • Structured query object: set a cursor field on the object, as shown in the example below.
  • SQL string: append OFFSET '<cursor>' to the query. See Syntax styles for the full clause mapping.
If you’re using the Python or TypeScript SDK, pagination is handled automatically. Only use this code if you’re developing with other tools.

Timeouts

All requests time out after 30 seconds, which is enough time for interactive queries, dashboards, and most routine reads. To optimize queries, see SQL best practices.

Examples

Fetch experiment results

Query an experiment to check review status or other metrics:

Fetch child spans by trace metadata

Retrieve specific child spans based on trace-level metadata:

Export data

Export logs, experiments, or datasets to JSON or Parquet by setting fmt.

Next steps

  • Learn the SQL syntax for querying logs, experiments, and datasets.
  • Follow SQL best practices to keep queries fast and within limits.
  • Run queries from your terminal with bt sql.
  • Review system limits for query timeouts and result-size caps.