For the complete documentation index optimized for AI agents, see llms.txt.Send a dynamic query to
POST /v1/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
--file or --json) or a TypeScript DSL expression (-e/--ts or --ts-file). The four input flags are mutually exclusive.
Arguments
| Argument | Description |
|---|---|
INSTANCE | Instance name from helix.toml. Defaults to dev if omitted. |
Available flags
Exactly one input flag is required (--file, --json, -e/--ts, or --ts-file).
| Flag | Type | Required | Description | Default |
|---|---|---|---|---|
-f, --file | Path | One input required | JSON request body file. | — |
--json | String | One input required | Inline JSON request body. | — |
-e, --ts | String | One input required | TypeScript DSL expression, evaluated locally to build the request (like mysql -e). See TypeScript DSL input. | — |
--ts-file | Path | One input required | Path to a .ts file containing a TypeScript DSL expression. | — |
--warm | Boolean | No | Send the request as a cache-warming call (X-Helix-Warm: true). Read requests only. | false |
--host | String | No | Override the host for local instances. | localhost |
--port | Number | No | Override the port for local instances. | [local.<instance>] port (default 6969) |
--compact | Boolean | No | Print compact JSON instead of pretty-printed JSON. | false |
Request body
The JSON request must include:request_type— lowercase"read"or"write". Anything else is rejected withrequest_type must be lowercase 'read' or 'write'.query_name— optional top-level query name for gateway logs and query diagnostics. Use exactlyquery_name;nameandqueryNameare not accepted aliases. Missing ornullfalls back to__dynamic__.query— the dynamic query object: aqueriesarray of{ "Query": { "name", "steps", "condition" } }entries plus areturnslist naming what to return (see the example below). Missingqueryis rejected withdynamic query request must include query.parameters— optional object of named parameters.
helix init local scaffolds examples/request.json with a runnable read request:
NWhere) before any terminal aggregator like 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.
TypeScript DSL input
Instead of hand-writing JSON, you can pass a TypeScript DSL expression and let the CLI build the request — the same waymysql -e runs SQL from the shell:
- The expression must evaluate to a
readBatch()orwriteBatch()builder.g,readBatch,writeBatch,defineParams, andparamare auto-imported and already in scope — you write only the expression, no imports. - The CLI evaluates it locally with Node using the published
@helix-db/helix-dbSDK, calls.toDynamicJson(), and posts the resulting dynamic-query JSON to/v1/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_typeis inferred automatically from whether you usedreadBatch()orwriteBatch().
- 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
-euse, 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.
--json/--file. For the full DSL surface, see the helix-query-typescript skill.
Validation rules
| Rule | Error |
|---|---|
request_type is missing | dynamic query request must include request_type |
request_type is not lowercase read or write | request_type must be lowercase 'read' or 'write' |
query_name is blank or whitespace-only | query_name must be non-empty when provided |
name or queryName is used instead of query_name | Invalid request body / unknown field |
query is missing | dynamic query request must include query |
--warm is used with a write request | --warm is only valid for read requests |
Neither --file nor --json is provided | Clap usage error |
Both --file and --json are provided | Clap conflict error |
Helix Cloud targets
For a Helix Cloud instance,helix query reads [enterprise.<instance>] in helix.toml and:
- Posts to
<gateway_url>/v1/query. - Sends an auth header named by
query_auth_header(defaultAuthorization) with the value read from the environment variablequery_auth_env(defaultHELIX_API_KEY). The value is read from your shell environment or from a.envfile in the project root (whichever is set), so you can keep the key out of your shell history.
gateway_url is missing, the CLI returns:
Environment variable <NAME> is required for Enterprise query auth.
Output
- A non-empty JSON response is pretty-printed by default; pass
--compactto print on a single line. 204 No Content(returned for--warmrequests) produces no output and exits successfully.- Non-2xx responses produce
Query failed with HTTP <status>: <body>and exit with a non-zero status.
Examples
Related
helix start— start a local instance to query againsthelix sync— refresh Helix Cloud gateway/auth metadata