Guide
Query API
The query API returns your logs, query results and detection tables to notebooks, scripts and data pipelines. Security analysts and data scientists work on the same rows. LTQL runs exactly as in Explore, and SQL exactly as on the SQL page. Results are paged JSON, and large pulls stream as Parquet. Every request reads through your workspace's own limits and is in the audit log.
For a worked notebook, see Notebooks: security and data science on the same data.
Get a key#
- Open Developers → Keys → API keys (admins and owners).
- Choose Create API key.
- Tick Query API (notebooks). This is the
queryscope.
The key only reads. It cannot save searches, create alert rules or change anything. To also keep queries in an investigation space from a notebook, tick Add analyses to investigation spaces (investigations) as well.
Send the key as Authorization: Bearer ltk_... or as X-Logthread-Key: ltk_....
| You run | Who may |
|---|---|
| LTQL, tables | any key with query |
| SQL and KQL, and exports | a key with query whose creator is a member, owner or admin (the rule of the SQL page and of exports in the app) |
A key limited to part of the data runs LTQL and SQL only over its part. It cannot read the tables, which hold the whole workspace.
Run a query: POST /api/v1/query#
curl -s https://logthread.com/api/v1/query \
-H "Authorization: Bearer $LOGTHREAD_API_KEY" -H 'Content-Type: application/json' \
-d '{"query": "severity:error | stats count() by service", "from": "2026-11-29T00:00:00Z", "to": "2026-11-30T00:00:00Z"}'| Field | Meaning |
|---|---|
language | ltql (default), sql or kql |
query | The query: LTQL up to 4,000 characters, SQL up to 20,000 |
params | SQL only: values bound by name, for example {"svc": "checkout"} for {svc:String} in the statement. Up to 30. from and to are bound for you |
from, to | RFC 3339 times with a UTC offset. The default is the last hour |
limit | LTQL records a page: 1 to 1,000 (default 1,000). SQL rows: 1 to 10,000 (default 1,000) |
cursor | The next_cursor of the previous page. SQL and KQL have one when the statement is ordered (ORDER BY; in KQL sort by or top); pass the same query, params and the answer's window with it |
How far back you can read:
- LTQL records: a 7-day page, read in 7-day slices back to your retention, newest first.
- LTQL
stats: up to 366 days, clamped to your retention. - SQL: up to your retention.
The answer:
{"kind": "records", "columns": [...], "rows": [...], "next_cursor": "eyJ...", "truncated": false,
"row_count": 100, "window": {"from": "...", "to": "..."},
"stats": {"read_bytes": 1048576, "elapsed_ms": 84.2},
"links": {"explore": "/explore?q=...", "save_search": "/explore?q=...&save=1", "alert": "/alerts/rules/new?type=scheduled_query&q=..."}}records(an LTQL search) has one object per record:event_id,ts,severity,severity_number,service,body,trace_id,span_id;attributesandresource.
Pass next_cursor back as cursor to read the next page. A query with its own sort or limit stage has one page.
table(LTQLstats, SQL, KQL) hascolumnswith their types, androwsas arrays in column order.
The rows are the same as in the app: the same query in Explore or on the SQL page gives the same rows. An ordered SQL or KQL statement pages with next_cursor (the next rows of the same statement and window, up to 100,000 rows); an unordered one cut at limit says truncated: true with a note: add an order, or export it.
Errors use the app's shape {code, message, retryable}. A mistake in a query is a 422 that gives the line and column where Logthread can place it. When the workspace is busy you get a 429 or 503 with Retry-After.
Export a large result: POST /api/v1/export#
Use the same body without limit and cursor, plus format: parquet (default) or ndjson. The file streams as it is read, so it has no row limit. LTQL exports hold the matching records. A stats query is refused with 422 use_query, because its table is small: get it from /api/v1/query instead. KQL exports as NDJSON only.
curl -s https://logthread.com/api/v1/export -o errors.parquet \
-H "Authorization: Bearer $LOGTHREAD_API_KEY" -H 'Content-Type: application/json' \
-d '{"query": "severity:error", "from": "2026-11-01T00:00:00Z", "to": "2026-11-29T00:00:00Z"}'One export runs at a time per workspace, and an export stops after 10 minutes or 10 GB. These are the export limits.
Detection and analysis tables: /api/v1/tables#
GET /api/v1/tables lists the tables and their columns. POST /api/v1/tables/{name} takes {from, to, limit, cursor}:
- the range defaults to the last 30 days, and is at most 366 days;
ruleswithout a range lists every rule; limitis up to 10,000 rows a page;- the answer has
next_cursoruntil the last page.
| Table | One row per | Notable columns |
|---|---|---|
rules | alert rule; detections have is_detection true | detection, techniques, tactic, query, enabled |
incidents | incident | rule_id, rule_name, is_detection, state, severity, started_at, acked_at, closed_at, disposition, outcome, time_to_ack_s, time_to_close_s |
situations | Situation | title, state, severity, security, score, member_count, incident_count |
situation_signals | signal in a Situation | situation_id, source, kind, service, env |
outcome is the analyst's mark from closing an incident:
- Remediated and Accepted risk are
true_positive; - False positive is
false_positive; - Duplicate is
duplicate; - an open incident is empty.
The precision of a rule is true_positive / (true_positive + false_positive) over its closed incidents. The tables hold no names, emails or note text.
From a notebook to a detection#
Each answer's links open the app's own guided steps, so a read-only key never changes anything:
exploreopens the query in Explore, or on the SQL page for SQL.save_searchopens the same page with the Save search dialog filled in. You name it and choose who sees it.alertopens the alert rule editor with the query filled in. It shows the 24-hour backtest, Would this have fired?, before you turn the rule on. An LTQL query that ends instatswith one aggregate becomes a computed-value rule:- you set its limit, then the backtest shows how often it would have fired over the last 24 hours;
- a
byclause is left out, andalert_notetells you to choose Evaluate each service separately or one incident per a field in the editor instead.
SQL has no alert link.
Keep the analysis with the case#
POST /api/investigations/spaces/{id}/analyses saves a query with how to chart it in an investigation space:
{"title": "Failed sign-ins per source", "language": "ltql",
"query": "event.action:login_failed | stats count() by source.ip", "range": "7d", "chart": "bar", "note": ""}- The query runs once over its range before it is kept, and a broken query is refused.
- A space keeps up to 20 analyses.
- In the app, the space's Analyses cards run each analysis again as the person looking.
- Listing needs
query. Adding and removing needinvestigations, and the key's creator must be a member.
Limits and costs#
- Rate: 60 requests a minute per key. Over that, you get 429 with
Retry-After. - Read budget: every read counts against your workspace's read allowance and its data scanned, like the same query in the app.
stats.read_bytessays how much each request read. - Concurrency: a loop in one notebook can slow only its own workspace's other queries, never another workspace's.
- Audit: each request is in the audit log as
query_api.query, with a hash of the query (never its text), the rows and the bytes read.