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

# Run simulations from the CLI

> Install the Tuner CLI, start a simulation run from your terminal, read the results, and use the exit code and JSON output in scripts.

> [!NOTE]
>
> Before you start, you need:
>
> * Linux or macOS, with Node.js 22 or later.
> * A [Tuner API key](https://docs.usetuner.ai/docs/getting-started/api-keys.md#create-a-tuner-api-key).
> * The agent's [Agent Remote ID](https://docs.usetuner.ai/docs/getting-started/api-keys.md#find-your-agent-remote-id).
> * [Inbound](https://docs.usetuner.ai/docs/simulation/inbound/setup.md) or [outbound](https://docs.usetuner.ai/docs/simulation/outbound.md) simulation set up for the agent.

## What is the Tuner CLI?

The Tuner CLI starts a simulation run for an agent and prints a verdict for each Scenario as it lands. It runs saved Scenarios from the [Scenario Library](https://docs.usetuner.ai/docs/simulation/scenarios.md), picked by tag, by ID or by [suite](https://docs.usetuner.ai/docs/simulation/suites.md).

## Install

Install the package globally. It adds the `tuner` command.

```bash theme={null}
npm install -g @usetuner.ai/cli
tuner --version
```

To run it without installing, use `npx @usetuner.ai/cli` in place of `tuner`.

## Set your credentials

The CLI reads the same variables as the SDK integrations. If your project already sends calls to Tuner with an SDK, run the CLI from that folder and there's nothing else to set up.

| Variable | Required | Description |
| - | - | - |
| `TUNER_API_KEY` | Yes, unless you ran `tuner auth login` | Your Tuner API key. |
| `TUNER_AGENT_ID` | Yes, unless you pass `--agent` | The agent's Agent Remote ID. The numeric agent ID also works. |
| `TUNER_WORKSPACE_ID` | No | If set, the CLI stops when the key belongs to a different workspace. |
| `TUNER_BASE_URL` | No | The API base URL. The default is `https://api.usetuner.ai`. |

To run outside a project folder, store a key once:

```bash theme={null}
tuner auth login
```

The CLI checks the key with Tuner and prints the workspace it belongs to. You can give it the key in three ways:

* Type it at the prompt.
* Pipe it in on stdin.
* Pass it with `--api-key`, which stays in your shell history.

The CLI stores the key in `credentials.json`, readable only by you:

| OS | Path |
| - | - |
| macOS | `~/Library/Application Support/tuner/credentials.json` |
| Linux | `$XDG_CONFIG_HOME/tuner/credentials.json`, or `~/.config/tuner/credentials.json` if `XDG_CONFIG_HOME` is not set |

For each value, the CLI uses the first one it finds, in this order:

1. The flag (`--api-key`, `--agent`, `--base-url`).
2. The environment variable.
3. For the key only, the key stored by `tuner auth login`.

## Run your first simulation

**1. Find a tag to run**

Tag the Scenarios you want in the [Scenario Library](https://docs.usetuner.ai/docs/simulation/scenarios.md), then list them:

```bash theme={null}
tuner scenarios list --tag smoke
```

**2. Start the run**

```bash theme={null}
tuner sim run --tag smoke
```

The CLI prints the workspace and agent it resolved before it starts, so you can see where the calls go.

**3. Read the results**

Each Scenario's verdict prints as it lands. When the run ends, the CLI prints a summary line and the dashboard URL.

```text theme={null}
Workspace: Acme · Agent: booking-staging (616)
Running 3 scenarios (run 482)...
  ✓ passed          Caller books a table for two
  ✗ failed          Caller asks to move a booking   failed evals: Offers an alternative time
  ✓ passed          Caller cancels a booking

2 passed · 1 failed · 0 inconclusive
<dashboard URL of the run>
```

The exit code is `1` here because a Scenario failed. See [Exit codes](#exit-codes).

## Choose what to run

Pass exactly one of `--tag`, `--scenario` or `--suite`.

```bash theme={null}
# Every Scenario with this exact tag
tuner sim run --tag smoke

# One Scenario, or several
tuner sim run --scenario 31
tuner sim run --scenario 31 --scenario 32
tuner sim run --scenario 31,32,33

# A suite, with its Scenarios and run settings
tuner sim run --suite smoke
```

* `--tag` matches the tag exactly, including case.
* `--scenario` takes numeric Scenario IDs from `tuner scenarios list`. Duplicate IDs are rejected.
* A tag with no Scenarios stops the command with an error that points to `tuner scenarios list`.
* An empty `--tag`, for example from an unset shell variable, stops the command with exit `2`.

A run holds up to 100 Scenarios, and a run of 40 is still one run with one run ID and one dashboard URL. Tuner starts the next call as each call ends. A tag or a list of IDs over 100 stops the command with an error.

## Run a suite

Running a suite needs `@usetuner.ai/cli` 0.3.0 or later.

Run a suite by name. To see the names, run `tuner suites list`.

```bash theme={null}
tuner suites list
tuner sim run --suite smoke
```

* The name matches ignoring case.
* The run uses the suite's Scenarios and run settings.
* These flags can't be combined with `--suite`, and the command stops before any call and names the flag: `--tag`, `--scenario`, `--language`, `--profile`, `--noise`, `--noise-intensity`.
* `--meta` works with `--suite`. See [Add run metadata](#add-run-metadata).

`tuner suites list` prints each suite's name and run settings. A suite whose test profile was deleted shows `(deleted)` as its profile.

These problems stop the command before any call, with exit `2`:

| Problem | Fix |
| - | - |
| The suite name is empty, for example from an unset shell variable | Set the variable or pass a name. |
| No suite has that name | Pick a name from `tuner suites list`. |
| The suite has no Scenarios | [Add Scenarios](https://docs.usetuner.ai/docs/simulation/suites.md#add-scenarios-to-a-suite) to the suite in the dashboard. |
| The suite's test profile was deleted | On the suite's page, pick another test profile under **Run settings** and click **Save**. See [Run a suite](https://docs.usetuner.ai/docs/simulation/suites.md#run-a-suite). |

## Set the language, noise and test profile

Each option takes a name. Run the matching `list` command to see the values.

| Option | Takes | List the values |
| - | - | - |
| `--language` | A code such as `en-US`, or the full name such as `English (American)` | `tuner languages list` |
| `--profile` | A [test profile](https://docs.usetuner.ai/docs/simulation/test-profiles.md) name | `tuner profiles list` |
| `--noise` | A background noise slug | `tuner noise list` |
| `--noise-intensity` | `low`, `medium` or `high`, or a gain of `0.5`, `1.0` or `1.5`. Needs `--noise`. | `tuner noise list` |

```bash theme={null}
tuner sim run --tag smoke \
  --language es-MX \
  --profile "Angry User" \
  --noise office \
  --noise-intensity high
```

Quote any name that contains spaces. An unknown name stops the command before any call starts. The error says which input didn't resolve and which `list` command shows the valid values.

## Read the results

Each line starts with the Scenario's verdict. Verdicts the dashboard lists are linked to [Call results](https://docs.usetuner.ai/docs/simulation/run-statuses.md#call-results).

| Verdict | Counted as | In the dashboard |
| - | - | - |
| `passed`, `ran` | passed | **Passed**, or **Ran** when the run had no evals to grade. |
| `failed` | failed | **Failed**. The line lists the failed evals. |
| `not connected` | inconclusive | **Failed**. The call never connected. |
| `setup error` | inconclusive | **Failed**. The line shows the voice provider's reason. See [Troubleshooting](#troubleshooting). |
| `platform error` | inconclusive | **Failed**. Something went wrong on Tuner's side, and the line shows the message. |
| `unreported` | inconclusive | **Unreported**. See [Fix an Unreported run](https://docs.usetuner.ai/docs/simulation/run-statuses.md#fix-an-unreported-run). |
| `analysis failed` | inconclusive | **Analysis failed**. See [Fix Analysis failed](https://docs.usetuner.ai/docs/simulation/run-statuses.md#fix-analysis-failed). |
| `canceled` | canceled | **Canceled**. The run was canceled before the call finished. |
| `pending` | pending | **Pending**. The call hasn't finished. |

## Exit codes

The exit code tells a script what happened.

| Code | Meaning |
| - | - |
| `0` | Every Scenario passed, or the command did what you asked. |
| `1` | The run finished and some Scenarios failed their evals. |
| `2` | Something in your setup needs fixing. The run didn't start, or it couldn't test your agent. |
| `3` | Tuner couldn't finish the run, for example after a timeout or a Tuner error. |
| `130` | You pressed Ctrl-C (SIGINT). The CLI cancels the run before it exits. |
| `143` | The process received SIGTERM. The CLI cancels the run before it exits. |

When a run has more than one outcome, the worst one wins: `1`, then `2`, then `3`, then `0`.

### Exit 1: a Scenario failed

At least one Scenario failed its evals. Open the run to see the failed evals. This includes a run that timed out after Tuner had already reported a failure.

### Exit 2: fix your setup

The message says what to fix. These problems stop the command before it places any call:

* A bad flag or value, such as `--tag` and `--scenario` together, an empty `--tag`, a bad `--timeout`, a bad `--meta` pair, or `--noise-intensity` without `--noise`.
* No API key, or a key Tuner rejects, or a key from a different workspace than `TUNER_WORKSPACE_ID`.
* No agent, or an agent, tag, Scenario, language, noise or test profile Tuner doesn't know.
* A tag with no Scenarios, or a run of more than 100 Scenarios.
* A suite problem listed in [Run a suite](#run-a-suite).
* No credits left, or an agent that isn't set up for simulation.
* An agent that already has a run in progress.

Two problems appear after the run starts:

* The run ends with a `setup error`: your own voice provider account is out of credits or quota.
* The CLI loses access while it follows the run, for example because the key was revoked.

### Exit 3: Tuner couldn't finish

Tuner or the network stopped the run, so run the command again. If a run had started, check it with `tuner runs get`, because it may still be going.

Before the run starts:

* Tuner is unreachable after the CLI's retries, or it returned a server error or rate-limited the requests.
* Tuner couldn't start the run.
* The connection was lost after the start request, so a run may have started. The CLI prints the agent's run in progress, if there is one.

After the run starts:

* A call never connected, a platform error occurred, a call went unreported, or analysis failed.
* `--timeout` ran out.
* The run was canceled outside this command, in the dashboard or with `tuner runs cancel`.
* Tuner stayed unreachable while the CLI followed the run.

An agent that never answered the call also exits `3`, even though the cause may be yours. Check the Scenario's message and the dashboard before you act on the code alone.

To pass a pipeline step when only Tuner failed, accept exit `3`:

```bash theme={null}
tuner sim run --tag smoke || [ $? -eq 3 ]
```

Drop `|| [ $? -eq 3 ]` to fail the step on `3` as well.

## Cancel a run

The CLI cancels the run for you when you stop it or when it runs out of time. You can also cancel a run by ID.

| How the run is canceled | What the CLI does |
| - | - |
| You press Ctrl-C (SIGINT) | Cancels the run once. |
| The process receives SIGTERM | Cancels the run once. |
| `--timeout` runs out | Cancels the run after that duration. |
| You run `tuner runs cancel <run-id>` | Cancels that run and prints the result. |

After a cancel, the CLI waits up to 10 seconds for the run to stop. The exit codes are in [Exit codes](#exit-codes).

A second Ctrl-C or SIGTERM exits at once, and the run may keep going. The CLI prints the `tuner runs get` command to check it.

`--timeout` takes a duration such as `90s`, `30m` or `1h30m`. A bare number counts as seconds.

```bash theme={null}
tuner sim run --tag smoke --timeout 20m
```

### Cancel a run by ID

Use this for a run you started with `--no-wait`, or one a script left behind. It uses the same agent as `tuner sim run`: `--agent`, then `TUNER_AGENT_ID`.

```bash theme={null}
tuner runs cancel 482
```

The command exits `0` and prints one of three results, each followed by the dashboard URL:

| Output | Meaning |
| - | - |
| `Run 482 canceled.` | The run was pending or running, and it's now canceled. |
| `Run 482 is analyzing: its calls are done and analysis continues.` | Every call has ended, so there's nothing to cancel. |
| `Run 482 already finished: status <status>, result <result>.` | The run had already ended. Repeating the command changes nothing. |

A replay run ID returns a not found error. See [Canceled runs](https://docs.usetuner.ai/docs/simulation/run-statuses.md#canceled-runs) for what happens to the calls and to credits.

To cancel a run when a CI job is canceled, see [Cancel and time out](https://docs.usetuner.ai/docs/simulation/ci/other-tools.md#cancel-and-time-out).

## Add run metadata

Pass `--meta key=value` to store metadata with the run. Repeat it for each pair.

```bash theme={null}
tuner sim run --tag smoke --meta commit=abc123 --meta env=staging
```

* The CLI splits each pair at the first `=`, so a value can contain `=`.
* A pair without `=`, an empty key or a repeated key stops the command with exit `2`.
* The run shows its metadata on the **Runs** tab. See [See which commit a run tested](https://docs.usetuner.ai/docs/simulation/run-statuses.md#see-which-commit-a-run-tested).
* The CLI prints one `Metadata:` line on stderr, and `tuner runs get` prints the same line.

The [GitHub Action](https://docs.usetuner.ai/docs/simulation/ci/github-actions#run-metadata) sends `commit`, `branch`, `pr_url` and `repo_url` for you. For other CI tools, see [Send the commit and branch](https://docs.usetuner.ai/docs/simulation/ci/other-tools.md#send-the-commit-and-branch).

## Start a run and check it later

Pass `--no-wait` to print the run ID and dashboard URL, then exit `0` without waiting.

```bash theme={null}
tuner sim run --tag smoke --no-wait
tuner runs get 482
```

`tuner runs get` prints the run's status, result and a line for each Scenario.

## Use the results in scripts

Add `--output json` to print one JSON document to stdout. Everything else goes to stderr:

* Progress, warnings and errors.
* The per-Scenario lines.
* The dashboard URL.

```bash theme={null}
tuner sim run --tag smoke --output json | jq '.summary'
```

```json theme={null}
{
  "total": 3,
  "passed": 2,
  "failed": 1,
  "inconclusive": 0,
  "canceled": 0,
  "pending": 0
}
```

In text output, stdout holds only the Scenario lines and the summary. Color shows only in a terminal, and `NO_COLOR` turns it off.

To branch on the exit code in a shell script:

```bash theme={null}
tuner sim run --tag smoke
status=$?
if [ "$status" -ne 0 ]; then
  echo "Simulation did not pass (exit $status)"
  exit "$status"
fi
```

The document carries `schema_version: 1`. Fields are only added within a version. The CLI package ships the full schema as `schema/run-result.v1.json`.

| Field | Contents |
| - | - |
| `run` | The run's `id`, `status`, `result`, `is_terminal`, `dashboard_url`, `workspace`, `agent`, `config` (`language`, `profile`, `noise`, `noise_intensity`), `started_at`, `completed_at` and `metadata`. A run started by tag also has `tag`. |
| `summary` | The counts from the summary line. |
| `scenarios` | One entry per Scenario: `scenario_id`, `library_scenario_id`, `name`, `verdict`, `failure_category`, `failed_evals` and `call_id`. |
| `reason` | `agent_failed`, `setup_error`, `tuner_error`, `timeout` or `canceled` for a run that started. The error code when nothing ran. `null` when the run passed. |
| `exit_code` | The exit code, one of `0`, `1`, `2`, `3`, `130` or `143`. |
| `error` | `code` and `message`, present only when something went wrong. |

## Commands and options

| Command | What it does |
| - | - |
| `tuner sim run` | Starts a run, waits for it and prints the results. |
| `tuner runs get <run-id>` | Prints a run's status and results. |
| `tuner runs cancel <run-id>` | Cancels a run that's still going. |
| `tuner auth login` | Checks a key and stores it. |
| `tuner auth status` | Shows which key is in use and its workspace. |
| `tuner auth logout` | Deletes the stored key. |
| `tuner agents list` | Lists the workspace's agents, with ID, Agent Remote ID, name and call direction. |
| `tuner scenarios list [--tag <tag>]` | Lists the agent's Scenarios, with ID, name, type and tags. |
| `tuner languages list` | Lists the values `--language` accepts. |
| `tuner noise list` | Lists the values `--noise` accepts, with each environment's intensities. |
| `tuner profiles list` | Lists the agent's test profiles. |
| `tuner suites list` | Lists the agent's suites, with Scenario count and run settings. |

Every `list` command prints a table, or JSON with `--output json`.

These options work on every command:

| Option | Description |
| - | - |
| `--api-key <key>` | Overrides `TUNER_API_KEY` and the stored key. |
| `--base-url <url>` | Overrides `TUNER_BASE_URL`. |
| `--verbose` | Prints requests and timings to stderr. |
| `-V`, `--version` | Prints the version. |

These options apply to `tuner sim run`:

| Option | Default | Description |
| - | - | - |
| `--tag <tag>` | None | Runs the agent's Scenarios with this tag. Pass exactly one of `--tag`, `--scenario` or `--suite`. |
| `--scenario <id>` | None | Runs this Scenario ID. Repeat it or separate IDs with commas. Pass exactly one of `--tag`, `--scenario` or `--suite`. |
| `--suite <name>` | None | Runs this suite with its Scenarios and run settings. Pass exactly one of `--tag`, `--scenario` or `--suite`. Can't be combined with `--language`, `--profile`, `--noise` or `--noise-intensity`. |
| `--agent <id>` | `TUNER_AGENT_ID` | The agent to run against. Required unless `TUNER_AGENT_ID` is set. |
| `--language <language>` | The agent's language | A language code or full name. |
| `--profile <name>` | None | A test profile name. |
| `--noise <slug>` | None | A background noise slug. |
| `--noise-intensity <level>` | `medium` | `low`, `medium` or `high`, or `0.5`, `1.0` or `1.5`. |
| `--output <format>` | `text` | `text` or `json`. |
| `--meta <key=value>` | None | Stores metadata with the run. Repeat it for several pairs. |
| `--no-wait` | Off | Prints the run ID and exits without waiting. |
| `--timeout <duration>` | `60m` | Cancels the run after this long. |
| `--fail-on-inconclusive` | Off | Deprecated. Has no effect and prints a warning. Inconclusive and timed-out runs exit `3`. |

These commands also need an agent, from `--agent` or `TUNER_AGENT_ID`: `tuner runs get`, `tuner runs cancel`, `tuner scenarios list`, `tuner profiles list` and `tuner suites list`.

`tuner sim run`, `tuner runs get`, `tuner runs cancel` and every `list` command take `--output`.

## Troubleshooting

> [accordion] No API key
>
> The CLI found no key in `--api-key`, `TUNER_API_KEY` or the stored credentials. Set `TUNER_API_KEY`, or run `tuner auth login`.

> [accordion] No agent
>
> The CLI found no agent. Pass `--agent <agent-remote-id>` or set `TUNER_AGENT_ID`. Run `tuner agents list` to see the agents in the workspace.

> [accordion] Agent not found in this workspace
>
> The key and the agent belong to different workspaces. Run `tuner auth status` to see the key's workspace, then check the Agent Remote ID in [API keys and IDs](https://docs.usetuner.ai/docs/getting-started/api-keys.md#find-your-agent-remote-id).

> [accordion] TUNER\_WORKSPACE\_ID doesn't match the key
>
> The CLI stops when `TUNER_WORKSPACE_ID` names a different workspace than the key. Fix the variable, or use a key from that workspace.

> [accordion] The agent already has a run in progress
>
> The CLI prints the run ID and its dashboard URL. Wait for that run to finish, or cancel it with `tuner runs cancel <run-id>`. See [Cancel a run](#cancel-a-run).

> [accordion] The run couldn't test your agent (setup\_error)
>
> Your voice provider account, for example Retell or ElevenLabs, is out of credits or over its quota. Each affected Scenario shows `setup error` and the provider's reason. Top up or raise the limit with your provider, then run the Scenarios again.

> [accordion] Tuner unavailable, retrying
>
> The CLI retries requests that fail on Tuner's side or on the network, with growing waits. See [Exit codes](#exit-codes) and [Limits](#limits).

## Limits

| Limit | Value |
| - | - |
| Scenarios per run | Up to 100 |
| Calls in progress at once | 10 |
| Default `--timeout` | 60 minutes |
| Retry window for an unreachable Tuner during `tuner sim run` | 5 minutes |
| Retry window for other commands | 30 seconds |
| Wait for a canceled run to stop | 10 seconds |

The CLI uses the public API. To start and read runs from your own code, see the **Simulation** group of the API Reference.

## Next steps

> [card] [Run statuses](https://docs.usetuner.ai/docs/simulation/run-statuses.md)
>
> What each run status and call result means, and how to fix runs that don't complete.

> [card] [GitHub Actions](https://docs.usetuner.ai/docs/simulation/ci/github-actions)
>
> Run the CLI on every pull request or merge, with a check, a comment and a job summary.


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