> ## Documentation Index
> Fetch the complete documentation index at: https://aivision.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Read the relevant procedure and prerequisites before suggesting commands. Cite the section and give an observable check. Treat sample data as illustrative. Report product actions and results only when verified in the user's environment.

# CLI queries

> Query Traces, Spans and Sessions, and export JSONL.

This page covers data queries. OpenShell service installation, status, logs and safe removal use the separate `aiv plugin` commands described in [Deploy the OpenShell plugin](https://aivision.mintlify.site/en/deployment/openshell.md). The plugin HTTP token is not a query SpaceKey.

## Prepare query credentials

Account login manages accounts and Spaces; data queries use a SpaceKey. These credentials serve different purposes.

Prepare the client using [Install aiv CLI](https://aivision.mintlify.site/en/guides/install-cli.md). These examples query Codex. Replace the platform URL, email, and `SPACE_ID` with your own values. A Web login or Web-generated installation command does not establish a CLI account session.

```bash theme={null}
aiv --version
aiv auth login --endpoint https://vision.example.com --email you@example.com
aiv auth status
aiv space list
aiv space use SPACE_ID
```

Enter your password at the prompt. Find the same space as the Web UI with `aiv space list`, then select it with `space use`. `space list` lists spaces without switching the current one. Choose one of the following paths.

**You already have a full Key**, copied from the Web creation dialog or provided by an administrator: run this command and paste that Key at the hidden prompt. Import verifies and saves it for the current space. Use this path to verify a Key created on the website.

```bash theme={null}
aiv key import
```

**You do not have a Key yet:** administrators and developers can create and save a new query Key. Without creation permission, obtain an authorized full Key from an administrator and import it as above.

```bash theme={null}
aiv key create --name cli
```

The following commands explicitly use `--agent-product Codex`. For another Agent, use its actual platform product identifier, such as `langfuse` for SDK ingestion; do not supply an individual Agent UUID. Successful onboarding may save a default product, but a first query or a space switch should not depend on one.

For Web Key creation, verification and rotation, see [Spaces and permissions](https://aivision.mintlify.site/en/guides/spaces.md).

## Follow one record from list to detail

1. List Traces in the time range containing your task and copy one complete ID.

```bash theme={null}
aiv query trace list --since 6h --limit 20 --format json --agent-product Codex
```

2. Replace `TRACE_ID` with that ID and run `trace get` first. Copy a `span_id` from the returned `spans`, replace `SPAN_ID`, then read that Span. `span list` fetches a batch by ID and also requires at least one Span ID. Replace placeholders before execution.

```bash theme={null}
aiv query trace get TRACE_ID --format json --agent-product Codex
aiv query span get TRACE_ID SPAN_ID --format json --agent-product Codex
aiv query span list TRACE_ID SPAN_ID --format json --agent-product Codex
```

3. To inspect a session, list Sessions first and replace `SESSION_ID` with an ID from that result. Keep the same time range for session usage.

```bash theme={null}
aiv query session list --since 6h --limit 20 --format json --agent-product Codex
aiv query session get SESSION_ID --format json --agent-product Codex
aiv query session usage SESSION_ID --since 6h --agent-product Codex
```

**Success:** the detail ID matches the list, and its name, time and status match the same record in the Web UI. An empty list does not confirm onboarding: check Space, product and time range, then use [no-data troubleshooting](https://aivision.mintlify.site/en/help/no-data.md). Inspect query metadata with `aiv query metadata traces --agent-product Codex`.

`--since` / `--until` accept RFC3339, timestamps and relative durations such as `15m`, `6h` and `2d`. The default window is the last hour. Use `--format json` for scripts.

## Batch exports

Run in the local directory where you want to save the data. `./dataset` is relative to that directory and is created by the CLI. Use a new empty directory for each export; an existing JSONL file with the same name is overwritten.

```bash theme={null}
aiv query trace export ./dataset --since 24h --limit 500 --agent-product Codex
aiv query log export ./dataset --since 24h --limit 5000 --agent-product Codex
```

Defaults produce `traces.jsonl` (one Trace detail per line) and `events.jsonl` (one event per line). Check that the reported `exported N` matches the line count, and open one JSON record to verify its ID and time. An empty Trace result prints `no traces to export` and may create no file; an old file is not evidence of this run.

```bash theme={null}
wc -l ./dataset/traces.jsonl ./dataset/events.jsonl
```

`--limit` caps the current list; exports do not automatically paginate. Reaching that limit does not establish a complete export. For an archive, use fixed `--since` / `--until` bounds, then use supported backend pagination or split time windows into separate directories. Errors may leave partial files; fix the cause and retry into a new directory. Exports may contain raw context; review collection mode and content before sharing.

## Multiple platforms

```bash theme={null}
aiv auth login --profile work --endpoint https://work.example.com --email you@example.com
aiv space list --profile work
aiv space use SPACE_ID --profile work
aiv key create --name cli --profile work
aiv query trace list --profile work --since 1h --agent-product Codex
```

Each profile binds a platform and account, and each Space saves its own Key. For 401 check Key validity; for 403 check that the Key belongs to the requested Space. Account login alone does not configure a query Key.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.