---
title: "Execute query with NDJSON streaming"
method: POST
path: "/query/stream"
tags: ["Query"]
---

# Execute query with NDJSON streaming

`POST /query/stream`

Returns an NDJSON stream for large result sets, exports, and piping.

**This is different from job SSE** (`GET /query/jobs/{id}/stream`):
- `/query/stream` — NDJSON export of results. One event per line. For `curl | jq`, data pipelines.
- `/query/jobs/{id}/stream` — SSE progress tracking. For Web UI real-time updates.

- Response: `Transfer-Encoding: chunked`, one JSON object per line.
- Last line is always `{"__meta": {...}}` — stream summary.
- Supported request fields: `q`/`query`, `from`/`earliest`, `to`/`latest`, and `variables`.
- `limit`, `offset`, `wait`, `profile`, and `format` are rejected with `400`.
- Client disconnect = cancellation.

## Request body

- QueryStreamRequest
  - `q` string — SPL2 query string
  - `query` string — Alias for `q`
  - `earliest` string — Legacy alias for `from`
  - `latest` string — Legacy alias for `to`
  - `from` string — Start time: relative (`-1h`, `-7d`) or ISO 8601.
  - `to` string — End time: relative (`now`, `-5m`) or ISO 8601.
  - `variables` object — Template variables substituted into the query before planning.

## Response `200`

NDJSON event stream

## Other responses

- `400` — Invalid SPL2 query

---

[API](https://skmtc.net/lynxbase/apis/lynxdb-api.md) · [All operations](https://skmtc.net/lynxbase/apis/lynxdb-api/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/lynxbase/lynxdb-api/versions/4363a070c444/schema)
