SQL console
Use the SQL console when a filter is not enough: to aggregate, join or export your data.
Select SQL in the sidebar. The console has an editor with autocomplete from the schema, a results grid with a Chart tab, and a sidebar with Schema and Saved tabs. Press ⌘↵ (or Ctrl+Enter) to run the query.
Select Format (Shift+Alt+F) to format the query.
The tables
Section titled “The tables”You query views of your project’s data: spans, traces, sessions, scores, experiment_items and dataset_items. Write their names without a prefix. See the SQL schema for every column.
The console shows raw data. Unlike the lists, it does not hide evaluation traces or experiment traces. Filter them out yourself with environment.
Query tabs
Section titled “Query tabs”Open a query in each tab, up to 20 per project. Use the plus button for a new tab and the close button on a tab to close it. Your tabs stay in your browser.
Examples
Section titled “Examples”The Examples menu holds ready-made queries. Three of them:
Cost per model per day:
SELECT date_trunc('day', start_time) AS day, model, sum(cost_total) AS costFROM spansWHERE span_kind = 'llm' AND model IS NOT NULLGROUP BY day, modelORDER BY day, cost DESCLatency percentiles of model calls, per model:
SELECT model, approx_percentile_cont(duration_ms, 0.5) AS p50_ms, approx_percentile_cont(duration_ms, 0.95) AS p95_ms, approx_percentile_cont(duration_ms, 0.99) AS p99_ms, count(*) AS callsFROM spansWHERE span_kind = 'llm' AND model IS NOT NULLGROUP BY modelORDER BY calls DESCUsers by spend:
SELECT user_id, count(*) AS traces, sum(cost_total) AS costFROM tracesWHERE user_id IS NOT NULLGROUP BY user_idORDER BY cost DESCLIMIT 50Parameters
Section titled “Parameters”Write a parameter as {name:Type}, where the type is String, Int, Float, Bool or Timestamp. The console asks for a value for each one. A Timestamp takes an RFC 3339 time or epoch milliseconds.
SELECT trace_id, name, cost_totalFROM tracesWHERE user_id = {user:String} AND cost_total > {min_cost:Float}ORDER BY cost_total DESCTime range
Section titled “Time range”The range picker sets the period that every query reads, for spans, traces and scores. Keep it as short as you can. Without a range, a query reads all the history your plan allows.
Limits
Section titled “Limits”The console runs read-only queries in a sandbox:
- One statement per run: a
SELECT,WITH,VALUES, a set operation, orEXPLAINof one of them. Statements that change data or settings are refused. - Queries are limited in size and in the number of tables they read.
- A query that runs too long is stopped, and so is one that needs more memory than the server allows. The error says which.
- A result holds at most 10,000 rows. When more rows match, the result is marked as truncated. Exports are not capped at that figure.
- Some functions are not available, such as those that can build very large values (
generate_series,repeat,replace). - Correlated subqueries,
WITH RECURSIVE,LATERALjoins,ROLLUP,CUBE,GROUPING SETS, and non-equi joins without an equality key are refused. See the SQL schema for the available functions.
Errors show in the console with the position of the problem.
Results
Section titled “Results”The Table tab shows the rows. Select a row to open a detail view with every column, its type and value, a copy button for each value, and Copy row as JSON.
The Chart tab draws the result as a Line or Bar chart. Choose the X column, one or more Y columns, and optionally a Split by column. A chart shows at most 5 series and the first 1,000 rows, and says so when it clips. Split by works with one Y column.
Saved queries and history
Section titled “Saved queries and history”Save a query with its parameters and range from the Saved queries menu: Save as…, then Save to update it. The Saved tab of the sidebar lists your queries under Mine and the project’s shared queries under Shared, with a filter box. A saved query is private to you until you select Share with project. Sharing needs the member role, and so does changing a shared query.
The History menu lists your last 50 runs, kept in your browser. Pick one to load it.
Export
Section titled “Export”Export a result with Export as CSV, NDJSON or Parquet. Exporting needs the member role. In CSV, a cell that starts with =, +, - or @ gets a leading ', so a spreadsheet does not run it as a formula.
From the command line
Section titled “From the command line”cetra query runs the same SQL against a running server and prints a table, JSON, CSV, NDJSON or Parquet.
cetra query --project acme/demo --since 24h \ "SELECT model, count(*) AS calls FROM spans WHERE span_kind = 'llm' GROUP BY model"See the CLI reference.