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

# Execute query with NDJSON streaming

`POST /query/stream`

Same input as `POST /query`, returns NDJSON stream. For large result sets, exports, 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.
- No default `limit` (streaming is for export). Client disconnect = cancellation.
- `wait` parameter is ignored — streaming always blocks until complete.

## Request body

- QueryRequest
  - `q` string, required — SPL2 query string
  - `from` string — Start time: relative (`-1h`, `-7d`) or ISO 8601. Default: `-15m`
  - `to` string — End time: relative (`now`, `-5m`) or ISO 8601. Default: `now`
  - `limit` integer — Max events to return
  - `offset` integer — Offset for pagination (tabular results only)
  - `format` 'json' | 'csv' | 'raw'
  - `wait` number, nullable — Controls sync/async behavior: - `null` (default) — **Sync.** Block until query completes or server timeout (30s). Returns `200` with results or `408` on timeout. - `0` — **Async.** Return `202` immediately with a job handle. Client polls or subscribes to SSE for progress. - `N` (seconds) — **Hybrid.** Wait up to N seconds. If query completes in time → `200` with results. If not → `202` with job handle and current progress. Best for UI: short queries feel instant, long queries degrade gracefully.

## Response `200`

NDJSON event stream

## Other responses

- `400` — Invalid SPL2 query

## Changes

- **2026-03-03** `7141381739ac` — 1 breaking, 4 warning, 6 info
  - the request property `q` became required
  - removed the request property `earliest`
  - removed the request property `latest`
  - removed the request property `query`
  - …7 more

[Change history](https://skmtc.dev/lynxbase/apis/lynxdb-api/changes/query/stream/post.md)

---

[API](https://skmtc.dev/lynxbase/apis/lynxdb-api.md) · [All operations](https://skmtc.dev/lynxbase/apis/lynxdb-api/llms.txt) · [OpenAPI document](https://skmtc-service-production.skmtc.workers.dev/v1/apis/lynxbase/lynxdb-api/revisions/7141381739ac/schema)
