LeveredDocs
CLI

Commands

Reference for the CLI commands.

Most commands that read or create data support --json for structured output. The usage line of each command shows whether it takes --json. Use levered <command> --help for inline documentation on any command.


Authentication

Manage your session and credentials.

CommandDescription
levered login [--api-url URL]Authenticate via browser OAuth. --api-url sets the API URL and saves it to ~/.levered/config.json before signing in.
levered logoutClear stored session tokens for the current environment.
levered whoamiPrint the email, user ID, and active organization of the signed-in user.
levered org list [--json]List the organizations you belong to. * marks the active one.
levered org switch [<name|slug|id>]Switch the active organization. Without an argument, pick from a numbered list. Opens the browser to re-issue the session token for that organization; in the same browser session, the dashboard switches too.

Configuration

Read and write CLI settings stored in ~/.levered/config.json.

CommandDescription
levered config listPrint all configuration key-value pairs.
levered config get <key>Print the value of a specific key.
levered config set <key> <value>Set a configuration value.

Optimizations

Create, manage, and inspect optimizations.

List optimizations

levered optimizations list [--limit N] [--order-by updated_at|created_at] [--include-archived] [--json]

List optimizations in the current organization. Returns up to --limit optimizations (1 to 100, default 10), newest first by --order-by. With updated_at (default), the list is ordered by the last update. With created_at, it is ordered by creation time. Archived optimizations are hidden unless --include-archived is set.

Show optimization details

levered optimizations show <id> [--json]

Print full details for a single optimization, including design factors, model configuration, linked metric, and current status.

Create an optimization

levered optimizations create \
  --name NAME \
  --design-factors JSON \
  --reward-metric-id UUID \
  [--description TEXT] \
  [--reward-type bool|numeric] \
  [--reward-window 24h] \
  [--excluded-combinations JSON] \
  [--context-factors JSON] \
  [--control variant|external|none] \
  [--holdout PERCENT] \
  [--baseline JSON] \
  [--json]

Create a new optimization as a draft.

FlagRequiredDescription
--nameYesHuman-readable name for the optimization.
--design-factorsYesJSON array of factors. Each factor has a name, a dtype (str or bool) and its levels.
--reward-metric-idYesUUID of the metric that defines success.
--descriptionNoDescription of the optimization.
--reward-typeNobool or numeric. Default: bool. If the reward metric has its own reward type, Levered uses the metric's type and ignores this flag.
--reward-windowNoConversion window for the reward metric, e.g. 24h, 7d or none. Default: 24h.
--excluded-combinationsNoFactor-level combinations never to serve, as a JSON array of maps from factor name to level value. Partial maps are allowed.
--context-factorsNoJSON array of context factors for personalization (e.g., country, device). Each context factor has a name and a dtype (str or bool).
--controlNoWhat holdout users see. With variant (default), one of the variants is the current experience and Levered serves it to the holdout. With external, the holdout keeps a version that is not one of the variants. external requires a holdout above 0, and holdout users train the model as that current version, never as a variant. With none, all variants are new, and the optimization has no holdout and no guardrails. Guardrails need a holdout above 0 with any control type. See Holdout.
--holdoutNoShare of traffic kept as the holdout, 0 to 50. Default: 10. Must be 0 with --control none.
--baselineWith --control variantThe current experience as a JSON map of factor name to level, e.g. '{"headline":"Scale up","cta_text":"Get started"}'. Required with --control variant, the default: Levered never picks a baseline for you.

Example. Create a hero section optimization with two design factors:

levered optimizations create \
  --name "Landing Page Hero" \
  --design-factors '[
    {"name": "headline", "dtype": "str", "levels": ["Ship faster", "Build better", "Scale up", "Go live today", "Start free"]},
    {"name": "cta_text", "dtype": "str", "levels": ["Get started", "Try it free"]}
  ]' \
  --reward-metric-id 8a3b12c4-5678-4def-abcd-1234567890ab \
  --baseline '{"headline": "Ship faster", "cta_text": "Get started"}' \
  --context-factors '[{"name": "country", "dtype": "str"}, {"name": "device_type", "dtype": "str"}]' \
  --json

Update optimization status

levered optimizations update <id> --status {live|paused|shipped|completed|archived}

Transition an optimization to a new status. See Optimizations for the status lifecycle.

Change other settings

levered optimizations update <id> [--name NAME] [--description TEXT] [--reward-window 24h] \
  [--design-factors JSON] [--excluded-combinations JSON] [--holdout PERCENT]
FlagDescription
--nameNew name. Allowed at any status.
--descriptionNew description. Pass "" to clear it. Allowed at any status.
--reward-windowConversion window for the reward metric, e.g. 24h, 7d or none.
--design-factorsReplace the design factors (JSON). Drafts only.
--excluded-combinationsCombinations never to serve (JSON). Only together with --design-factors.
--holdoutShare of traffic kept as the holdout, 0 to 50. Drafts only.

Label factors and levels

levered optimizations label <id> --factor <name> [--context | --level <value|id>] [--label <text>] [--description <text>] [--hypothesis <text>]

Set the display label, description or hypothesis of a design factor or level. Works at any status and does not change the values that the SDK serves. Pass "" to clear a field. --hypothesis applies to factors only. To label a context factor, pass --context. --context cannot be combined with --level.

Change what users outside the optimization see

levered optimizations update <id> --control none
levered optimizations update <id> --control variant --baseline-variant '{"headline":"Ship faster","cta_text":"Get started"}'
levered optimizations update <id> --control external --holdout 10

--control none marks all variants as new. Lift is then reported against an even split of traffic. It requires a holdout of 0. On a draft, --control none --holdout 0 sets both in one call. Guardrails need a holdout, so the change removes them. If the requirements are not met, the API refuses the change and the CLI prints the reason.

--control variant makes a variant the baseline. Name it with --baseline-variant: Levered never picks one for you.

--control external (drafts only) keeps the current version for the holdout and requires a holdout above 0.

Ship the winner

levered optimizations ship <id>

Serves the leading variant for each context to 100% of traffic. Learning stops, the holdout is removed, and results are frozen. Prints the shipped policy, which lists the variant served to each context segment. Pass -y to skip the confirmation and --json to get the policy as JSON.

To go back to learning, run levered optimizations update <id> --status live. This restores the holdout.

Stop an optimization

levered optimizations stop <id>

Stops the optimization permanently (status completed). Levered stops serving variants, so users get the fallback defined in your app. This cannot be undone. Pass -y to skip the confirmation.

Archive an optimization

levered optimizations archive <id> [-y]

Archive an optimization. Prompts for confirmation unless -y is passed.

View results

levered optimizations results <id> [--json]

Print performance results for an optimization: exposures and rates per variant, measured lift against the holdout, and the model's figures: policy and best-variant lift with their intervals, each variant's probability of being best and expected reward, each design factor's factor effect and level effects, the current lift split by design factor (factor uplift and importance, with the interaction term), and each context factor's importance. --json returns the API's results with the model figures under model.

The figures come from the posterior. A design factor's level effects compare each level with the reference, with the other factors mixed by that level's own Thompson policy, and its factor effect is what every segment taking its own best level is worth. A factor's uplift is the live policy over the factor's reference policy, which keeps the reference's mix over that factor's levels; its importance is its share of the current lift, which the factor uplifts and the interaction term split between them (a point share that sums to 1 with the interval of the per-draw share, whatever the lift's sign). A context factor's uplift is the live policy over the same policy with that factor averaged out, and its importance its share of the personalization gain, which the context uplifts and their interaction term split between them; do not compare it with a design factor's figures.

View lift history

levered optimizations lift-history <id> [--days N] [--json]

Print the model's policy and best-variant lift, one point per day: the last posterior of each day. --days limits it to a trailing window.

View progress

levered optimizations progress <id> [--matured-only] [--json]

Show the progress of an optimization:

  • Days running, counted from the first measured traffic.
  • Enrollment per arm, as unique users and converters, with the holdout share.
  • Convergence, which covers progress to best, P(beats baseline), and the variant that the model currently ranks highest with its probability of being best (its share of optimized traffic).
FlagDefaultDescription
--matured-onlyoffEnrollment counts only include day cohorts whose conversion window has fully closed.

Enrollment counts are per participant. A user who is exposed or converts multiple times counts once. The counts come from the measured holdout series and are not comparable to the model's per-event exposure counts shown in results.

View guardrails

levered optimizations guardrails <id> [--matured-only] [--json]

Show the following for each guardrail metric, followed by the overall rollup status:

  • The rate of the users served by the model and the rate of the holdout.
  • The result of the holdout test with its 95% confidence interval and p-value.
  • The status of the guardrail: ok, violated, or pending while data is missing.
FlagDefaultDescription
--matured-onlyoffOnly count users whose guardrail window has closed.

Add, change or remove a guardrail

levered optimizations guardrail-add <id> --metric <name|id> \
  --direction no-decrease|no-increase [--threshold <pct>] [--window 24h|7d|none]
levered optimizations guardrail-update <id> --metric <name|id> \
  [--direction no-decrease|no-increase] [--threshold <pct>] [--window 24h|7d|none]
levered optimizations guardrail-remove <id> --metric <name|id>

Guardrails can be changed at any status. Guardrails compare against the holdout, so they need a holdout above 0. Setting the holdout to 0 or removing the baseline removes the guardrails. An optimization has at most 10 guardrails, one per metric.

FlagDefaultDescription
--metricrequiredFor guardrail-add, a metric name or id from levered metrics list. For guardrail-update and guardrail-remove, the metric name, metric id or guardrail id of an existing guardrail.
--directionrequired for guardrail-addno-decrease is violated when the metric drops, no-increase when it rises.
--threshold0Change in percent that is tolerated before the guardrail is violated, from 0 to 100.
--windowNoneConversion window, for example 24h or 7d. none counts conversions without a time limit.

guardrail-remove removes the guardrail only. The metric is kept.

Capture variant screenshots

levered optimizations screenshot <id> --url <page-url> \
  [--device desktop|mobile|tablet] [--viewport WIDTHxHEIGHT] \
  [--selector <css>] [--wait-ms 800] [--inject-tag] \
  [--full-page] [--only 1,4] [--out-dir <dir>] [--no-upload] [-y]

Screenshot every servable variant of an optimization against a running app and upload the images to Levered, so each variant shows a visual preview in the dashboard's variants table.

For each variant, the command opens the page in a headless browser, intercepts the SDK's serve call, and forces that variant's factor values, so the page renders what users in that arm see. Point --url at your local dev server or a staging URL. The page must already use useVariant for this optimization.

FlagDefaultDescription
--urlrequiredURL of the page to screenshot (your running app).
--selectorNoneCSS selector to wait for before capturing. Use when the page renders content dynamically.
--devicedesktopDevice preset: desktop (1280x800), mobile (430x932) or tablet (820x1180).
--viewportNoneOverride the device preset's size with WIDTHxHEIGHT.
--inject-tagoffInject the hosted Levered web tag into the page before capture, for script-tag sites that do not have it installed yet.
-yoffSkip the sample-preview confirmation and capture every variant.
--wait-ms800Extra settle time in milliseconds after the page loads.
--full-pageoffCapture the full scrollable page instead of the viewport.
--onlyallComma-separated variant numbers to capture.
--out-dirtemp dirKeep the PNGs in this directory.
--no-uploadoffCapture only; skip uploading to Levered.

Requires Node.js on PATH. The first run installs a pinned Playwright and downloads the Chromium browser (~130 MB, one-time) into ~/.levered/screenshot-runner/. Disabled and excluded variants are skipped, and re-running overwrites the previous screenshots.

List observations

levered optimizations observations <id> [--page N] [--size N] [--json]

Paginate through the raw observation data (exposures matched to rewards) for an optimization.

FlagDefaultDescription
--page1Page number.
--size20Number of observations per page.

Models

Inspect and manage the models of optimizations.

CommandDescription
levered models list [--limit N] [--include-archived] [--json]List models in the organization.
levered models delete <id> [-y]Delete a model. Prompts for confirmation unless -y is passed.

Posterior

levered posterior query <optimization-id> --sql '<sql>' [--param name=value] [--version <v>] [--json]

Run read-only SQL against an optimization's posterior: the source of every model figure the dashboard and CLI show. See the posterior API for the tables, views and standard queries.

FlagDefaultDescription
--sqlrequiredThe query. Single-quote it, or pass it through a quoted heredoc, so the shell leaves $params alone.
--paramnoneBind $name as name=value; repeatable. A JSON number, boolean, null or quoted string binds as that, anything else as a string.
--versionlatestThe posterior version to read. Each response lists available_versions.
--jsonoffPrint the full response, including the version and the list of available versions.

Warehouse

Inspect and query your data warehouse. levered warehouse use-managed selects the Managed Warehouse. Connections to your own warehouse are managed through the dashboard or the API.

CommandDescription
levered warehouse use-managed [--replace] [--json]Use the Levered-hosted Managed Warehouse. If the organization already has a connection to its own warehouse, the command fails unless --replace is set. With --replace, the Managed Warehouse replaces that connection.
levered warehouse status [--json]Show the current warehouse connection status and provider.
levered warehouse tables [--json]List all tables in the connected dataset/schema.
levered warehouse columns <table> [--json]List column names and types for a table.
levered warehouse preview <table> [-n N] [--json]Preview rows from a table. Default: 10 rows.
levered warehouse query <sql> [-n N] [--json]Run a SQL query against your own warehouse connection (not available on the Managed Warehouse). Default limit: 100 rows (-n, 1 to 1000).
levered warehouse exposure-columns [--anonymous-id COL] [--timestamp COL] [--variant COL] [--json]Show or set which columns of your exposures table hold the SDK id, the exposure time and the variant. New optimizations read their exposures with these columns. See Use your own column names.

AI agents can use these commands to discover table schemas before writing metric SQL.


Metrics

Define reward metrics. A reward metric is a SQL query that returns reward events from your warehouse.

List metrics

levered metrics list [--json]

Create a metric

levered metrics create \
  --name NAME \
  --sql SQL \
  --anonymous-id-col COL \
  --timestamp-col COL \
  [--value-col COL] \
  [--reward-type TYPE] \
  [--json]
FlagRequiredDescription
--nameYesHuman-readable metric name.
--sqlYesSQL query that returns reward events from your warehouse.
--anonymous-id-colYesColumn in the query result that identifies the user (anonymous ID).
--timestamp-colYesColumn with the event timestamp.
--value-colNoColumn with a numeric reward value. Omit for binary (conversion) metrics.
--reward-typeNobool or numeric. With numeric, set --value-col.

Example. Create a sign-up conversion metric:

levered metrics create \
  --name "Sign-ups (7d)" \
  --sql "SELECT anonymous_id, signed_up_at FROM analytics.sign_ups WHERE signed_up_at >= CURRENT_DATE - 7" \
  --anonymous-id-col anonymous_id \
  --timestamp-col signed_up_at \
  --json

Preview metric data

levered metrics preview <id> [--limit N] [--json]

Run the metric's SQL query and display a sample of matching rows. Use it to check that the query returns the expected data before linking the metric to an optimization.

Delete a metric

levered metrics delete <id> [-y]

Delete a metric. Prompts for confirmation unless -y is passed. A metric used as a guardrail cannot be deleted. Remove the guardrail first.


Variant Serving

Request a variant assignment for a user outside of the SDK.

levered serve <optimization-id> [--anonymous-id ID] [--context JSON] [--dry-run] [--json]
FlagDescription
--anonymous-idThe user's anonymous ID. If omitted, a random ID is generated.
--contextJSON object of context factor values for personalized serving (e.g., '{"country": "US", "device_type": "mobile"}').
--dry-runRun the same decision path without recording anything on Levered's side and without training. Works on draft optimizations. Use it to see which variant a test user gets and whether the user is in the holdout.

Returns the selected variant (one level for each design factor) for the given user and context, and is_holdout.


Verify

Check an optimization's setup before launch.

levered verify <optimization-id> [--anonymous-id ID] [--timeout SECONDS] [--days N] [--json]

Each call runs the identity check on the last --days days (default 14) of your exposures table. The check reports two shares:

  • The share of exposure ids that also appear in the reward metric.
  • If the table has an is_holdout column, the share of is_holdout rows that Levered's holdout hash also assigns to the holdout.

A low share indicates a possible id mismatch. Interpret it using representative non-test data, as described in Test before launch.

With --anonymous-id on the Managed Warehouse, it first waits up to --timeout seconds (default 120) for a test exposure and a test reward from that user. JSON output includes exposure and reward for arrival, plus the aggregate report under identity. Top-level ok is true only when arrival and identity.ok are both true.

Exits with status 1 when either check fails or an API error occurs. Exit status 1 does not always mean a missing event, so inspect the JSON fields and errors. If arrival succeeds but aggregate reward overlap cannot be established solely because representative non-test data is absent or QA rewards are intentionally excluded, record identity as pending under the test-before-launch rules. Query/authentication errors, failed holdout checks, and failures with representative data still block. An authenticated managed event-arrival read returns only the event booleans. It does not mark aggregate identity as passed.


Interactive Dashboard

levered dashboard [--refresh SECONDS]

Launch a terminal UI (TUI) that displays live optimization data, including variant distributions, reward rates, and model state. The display refreshes on the interval specified by --refresh (default: 10 seconds).

The Metrics tab can also delete the selected metric (d), and the Warehouse tab can test (t) or disconnect (d) the warehouse connection. Neither action asks for confirmation.