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

# LangSmith CLI

> Query and manage agent traces, runs, datasets, evaluators, experiments, insights, and threads from the terminal or a coding agent

The LangSmith CLI is a command-line tool for querying and managing your LangSmith data. It's designed for both developers and AI coding agents and outputs human-readable tables by default, with a `--format json` option for scripting. Use it when you need scriptable access to your LangSmith data, such as bulk exports, automation, or giving a coding agent direct access to your [traces, runs, and datasets](https://docs.langchain.com/langsmith/observability-concepts.md).

## Install

```bash macOS / Linux (recommended) theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
curl -fsSL https://cli.langsmith.com/install.sh | sh
```

```powershell Windows theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
irm https://cli.langsmith.com/install.ps1 | iex
```

```bash Homebrew theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
brew install langchain-ai/tap/langsmith-cli
```

```powershell Scoop theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
scoop install langsmith-cli
```

```bash GitHub Releases theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
# Download the latest binary for your platform:
# https://github.com/langchain-ai/langsmith-cli/releases
```

```bash PyPI theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
# As a standalone tool
uv tool install langchain-langsmith-cli
pipx install langchain-langsmith-cli

# Into the current Python environment
pip install langchain-langsmith-cli
```

```bash Go install theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
go install github.com/langchain-ai/langsmith-cli/cmd/langsmith@latest
```

The PyPI package, `langchain-langsmith-cli`, ships the same prebuilt binary as the other install methods, with one wheel per platform. It installs through any PyPI proxy, such as a JFrog Artifactory PyPI remote repository or a Nexus PyPI proxy, so you can install it where only an internal package index is reachable.

> [!WARNING]
>
> `pip install langsmith-cli` installs a different, third-party package. Install `langchain-langsmith-cli` instead.

To upgrade at any time:

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
langsmith self-update
```

Use the `--dry-run` flag to preview the update without installing.

`self-update` replaces the binary in place for installs from the install script or GitHub Releases. If a package manager installed the CLI, `self-update` leaves the binary alone and prints the command to run instead:

| Installed with | Upgrade command |
| - | - |
| Homebrew | `brew upgrade langchain-ai/tap/langsmith-cli` |
| Scoop | `scoop update langsmith-cli` |
| `uv tool install` | `uv tool upgrade langchain-langsmith-cli` |
| `pipx install` | `pipx upgrade langchain-langsmith-cli` |
| `pip install` | `python -m pip install --upgrade langchain-langsmith-cli`, with the Python of the environment the CLI is installed in |
| `uv pip install` | `uv pip install --python <python> --upgrade langchain-langsmith-cli` |
| `uv add` (uv project) | `uv lock --upgrade-package langchain-langsmith-cli && uv sync`, run in the project |
| `go install` | `go install github.com/langchain-ai/langsmith-cli/cmd/langsmith@latest` |

To replace the binary in place anyway, pass `--force`.

> [!NOTE]
>
> Querying a [SmithDB](https://docs.langchain.com/langsmith/smithdb-sdk-migration.md)-backed deployment requires LangSmith CLI `v0.2.44` or later.

## Authenticate

The CLI selects an agent environment through `--project` or `LANGSMITH_PROJECT`. [Retrieve that environment's `tracer_session_name`](https://docs.langchain.com/langsmith/create-an-agent#use-an-environment-project) and use it for these options. Commands named `project`, such as `project list`, work with the [trace storage](https://docs.langchain.com/langsmith/observability-concepts.md#agents-and-environments) behind each agent environment, not with agents.

`langsmith auth login` requires LangSmith CLI `v0.2.30` or later. `langsmith profile` commands require LangSmith CLI `v0.2.26` or later.

The recommended local setup is to authenticate with OAuth:

> [!NOTE]
>
> `langsmith auth login` also works against self-hosted instances from LangSmith CLI `v0.2.46` and newer, provided the deployment is on LangSmith `0.16` or later with the OAuth authorization server enabled (requires a signing JWKS to be configured). See [Self-hosted instances](#self-hosted-instances). On earlier deployments, or without a signing JWKS, authenticate with an API key or create an API-key profile.

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
langsmith auth login
```

This opens a browser-based authorization flow and stores OAuth tokens in `~/.langsmith/config.json` under the selected [profile](https://docs.langchain.com/langsmith/profile-configuration.md). Select a profile with `--profile` or `LANGSMITH_PROFILE`:

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
langsmith auth login --profile dev
langsmith --profile dev project list
```

In headless environments, pass `--no-browser` and open the printed URL manually:

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
langsmith auth login --no-browser --workspace-id <workspace-id>
```

To manage saved profiles:

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
langsmith profile list
langsmith profile create dev --workspace-id <workspace-id> --set-current
langsmith profile use dev
langsmith profile set-workspace <workspace-id>
```

For the full profile configuration reference, see [Profile configuration](https://docs.langchain.com/langsmith/profile-configuration.md).

You can also authenticate with an API key directly.

Set your [API key](https://docs.langchain.com/langsmith/create-account-api-key.md) as an environment variable:

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
export LANGSMITH_API_KEY="lsv2_..."
```

Optionally, set the agent environment to query by default using its `tracer_session_name`:

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
export LANGSMITH_PROJECT="<environment-tracer-session-name>"
```

If you're using LangSmith [self-hosted](https://docs.langchain.com/langsmith/self-hosted.md), also set the endpoint:

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
export LANGSMITH_ENDPOINT="https://your-langsmith-instance.com"
```

Or, pass them as flags per command:

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
langsmith --api-key lsv2_... trace list --project "<environment-tracer-session-name>"
```

### Self-hosted instances

Point the CLI at your instance with `--api-url`, or with `LANGSMITH_ENDPOINT`. Both the browser-based login and API keys are supported.

> [tab] OAuth
>
> Requires LangSmith CLI `v0.2.46` or later and a deployment on LangSmith `0.16` or later, with the OAuth authorization server enabled. The chart exposes the OAuth authorization server under `/api`, but those endpoints stay inert until you [configure a signing JWKS](https://docs.langchain.com/langsmith/kubernetes.md#configure-a-signing-jwks).
>
> The OAuth authorization server is enabled automatically when `config.hostname` is set in your Helm chart **and** a signing JWKS is configured (via `config.signingJwks`, or the key `langsmith_signing_jwks` in `config.existingSecretName`). Without the signing JWKS, the OAuth endpoints are inactive and the CLI will receive a `404` — use the API key tab instead.
>
> ```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
> langsmith auth login --api-url https://langsmith.example.com --profile self-hosted
> ```
>
> Pass your instance's base URL. The CLI reads the deployment's authorization server metadata to find the OAuth endpoints, so `https://langsmith.example.com` and `https://langsmith.example.com/api` both work.
>
> Tokens are stored under the named profile, so later commands only need `--profile`:
>
> ```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
> langsmith --profile self-hosted project list
> ```

> [tab] API key
>
> Works on every LangSmith version.
>
> ```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
> export LANGSMITH_ENDPOINT="https://langsmith.example.com"
> export LANGSMITH_API_KEY="lsv2_..."
>
> langsmith project list
> ```
>
> To save the endpoint and key as a reusable profile instead:
>
> ```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
> LANGSMITH_API_KEY="lsv2_..." langsmith profile create self-hosted \
>   --api-url https://langsmith.example.com --set-current
> ```

> [!WARNING]
>
> `LANGSMITH_ENDPOINT` takes precedence over a profile's `api_url`. If it is set in your shell, every profile you select resolves to that endpoint — a common cause of commands unexpectedly reaching LangSmith Cloud while a self-hosted profile is active. Unset it when working with profiles, or pass `--api-url` explicitly.

## Set up coding agents

`langsmith setup` gives Claude Code, Cursor, and Codex the LangSmith [skills](https://docs.langchain.com/langsmith/skills.md) and the hosted [LangSmith MCP server](https://docs.langchain.com/langsmith/langsmith-remote-mcp.md). It detects the agents installed on your machine, shows what it will change, and asks before writing. Running it again changes nothing that is already set up.

> [!NOTE]
>
> `langsmith setup` requires LangSmith CLI `v0.5.0` or later. From `v0.6.0`, it installs the [`langchain-skills`](https://github.com/langchain-ai/langchain-skills) plugin and replaces skills it installed earlier from the deprecated `langsmith-skills` package.

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
langsmith setup                        # detect agents, preview, confirm
langsmith setup --dry-run              # show the plan only
langsmith setup --agent cursor --yes   # one agent, no prompt
langsmith setup --no-skills            # MCP server only (or --no-mcp for skills only)
```

| Agent | Skills | MCP server |
| - | - | - |
| Claude Code | `langchain-skills` plugin | `langsmith`, user scope |
| Cursor | `~/.cursor/skills/<skill>` | `langsmith` in `~/.cursor/mcp.json` |
| Codex | `~/.codex/skills/<skill>` | `[mcp_servers.langsmith]` in `~/.codex/config.toml` |

No API key is written: each agent signs in to the MCP server with OAuth. `setup` never replaces an MCP entry named `langsmith` or a skill directory it didn't write unless you pass `--force`.

## Quickstart

The following commands cover the core resource types:

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
# List tracing projects
langsmith project list

# List recent traces in a project
langsmith trace list --project "<environment-tracer-session-name>" --limit 5

# Get a specific trace with full detail
langsmith trace get <trace-id> --project "<environment-tracer-session-name>" --full

# List LLM runs with token counts
langsmith run list --project "<environment-tracer-session-name>" --run-type llm --include-metadata

# Datasets and experiments
langsmith dataset list
langsmith experiment list --dataset my-eval-set

# Conversation threads
langsmith thread list --project "<environment-tracer-session-name>"

# Find what broke, then check that a fix worked
langsmith investigate --project "<environment-tracer-session-name>"
langsmith verify --project "<environment-tracer-session-name>" --since 2026-11-30T14:00:00Z

# Turn a failing run into an example, run an experiment, and compare it with a baseline
langsmith example create --dataset regressions --from-run <run-id>
langsmith experiment run --dataset regressions --name candidate -- python app.py
langsmith experiment compare baseline candidate

# Sandboxes
langsmith sandbox list
langsmith sandbox tunnel my-vm --remote-port 5432
```

## Search with AI

[AI search](https://docs.langchain.com/langsmith/filter-traces.md#search-with-ai) finds runs, traces, and threads from a plain-language description, which LangSmith turns into filters, time bounds, and conditions on the conversation. Use `--ai-search` on the streaming query commands to search from the terminal.

> [!NOTE]
>
> These commands require LangSmith CLI v0.3.9 or later and an organization admin to [enable AI search](https://docs.langchain.com/langsmith/filter-traces.md#enable-ai-search). The same data-handling and PHI restrictions apply as in the UI. For release stage and availability, see [Search with AI](https://docs.langchain.com/langsmith/filter-traces.md#search-with-ai). The commands require `--project-id` and do not resolve `--project` names.

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
langsmith threads streaming query --project-id <project-id> --ai-search "threads with more than 5 turns where the user got confused"
langsmith traces streaming query --project-id <project-id> --ai-search "traces where the agent didn't complete the task"
langsmith runs streaming query-v2 --project-id <project-id> --ai-search "llm calls that errored in the last 2 days" --max-items 20
```

Each server-sent event prints as a JSON patch, and `--max-items` counts events, not matched runs, traces, or threads.

Pass a nonempty description of at most 2,000 UTF-8 bytes, and put structured conditions in the description itself. Combining `--ai-search` with `--filter`, `--trace-filter`, `--tree-filter`, or `--thread-filter` returns HTTP `400`. A time period in the description replaces `--min-start-time` and `--max-start-time`.

The non-streaming `traces query` and `threads query` commands also accept `--ai-search`, but the server rejects those requests with HTTP `406` because AI search requires streaming. Ordinary list commands do not support AI search.

## Output formats

**Default**

Human-readable tables:

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
langsmith trace list --project "<environment-tracer-session-name>"
```

**JSON**

`--format json` to pipe, script, or feed output to an agent. From `v0.6.0`, `--json` is a shorthand for `--format json`:

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
langsmith --format json trace list --project "<environment-tracer-session-name>"
langsmith trace list --project "<environment-tracer-session-name>" --json
```

To filter JSON output without installing `jq`, pass a jq expression with `--jq`, which implies `--format json`:

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
langsmith trace list --project "<environment-tracer-session-name>" --jq '.[].trace_id'
```

**Write to file**

`-o <path>`:

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
langsmith trace list --project "<environment-tracer-session-name>" -o traces.json
```

Stdout carries only the result. From `v0.6.0`, notes about it go to stderr: the profile and workspace in use when you have more than one profile, a list that stopped at `--limit` while more items match, and a run or trace list that searched only the default 7-day window. With `--format json` or `--jq`, each note is a JSON object with a `notice` field.

> [!NOTE]
>
> Today, output that is piped or redirected stays human-readable, and the CLI warns on stderr. From `v1.0.0`, piped or redirected output defaults to JSON. Pass `--format` explicitly in scripts to keep the same output across the change.

## Use the CLI from scripts and agents

The CLI never waits on a prompt that a script or agent can't answer, and its errors say how to fix them.

* **Destructive commands need `--yes`.** Commands that delete or overwrite data ask for confirmation in a terminal. Without a terminal, pass `--yes`. From `v0.6.0` until `v1.0.0`, a run without a terminal and without `--yes` goes ahead with a deprecation warning only if the command never prompted before or stdin supplies `y`; otherwise it refuses. From `v1.0.0`, it always refuses. An agent should confirm with the user, then rerun with `--yes`.
* **Retry-safe creates.** From `v0.6.0`, `dataset create`, `prompt create`, and `agents create` accept `--if-not-exists`, which returns the existing resource instead of failing when it already exists.
* **Errors name the fix.** From `v0.6.0`, unknown subcommands fail with a suggestion, and not-found, workspace, and permission errors name the command to run next, such as `langsmith workspaces list`.
* **Exit codes.** Every failure exits `1` until `v1.0.0`. From `v0.6.0`, set `LANGSMITH_EXIT_CODES=detailed` to use the detailed codes now:

| Code | Meaning |
| - | - |
| `1` | Bad input |
| `2` | Authentication |
| `3` | Not found |
| `4` | Conflict or plan limit |
| `5` | `--wait` timed out |
| `6` | Server error or unreachable |
| `7` | Rate limited |

`langsmith docs agents` prints a task-oriented command reference for coding agents, generated from the installed version of the CLI.

## Commands

Each command group targets a specific LangSmith resource. Most commands support `--limit`, `--offset`, and a shared set of [filter flags](#filter-flags).

### List trace-storage destinations

The legacy `project list` command lists the backing trace-storage destinations, including those associated with agent environments. It returns up to 20 by default, sorted by most recent activity. Use [`experiment list`](#view-experiments) to list evaluation experiments.

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
langsmith project list
langsmith project list --limit 50 --name-contains chatbot
langsmith --format json project list
```

### Query traces

Defaults to the last 7 days, newest first. Use `--since` or `--last-n-minutes` to change the time window.

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
langsmith trace list --project "<environment-tracer-session-name>" --limit 50 --last-n-minutes 60
langsmith trace list --project "<environment-tracer-session-name>" --error                     # errors only
langsmith trace list --project "<environment-tracer-session-name>" --min-latency 5             # slow traces (>5s)
langsmith trace list --project "<environment-tracer-session-name>" --tags production           # filter by tag
langsmith trace list --project "<environment-tracer-session-name>" --full                      # all fields
langsmith trace list --project "<environment-tracer-session-name>" --show-hierarchy --limit 3  # include full run tree
langsmith trace get <trace-id> --project "<environment-tracer-session-name>" --full
langsmith trace export ./traces --project "<environment-tracer-session-name>" --limit 20 --full
```

### Query runs

Defaults to 50 results (most other commands default to 20). The same 7-day time window applies. Use `--since` or `--last-n-minutes` to override.

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
langsmith run list --project "<environment-tracer-session-name>" --run-type llm
langsmith run list --project "<environment-tracer-session-name>" --run-type tool --name search
langsmith run list --project "<environment-tracer-session-name>" --min-tokens 1000 --include-metadata
langsmith run get <run-id> --full
langsmith run export llm_calls.jsonl --project "<environment-tracer-session-name>" --run-type llm --full
```

### Query threads

`--project` is required for all thread commands.

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
langsmith thread list --project "<environment-tracer-session-name>" --last-n-minutes 120
langsmith thread get <thread-id> --project "<environment-tracer-session-name>" --full
```

### Investigate failures and verify fixes

> [!NOTE]
>
> Requires LangSmith CLI `v0.5.0` or later.

`investigate` and `verify` each run a fixed set of reads and return one compact report, so an agent makes one call instead of chaining list and stats commands. With `--format json`, the suggested follow-up commands are in `.next`.

`investigate` compares a window (default: the last 24 hours) with a baseline just before it (`--baseline`, default `7d`): trace count, error rate, p50 and p99 latency, and cost. It groups the newest failed runs by step and error, marks each group as new or ongoing, and lists evidence trace IDs and related open issues.

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
langsmith investigate --project "<environment-tracer-session-name>"
langsmith investigate --project "<environment-tracer-session-name>" --last-n-minutes 60 --baseline 24h --format json
```

`verify` checks that failures stopped after a fix. Pass `--since` with the time the fix went live, and narrow the target failures with `--match`. Each target is reported as `fixed`, `still_failing`, `inconclusive` (too few runs to tell), or `no_traffic`, and errors that appear only after the fix are listed as `new_failures`.

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
langsmith verify --project "<environment-tracer-session-name>" --since 2026-11-30T14:00:00Z --match RateLimitError
```

### Manage datasets

`dataset export` exports the examples (rows) within a dataset, not the dataset metadata itself.

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
langsmith dataset list
langsmith dataset list --name-contains eval
langsmith dataset get my-dataset
langsmith dataset create --name my-eval-set --description "QA pairs for v2"
langsmith dataset create --name my-eval-set --if-not-exists   # v0.6.0+: returns the dataset if it exists
langsmith dataset delete my-old-dataset --yes
langsmith dataset export my-dataset ./data.json --limit 500
langsmith dataset upload data.json --name new-dataset
```

### Manage examples

Use `--split` to assign examples to named splits (such as `test` or `train`) when creating or listing.

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
langsmith example list --dataset my-dataset --limit 50
langsmith example list --dataset my-dataset --split test
langsmith example create --dataset my-dataset \
  --inputs '{"question": "What is LangSmith?"}' \
  --outputs '{"answer": "A platform for LLM observability"}' \
  --split test
langsmith example delete <example-id> --yes
```

From `v0.6.0`, `--from-run` turns runs into examples. Each example copies the run's inputs, outputs, and attachments and keeps the run as its source. `--from-run` is repeatable, `--from-run -` reads run IDs from stdin, and `--skip-duplicates` skips runs whose inputs already match an example in the dataset. For chat and LLM datasets, the server converts each run to the dataset's format.

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
langsmith example create --dataset regressions --from-run <run-id> --skip-duplicates
langsmith run list --project "<environment-tracer-session-name>" --error --jq '.[].run_id' \
  | langsmith example create --dataset regressions --from-run - --skip-duplicates
```

### Manage evaluators

Evaluators can be offline (run against a dataset during experiments) or online (run against an agent environment). Use `--sampling-rate` to evaluate only a fraction of production runs, and `--replace` to overwrite an existing evaluator by name.

From `v0.6.0`, `evaluator upload` sends the whole file unchanged, so imports and helpers are kept. The file must define `perform_eval` (Python) or `performEval` (JavaScript or TypeScript). Earlier versions require `--function`.

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
langsmith evaluator list
langsmith evaluator upload evals.py --name accuracy --dataset my-eval-set
langsmith evaluator upload evals.py --name latency-check \
  --project "<environment-tracer-session-name>" --sampling-rate 0.5
langsmith evaluator upload evals.py --name accuracy --dataset my-eval-set --replace --yes
langsmith evaluator delete <evaluator-id> --delete-rules --yes
```

> [!WARNING]
>
> From `v0.6.0`, `--function`, which uploads a single function renamed to `perform_eval`, is deprecated, and it will be removed in `v1.0.0`. Define `perform_eval` or `performEval` in the file instead.

### Run and compare experiments

`experiment list` shows evaluation experiments. Use [`project list`](#list-projects) for the trace-storage destinations associated with agent environments.

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
langsmith experiment list
langsmith experiment list --dataset my-eval-set
langsmith experiment get my-experiment-2024-01-15
```

> [!NOTE]
>
> `experiment run` and `experiment compare` require LangSmith CLI `v0.6.0` or later.

`experiment run` runs your app over every example in a dataset and records the results as an experiment. The command after `--` runs once per example, outside a shell. It reads the example's inputs as a JSON object on stdin, gets `LANGSMITH_EXAMPLE_ID` and `LANGSMITH_RUN_ID` in its environment, and must print its outputs as one JSON value on stdout. A non-zero exit, a timeout (`--timeout`, default 5 minutes), or output that isn't JSON records that example with an error, and the other examples still run.

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
langsmith experiment run --dataset my-eval-set --name baseline -- python app.py
langsmith experiment run --dataset my-eval-set --name candidate --metadata model=gpt-5 --concurrency 8 -- python app.py
langsmith experiment run --dataset my-eval-set --split test --evaluator correctness -- node app.js
```

The dataset's evaluators score the runs asynchronously, the same way they score experiments run with the SDK, so check scores later with `experiment get`. `--evaluator` limits scoring to the named evaluator rules. The command exits non-zero only when the experiment can't be created, recorded, or closed. Examples whose command failed are counted in `error_count`.

`experiment compare` compares a candidate experiment with a baseline on the same dataset. It reports each feedback score, total cost, p50 and p99 latency, total tokens, and error rate for both experiments and the change, and lists the examples that got worse: `pass_to_fail`, `score_drop`, or `new_error`. Higher scores are treated as better. `--limit` caps the listed examples (default 20); `regression_count` is always the full count.

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
langsmith experiment compare baseline candidate
langsmith experiment compare baseline candidate --jq '.feedback.correctness.delta'
```

### Manage insights

`insights` commands create, run, and read [Insights](https://docs.langchain.com/langsmith/insights.md) configurations and their jobs, which group an agent environment's traces into categories that show usage patterns and where the agent fails. Select the environment with `--project` or `LANGSMITH_PROJECT`, set to its [`tracer_session_name`](https://docs.langchain.com/langsmith/create-an-agent#use-an-environment-project), or with `--project-id`, set to its [`session_id`](https://docs.langchain.com/langsmith/resolve-an-agent).

On LangSmith Cloud, and on self-hosted installations that [run continuous Insights](https://docs.langchain.com/langsmith/self-host-insights-chat.md#check-whether-insights-runs-continuously), a configuration is an insight that categorizes new traces as they arrive. Each job builds or refreshes its categories. On other self-hosted installations, each job produces a [batch report](https://docs.langchain.com/langsmith/insights-batch-reports.md).

> [!NOTE]
>
> `insights create`, `insights run`, and `insights config` require LangSmith CLI v0.2.60 or later.

To create an insight or a batch report, define it in a JSON file:

```json theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
{
  "name": "Weekly reliability review",
  "summary_prompt": "Identify the request and outcome: {{run.inputs}} {{run.outputs}}",
  "last_n_hours": 168,
  "filter": "eq(is_root, true)",
  "model": "openai",
  "schedule_cron": "0 9 * * 1"
}
```

* **`name`** and **`summary_prompt`**: Required. The [summary prompt](https://docs.langchain.com/langsmith/insights-batch-reports.md#summary-prompt) is a Mustache template and must reference at least one of `{{run.inputs}}`, `{{run.outputs}}`, `{{run.error}}`, `{{run.feedback}}`, or `{{all_thread_messages}}`. The CLI does not support auto mode, so state what Insights should look for in this prompt.
* **`last_n_hours`**, or **`start_time`** and **`end_time`**: The time range to sample traces from. Use one form, not both.
* **`model`**: `openai` (default) or `anthropic`. To pick specific models, set **`cluster_model`** and **`summary_model`** together, each to `openai`, `anthropic`, or a [model configuration](https://docs.langchain.com/langsmith/model-configurations.md) UUID. Display names are not accepted.
* **`schedule_cron`**: A cron expression for a recurring batch report. The first job starts immediately, and later jobs follow the schedule. Omit it for a one-time report. With continuous Insights, scheduled jobs do not run.

The file also accepts `filter`, `sample`, `hierarchy`, `partitions`, `attribute_schemas`, and `description`. Unknown fields cause an error.

`insights create` saves the file as a job configuration and starts its first job. Jobs run asynchronously and incur model costs. With continuous Insights, the insight also incurs model costs for each conversation it categorizes. The workspace needs secrets for the selected models. Pass `--wait` to poll until the job succeeds or fails, for up to 30 minutes. Pass `--config -` to read the file from stdin.

With continuous Insights, the insight chooses its own [sampling rate](https://docs.langchain.com/langsmith/insights.md#choose-runs). The CLI cannot set the rate or Slack updates. Use the UI instead.

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
langsmith insights create --project "<environment-tracer-session-name>" --config insights.json
langsmith insights create --project "<environment-tracer-session-name>" --config insights.json --wait
```

`insights run` starts a new job from a saved configuration without changing the configuration. With continuous Insights, the job refreshes the insight's categories:

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
langsmith insights config list --project "<environment-tracer-session-name>"
langsmith insights config list --project "<environment-tracer-session-name>" --include-prebuilt
langsmith insights run <config-id> --project "<environment-tracer-session-name>" --wait
```

`insights list` returns jobs with their status and category counts. `insights get` adds the executive summary, highlighted traces, and per-category statistics:

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
langsmith insights list --project "<environment-tracer-session-name>" --limit 5
langsmith insights get <insight-id> --project "<environment-tracer-session-name>"
```

`insights config update` replaces a configuration's name and analysis settings from a JSON file in the same format. It does not start a job. With continuous Insights, the insight applies the new settings to conversations it analyzes from then on. Omit `description` or `schedule_cron` to keep the current value, or set `schedule_cron` to `null` to stop the schedule. `insights config delete` removes the configuration and every job it produced. With continuous Insights, it also stops categorizing new traces.

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
langsmith insights config update <config-id> --project "<environment-tracer-session-name>" --config insights.json
langsmith insights config delete <config-id> --project "<environment-tracer-session-name>" --yes
```

### Manage sandboxes

Sandbox commands let you build snapshots, create sandboxes, execute commands, open interactive consoles, and tunnel TCP ports to services running inside sandboxes.

See [Sandbox CLI](https://docs.langchain.com/langsmith/sandbox-cli.md) for the full sandbox command reference.

### Trace an MCP server

> [!NOTE]
>
> Requires LangSmith CLI `v0.6.0` or later.

`langsmith mcp proxy` traces each tool call an MCP server handles, with no changes to the server. Register the proxy with your agent in place of the server. The agent talks to the proxy over stdio, and the proxy starts the server, or forwards to a remote server with `--url`, and passes MCP messages through unchanged. Each `tools/call` becomes a tool run with its arguments and result in `--project` (default: `LANGSMITH_PROJECT`, then `default`).

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
claude mcp add everything -- langsmith mcp proxy --project my-mcp -- npx -y @modelcontextprotocol/server-everything
langsmith mcp proxy --project my-mcp --url https://mcp.example.com/mcp --header "Authorization: Bearer $TOKEN"
```

`--header` values go only to `--url`, never to LangSmith, and LangSmith credentials never go to `--url`. `--url` must use HTTPS unless the host is `localhost`, and redirects to another host are refused. Tracing never blocks the server: without LangSmith credentials, the proxy warns on stderr and runs the server untraced.

> [!WARNING]
>
> `--header` values are command-line arguments, so other users on a shared machine can see them in the process list while the proxy runs. Avoid passing long-lived credentials this way on shared hosts.

### Manage custom apps

`langsmith apps` commands scaffold, run locally, and publish [custom apps](https://docs.langchain.com/langsmith/custom-apps.md), UIs that run inside LangSmith and call the LangSmith API.

See [CLI reference](https://docs.langchain.com/langsmith/custom-apps.md#cli-reference) for the full command list.

### Hash a recovery password

> [!NOTE]
>
> Requires LangSmith CLI `v0.5.1` or later.

Generate a password hash for self-hosted [recovery admin login](https://docs.langchain.com/langsmith/self-host-sso-recovery.md), entirely offline:

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
langsmith auth hash-password
```

This prompts for the password and a confirmation, without echoing either to the terminal, and prints a PBKDF2-SHA256 hash in the form `pbkdf2_sha256$<iterations>$<salt>$<hash>`. No login or API key is required.

For scripted use, pipe the password on stdin instead:

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
echo -n "$RECOVERY_PASSWORD" | langsmith auth hash-password --password-stdin
```

### Call the LangSmith API directly

The `api` command is an authenticated, scriptable wrapper around the raw LangSmith REST API — useful for endpoints the typed commands above don't cover, or for piping JSON into and out of shell scripts. It's modeled after `gh api` and `curl`: pass the path as the only positional argument, and use `-X` to set the HTTP method (defaults to `GET`). Auth headers (`x-api-key`, `x-tenant-id`) are injected automatically.

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
# GET (default method) — query string supported in the path
langsmith api sessions?limit=5

# Discover endpoints from the OpenAPI spec
langsmith api ls --tag datasets
langsmith api info GET sessions

# Typed JSON fields with -F (numbers, booleans, null, objects, arrays parsed as JSON)
# Method auto-promotes to POST when -F/-f/--input/--body is supplied
langsmith api runs/query -F session_id=abc -F limit=10

# String-typed fields with -f (always sent as a JSON string, even if numeric)
langsmith api datasets -f name=my-dataset -f description="QA pairs"

# Other HTTP methods via -X
langsmith api sessions/abc-123 -X DELETE

# Send a request body from a file or stdin
langsmith api datasets --input create-dataset.json
echo '{"name":"test"}' | langsmith api sessions --input -

# Force GET with fields — fields go to the query string instead of a body
langsmith api runs -X GET -F limit=5 -F session=abc

# Inspect response status + headers
langsmith api sessions --include

# Add custom headers
langsmith api sessions -H "Accept: text/csv"
```

Key flags:

| Flag | Short | Default | Description |
| - | - | - | - |
| `--method` | `-X` | `GET` | HTTP method |
| `--field` | `-F` | — | Typed JSON field as `key=value`. Repeatable. Use `@<path>` or `@-` for file/stdin values. |
| `--raw-field` | `-f` | — | String JSON field as `key=value`. Repeatable. |
| `--input` | — | — | File to use as the request body (`-` for stdin) |
| `--body` | — | — | Raw request body (JSON string, `@file`, or `@-` for stdin) |
| `--header` | `-H` | — | Additional headers as `Key:Value`. Repeatable. |
| `--include` | `-i` | `false` | Print response status line and headers before body |

`--input` and `--body` are mutually exclusive. Subcommands `langsmith api ls` and `langsmith api info` browse and describe endpoints from the cached OpenAPI spec — pass `--refresh` to re-fetch.

## Filter flags

Most `trace` and `run` commands share these filters:

| Flag | Description | Example |
| - | - | - |
| `--project` | Agent environment's `tracer_session_name` | `--project "<environment-tracer-session-name>"` |
| `--limit, -n` | Max results | `-n 10` |
| `--offset` | Pagination offset | `--offset 20` |
| `--last-n-minutes` | Override the 7-day default | `--last-n-minutes 60` |
| `--since` | After ISO timestamp | `--since 2024-01-15T00:00:00Z` |
| `--error` / `--no-error` | Filter by error status | `--error` |
| `--name` | Name search (case-insensitive) | `--name ChatOpenAI` |
| `--run-type` | Run type (`llm` or `tool`) | `--run-type llm` |
| `--min-latency` / `--max-latency` | Latency range in seconds | `--min-latency 2.5` |
| `--min-tokens` | Minimum total tokens | `--min-tokens 1000` |
| `--tags` | Tags, comma-separated (OR logic) | `--tags prod,v2` |
| `--filter` | Raw LangSmith filter DSL | `--filter 'eq(status, "error")'` |
| `--trace-ids` | Specific trace IDs | `--trace-ids abc123,def456` |

**Detail flags** — control which fields are included in the response:

| Flag | Adds |
| - | - |
| `--include-metadata` | Status, duration, tokens, costs |
| `--include-io` | Inputs, outputs, error |
| `--include-feedback` | Feedback stats |
| `--full` | All of the above |
| `--show-hierarchy` | Full run tree (traces only) |

***

[Connect these docs](https://docs.langchain.com/use-these-docs.md) to your agent of choice via MCP for real-time answers.

[Edit this page on GitHub](https://github.com/langchain-ai/docs/edit/main/src/langsmith/langsmith-cli.mdx) or [file an issue](https://github.com/langchain-ai/docs/issues/new/choose).
