SQL editor
Query your spans, traces, and scores with read-only ClickHouse SQL.
The SQL editor runs read-only ClickHouse SQL over your project’s data. Use it for questions the Logs filters can’t answer, such as cost per model or error rate per customer.
Run a query
Open the editor
Go to Observability › SQL editor. A new tab offers Start from a template: Cost by day, Top models, Error rate, and Traces overview. Pick one, or write your own.
Write the SQL
The Tables panel on the right lists every table and column. Click a column to insert it, or use Preview rows on a table. The editor also autocompletes tables, columns, and functions.
This query returns cost and latency per model for the last 7 days:
Run it
Click Run or press ⌘ Enter (Ctrl Enter on Windows and Linux). If the tab has several statements, it runs the one at the cursor. If you select text, it runs the selection.
The results show below the editor, with the row count, duration, and time. Click a column header to sort, or click Inspect row to read one row in full.

Always filter on the table’s time column, such as timestamp for logs. Queries without one scan more data and are more likely to time out.
Save and manage queries
Every tab is a saved query. Your SQL saves as you type or run, and the editor shows Saved when it’s done.
- New query: click the button after the last tab. New queries are named Untitled query.
- Rename: hover the open tab and click the pencil.
- Delete: click × on the tab, then confirm. This deletes the saved query for good.
Chart the results
When the result has a time column and a numeric column, click Chart to plot it. Click Add to dashboard to put the chart on a Metrics view.
This query produces the chart above:
Export results
Click Export, or press E, and choose Export as CSV or Export as JSONL. The export reruns your query in the background, so it isn’t limited to the rows on screen. When it’s done, download it from the dialog or from Settings › Exports.
Copy rows as TSV, in the same menu, copies the rows shown.
Tables
The Rollups group in the Tables panel has pre-aggregated tables for faster charts over long ranges: log_metrics, log_metrics_hourly, latency_quantiles_minute, latency_quantiles_hourly, and metadata_metrics.
Useful logs columns include model, provider_id, cost, latency, prompt_tokens, completion_tokens, status, customer_identifier, thread_identifier, and trace_unique_id. Read custom properties with metadata['key'].
More examples
Error rate by model, last 24 hours:
Cost by a custom property, such as feature:

