Skip to main content
-q, --query runs the JSON response through a jq filter and prints the results as raw values, one per line. It is mutually exclusive with --json. On a list command, the filter always runs against a bare JSON array of resources, so .[].metadata.id works on every list command. This holds even where --json wraps the array: inferencing list-models and inferencing list-endpoints emit {"data":[...]} under --json, but -q still sees the array:
On a command that returns one resource, the filter runs against that resource:

Extract a single field

Get just the IDs from a list response:
Each filter result is printed on its own line, so the output flows naturally into shell loops:

Reshape the output

Filters can transform the response into a new structure. Results that are not scalars (objects and arrays) print as compact JSON, one per line. The following collects each instance’s id and name into a single array:
Filter first, then project:

Combine with an external jq

The output of -q is still valid JSON when the filter produces JSON, so you can pipe it into jq (or any other JSON-aware tool) for further processing:

Multiple filters

-q can be repeated. The filters’ results are zipped into one line per item: one result from each filter per line, space-separated, which is handy for tabular output:
Output stops as soon as any filter runs out of results. When that happens, a warning is printed on stderr, unless the filter that ran out is the first one: a short first filter is deliberate, as in this example, which prints the count next to the first ID:

When a filter fails

An invalid filter makes the command exit with status 1. After a create or update, the resource has already been saved by then, so the CLI prints the full payload to stdout and the error on stderr explains that only the filter failed.