Skip to main content
Reference
For the complete documentation index optimized for AI agents, see llms.txt.
Send a dynamic query to POST /v2/query on a local or Helix Cloud instance. You can supply the query as a raw JSON request (--file/--json) or write it in the TypeScript DSL (-e/--ts/--ts-file) and let the CLI build the request for you.

Usage

Provide exactly one input: a JSON request (--file or --json) or a TypeScript DSL expression (-e/--ts or --ts-file). The four input flags are mutually exclusive.

Arguments

Available flags

Exactly one input flag is required (--file, --json, -e/--ts, or --ts-file).

Request body

The JSON request must include:
  • request_type — lowercase "read" or "write". Anything else is rejected with request_type must be lowercase 'read' or 'write'.
  • query_name — optional top-level query name for gateway logs and query diagnostics. Use exactly query_name; name and queryName are not accepted aliases. Missing or null falls back to __dynamic__.
  • query — exactly one typed read or write batch containing entries and returns. Missing query is rejected with dynamic query request must include query.
  • parameters and parameter_types — optional typed runtime values and their schemas.
helix init local scaffolds examples/request.json with a runnable read request:
Every traversal root must contain a valid source before an operation such as count. Use --file for checked-in or reusable requests, and --json for quick one-off requests from a shell. Quote inline JSON so your shell passes it as one argument.

Query warming

--warm sends the same read body with X-Helix-Warm: true. Helix Cloud fans the request out to every eligible database backend and discards their response bodies. The command succeeds silently on 204 No Content after at least one backend succeeds; partial backend failure does not fail the warm-up. If every target fails, the gateway returns the normal deterministic error. A standalone local instance warms its single process; the v0.0.4 runtime returns 200 OK with the normal query body. A managed cluster with no eligible warming target returns 503 Service Unavailable. Warm writes are rejected with 400 Bad Request before backend execution. At the HTTP/SDK layer, combine X-Helix-Warm: true with X-Helix-Require-Writer: true when only the authoritative writer should be warmed. Authentication, read rate limits, retries, and normal query timeouts still apply.

TypeScript DSL input

Instead of hand-writing JSON, you can pass a TypeScript DSL expression and let the CLI build the request — the same way mysql -e runs SQL from the shell:
How it works:
  • The expression must evaluate to a readBatch() or writeBatch() builder. g, readBatch, writeBatch, defineParams, and param are auto-imported and already in scope — you write only the expression, no imports.
  • The CLI evaluates it locally with Node using the forthcoming v3 @helix-db/helix-db SDK, calls .toQueryJson(), and posts the resulting operation-tree request to /v2/query. The builders are pure (no I/O), so no instance needs to be running to build the request — only to run it. There is no separate compile step.
  • request_type is inferred automatically from whether you used readBatch() or writeBatch().
Requirements:
  • Node.js 20+ on PATH (npm ships with it). On first use the CLI installs the SDK once into its cache directory; later runs reuse it.
  • For inline -e use, write a single expression with no TypeScript type annotations (it is evaluated as an expression, not compiled). Put more elaborate queries in a --ts-file.
If Node is missing, the CLI tells you to install Node 20+ or fall back to --json/--file. For the full DSL surface, see the helix-query-typescript skill.

Validation rules

Helix Cloud targets

For a Helix Cloud instance, helix query reads [enterprise.<instance>] in helix.toml and:
  • Posts to <gateway_url>/v2/query.
  • Sends an auth header named by query_auth_header (default Authorization) with the value read from the environment variable query_auth_env (default HELIX_API_KEY). The value is read from your shell environment or from a .env file in the project root (whichever is set), so you can keep the key out of your shell history.
If gateway_url is missing, the CLI returns:
If the auth env var is missing, the CLI returns Environment variable <NAME> is required for Enterprise query auth.

Connection errors

If the CLI cannot reach the instance, it reports cannot reach Helix instance '<instance>' at <endpoint> with a recovery hint tailored to the instance kind:
  • LocalStart it with helix start <instance> and check it with helix status <instance>. If it runs on another host/port, pass --host/--port.
  • EnterpriseCheck the gateway_url for '<instance>' in helix.toml and your network connection. helix sync <instance> refreshes the gateway metadata from Helix Cloud.

Output

  • A non-empty JSON response is pretty-printed by default; pass --compact to print on a single line.
  • 204 No Content (returned by Helix Cloud after at least one warm target succeeds) produces no output and exits successfully.
  • A standalone local warm read can return 200 OK; its normal JSON body is printed.
  • Non-2xx responses produce Query failed with HTTP <status>: <body> and exit with a non-zero status.

Examples

  • helix start — start a local instance to query against
  • helix sync — refresh Helix Cloud gateway/auth metadata