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

# Command reference

> Every Kelviq CLI command, flag by flag.

All commands support `--help`. The CLI targets your **sandbox** environment unless you pass `--prod` — see [Environments & authentication](https://docs.kelviq.com/cli/environments.md).

Every command reads `KELVIQ_*` variables from `.env.local` and then `.env` in the working directory before it runs, so a project's env file works without exporting anything. A variable already set in your shell always wins. Two global flags control this:

| Flag | Description |
| - | - |
| `--env-file <path>` | Read this dotenv file instead of `.env.local`/`.env`. Repeat it for several files; a missing file is an error. |
| `--no-env-file` | Don't read any env file. |

Output is colorized on interactive terminals (green creates, yellow updates, red archives) and automatically plain when piped. Disable colors explicitly with the global `--no-color` flag or the `NO_COLOR` environment variable.

***

## kelviq init

Writes a starter `kelviq.config.ts` to the current directory.

```shell theme={null}
kelviq init                     # the saas template
kelviq init --template usage    # metered usage with an overage price
kelviq init --template license  # a plan that issues license keys
kelviq init -o pricing/kelviq.config.ts
kelviq init --force
```

| Flag | Description |
| - | - |
| `--template <name>` | Which starter catalog to write: `saas` (default), `usage`, or `license`. |
| `-o, --output <path>` | Where to write the file. Defaults to `kelviq.config.ts` in the current directory. |
| `--force` | Overwrite the file if it already exists. Without it, `init` refuses rather than clobbering your edits. |

Each template is a complete catalog that `kelviq push` accepts as written, using the typed builders from `@kelviq/cli/config` — see the [format reference](https://docs.kelviq.com/cli/kelviq-config.md):

* **`saas`** — a product with a free plan and a Pro plan billed monthly or yearly, gating a Boolean feature and a Customizable limit.
* **`usage`** — a `METER` feature with the details the API requires, a free plan with a hard monthly allowance, and a Pro plan with an included quantity plus a tiered pay-as-you-go overage price.
* **`license`** — a Pro plan whose orders issue license keys valid on up to three devices.

***

## kelviq login

Stores a Server API key for the CLI to use.

```shell theme={null}
kelviq login          # store a sandbox key (default)
kelviq login --prod   # store a production key
```

| Flag | Description |
| - | - |
| `--prod` | Store the key for the production environment instead of sandbox. |

What it does:

1. Prints the dashboard's [API keys page](https://app.kelviq.com/settings/api-keys) URL and tries to open it in your default browser — already switched to the environment you're logging into (sandbox by default, production with `--prod`), so the key on screen is the key the CLI expects.
2. Prompts you to paste the key. In an interactive terminal each pasted character shows as `*` — so you can see the paste landed — and a `Received a N-character key.` line confirms the length. The key itself is never echoed or logged.
3. Stores it in `~/.config/kelviq/config.json` with owner-only permissions (`0600`).

> [!WARNING]
>
> Paste a **Server API Key**, not a Client API Key. Server keys have full API access — treat the config file like any other credential store, and never commit it anywhere.

`login` does not check the key. Run `kelviq env --check` afterwards to confirm the API accepts it. Kelviq has no key-introspection endpoint yet, so the CLI can't show which organization the key belongs to.

For CI and other non-interactive contexts, skip `login` entirely and set an environment variable instead — see [Environments & authentication](https://docs.kelviq.com/cli/environments.md#environment-variables).

***

## kelviq logout

Removes stored API keys.

```shell theme={null}
kelviq logout          # remove the stored sandbox key
kelviq logout --prod   # remove the stored production key
kelviq logout --all    # remove both
```

| Flag | Description |
| - | - |
| `--prod` | Remove the production key instead of sandbox. |
| `--all` | Remove both sandbox and production keys. |

`logout` only touches the stored config file. Keys supplied via environment variables are unaffected — unset those in your shell or CI configuration.

> [!NOTE]
>
> Removing a key locally does not revoke it. To revoke a key, delete it from the [API keys page](https://app.kelviq.com/settings/api-keys) in the dashboard.

***

## kelviq env

Shows which environment and keys the CLI is configured with, and which env files it read.

```shell theme={null}
kelviq env
kelviq env --check
```

```text theme={null}
Environment : sandbox (default — use --prod to target production)
KELVIQ_ENV  : unset (sandbox) — unprefixed KELVIQ_* vars apply to sandbox
Sandbox URL : https://sandboxapi.kelviq.com/api/v1
Prod URL    : https://api.kelviq.com/api/v1
Sandbox key : set
Prod key    : missing
Org         : unknown — Kelviq has no key-introspection endpoint yet
Env files   : /path/to/app/.env.local (KELVIQ_SERVER_API_KEY, KELVIQ_ENV)
```

| Flag | Description |
| - | - |
| `--check` | Make one authenticated read per configured key and report whether the API accepted it. |
| `--json` | Machine-readable output. Never includes any part of a key's value. |

Without `--check`, key rows show `set` or `missing` only and nothing is sent to the API. With `--check`, each configured key gets one `GET /catalog/products/` call against its own environment's host and a result line:

```text theme={null}
Sandbox check : ok
Prod   check : skipped (no key configured)
```

`ok` means the key was accepted. `rejected` (HTTP 401 or 403) almost always means the key belongs to the other environment. The command exits non-zero when any configured key fails, or when no key is configured, so a script or agent can gate on it. `--check --json` adds `sandboxCheck` and `prodCheck` objects (`{ ok, status, httpStatus?, message? }`) to the JSON document.

***

## kelviq pull

Fetches your remote catalog and writes it as a `kelviq.config.ts`.

```shell theme={null}
kelviq pull                    # pull the sandbox catalog
kelviq pull --prod             # pull the production catalog
kelviq pull -o pricing.config.ts
kelviq pull --force            # overwrite an existing file
```

| Flag | Description |
| - | - |
| `--prod` | Pull from the production environment instead of sandbox. |
| `-o, --output <path>` | Where to write the config. Defaults to `kelviq.config.ts` in the current directory. |
| `--force` | Overwrite the output file if it already exists. Without it, `pull` refuses rather than overwriting local edits. |

What it fetches: all products, all features, the **latest version** of each plan, and each plan's prices and entitlements. Every cross-reference in the generated file uses `identifier` slugs, never UUIDs — the file is stable across environments that share identifiers.

On success, `pull` prints the path it wrote and a **warnings list** for anything it couldn't represent in the config format (for example, plan fields like `links`, `countries`, and `files` are dropped, with one warning each; a plan's `license` settings are pulled into the file). Warnings are informational — the file it wrote is still valid.

On failure — missing key, network error, unexpected API response — `pull` writes `pull failed: <reason>` to stderr and exits non-zero without touching the output file.

***

## kelviq push

Deploys a `kelviq.config.ts` to a Kelviq environment: fetches the current remote catalog, computes exactly what would change, shows you the diff, and applies it only after confirmation.

```shell theme={null}
kelviq push --dry-run          # preview only — never writes anything
kelviq push                    # diff, confirm, apply to sandbox
kelviq push --prod             # same, against production
kelviq push --publish          # also publish the plans this run changed
kelviq push pricing.config.ts  # explicit config path
```

| Flag | Description |
| - | - |
| `[config]` | Path to the config file. Defaults to `kelviq.config.ts`. |
| `--prod` | Target production instead of sandbox. |
| `--dry-run` | Print the diff and exit. Guaranteed zero writes. |
| `--yes` | Skip the confirmation prompts (required in non-interactive sessions, e.g. CI). |
| `--publish` | Publish the plans this run created, updated, or price-replaced — with its own confirmation. |
| `--migrate-features` | With `--publish`: migrate existing customers to the published plan's entitlements. |
| `--migrate-pricing` | With `--publish`: migrate existing customers to the published plan's pricing. |
| `--prune` | Archive remote-only plans/features that the CLI created (see below). |
| `--allow-prod-prune` | Required in place of the interactive typed confirmation to `--prune` production non-interactively. |
| `--verbose` | Expand aggregated warnings (e.g. list every stripped server-owned price field individually). |
| `--json` | With `--dry-run` only: emit the machine-readable plan-of-record as JSON on stdout. |

The diff shows **what actually changes**, value to value — `~ update plan "pro": name "Pro" → "Pro Plan"` — so the confirmation gate is reviewable at a glance.

### Scripting with `--json`

`kelviq push --dry-run --json` prints exactly one JSON document: `{environment, direction, changes, summary, operations, prune, publish, featureDrift, errors, warnings}`. The `changes` boolean makes drift checks a one-liner in CI:

```shell theme={null}
kelviq push --dry-run --json | jq -e '.changes | not' || echo "catalog has drifted"
```

`--json` is valid only with `--dry-run` (JSON mode never mixes with prompts or writes), always exits 0 on a successful render, and emits `{"error": …}` documents on failures. The shape is a documented, versioned contract — see the repo README.

### What push writes — and in what order

Push converges the environment toward your config in dependency order: products → features → plans → entitlements → prices → publish → prune. Cross-references you wrote as identifiers are resolved to UUIDs automatically, including references to resources created earlier in the same run.

**Everything push writes is a draft by default.** Plan creates land in draft; updating a published plan creates a new draft version. Nothing a customer sees changes until a plan is explicitly published. On a mid-run failure, push stops immediately, reports exactly what was applied and what wasn't, and exits non-zero — there's no rollback, but because the writes were drafts, a half-applied push has no customer impact.

Push stamps a `managed-by: kelviq-cli` entry into the `metadata` of every feature and plan it creates (merged with any metadata you declare). That marker is how `--prune` later distinguishes CLI-managed resources from everything else — you'll see it in the dashboard, and it's safe to leave alone.

### Prices are all-or-nothing per plan

A plan **with** a `prices` array in config always pushes that complete array, replacing the plan's entire remote price set. A plan **without** a `prices` key never touches remote prices at all. Omitting `prices` means "leave pricing alone," not "this plan is free."

Prices are compared on the fields your config sets. A field you omit — `freeTrial`, `taxBehavior`, a charge's `paymentType` or `reset` — is left to the server's default and never counts as a difference, so a hand-authored price diffs clean after its first push.

### METER features are checked before anything is written

The API rejects a `METER` feature created without `featureDetails` (`featureSubType` and `units`). Push checks for this while building the plan and stops before any write, naming the feature and the shape to add — see [feature()](https://docs.kelviq.com/cli/kelviq-config.md#feature).

### Features can't be updated — by design

The Kelviq API deliberately treats feature attributes as immutable; renaming a feature is a dashboard operation. If a feature in your config differs from its remote counterpart, push stops **before writing anything** and lists the drifted fields. A feature's identifier and type can't change: to change them, create a new feature, then run `kelviq pull` and push again. Edit the name in the [dashboard](https://app.kelviq.com).

### Publishing

`--publish` publishes the plans the run just changed, after a second, separate confirmation listing them. A bare `--publish` never migrates existing customers — they stay on their current entitlements and pricing until you deliberately pass `--migrate-features` and/or `--migrate-pricing`, each of which spells out its consequence before you confirm. `--yes` skips prompts; it never substitutes for passing a migration flag explicitly.

### Pruning

Remote-only resources — things that exist in the environment but not in your config — are normally just listed as warnings. `--prune` archives them, under strict conditions:

* Only plans and features **carrying the `managed-by: kelviq-cli` marker** are ever archived. Anything created in the dashboard, by another tool, or before marker support is listed as *skipped* with the reason — never touched.
* **Products are never pruned**, ever.
* Archiving is the platform's soft-delete — nothing is destroyed.
* Pruning production requires typing the environment name at a dedicated prompt (or `--allow-prod-prune` in CI). `--yes` alone never unlocks it.

***

## kelviq promote

Moves your sandbox catalog to production in one command — the same engine and safety rails as `push`, with sandbox as the source instead of a local file.

```shell theme={null}
kelviq promote --dry-run       # preview what production would change — read-only
kelviq promote                 # diff, confirm, apply drafts to production
kelviq promote --publish       # and publish the changed plans
```

| Flag | Description |
| - | - |
| `--dry-run` | Print the sandbox→production diff and exit. Guaranteed zero writes. |
| `--yes` | Skip the confirmation prompts. |
| `--publish` / `--migrate-features` / `--migrate-pricing` | Same semantics as `push`. |
| `--prune` | Archive marker-carrying production plans/features absent from sandbox. Always crosses the production-prune gate. |
| `--allow-prod-prune` | Non-interactive stand-in for the typed production confirmation. |
| `--verbose` / `--json` | Same semantics as `push` (`--json` requires `--dry-run`). |

Promote reads and writes **no local file** — it fetches the sandbox catalog in memory and reconciles production toward it, matching resources by identifier (which is why the config format bans per-environment UUIDs). It needs both keys configured: sandbox to read, production to write.

Everything you know about push applies: drafts by default, a confirmation showing the full diff first, feature drift between the environments stops the run with dashboard guidance, and prices replace whole-set per plan. The intended workflow is always `--dry-run` first:

```shell theme={null}
kelviq promote --dry-run   # read what would change
kelviq promote             # then do it
```

Promotion is one-way — sandbox to production. There is no reverse mode.

***

## kelviq status

Shows the live catalog of an environment without writing a config file: products, features, and the latest version of every plan with its price and entitlement counts. Read-only — the check to run after a push to confirm what landed.

```shell theme={null}
kelviq status
kelviq status --prod
kelviq status --json
```

```text theme={null}
Environment : sandbox

Products (1)
  my-app  My App

Features (2)
  api-calls          METER         API calls
  history-retention  CUSTOMIZABLE  History retention (days)

Plans (2)
  free  Free  product my-app  ·  v1  ·  1 price  ·  1 entitlement  ·  visible
  pro   Pro   product my-app  ·  v2  ·  1 price  ·  2 entitlements  ·  visible  ·  license keys
```

| Flag | Description |
| - | - |
| `--prod` | Read production instead of sandbox. |
| `--json` | Emit `{ environment, products, features, plans }`, each plan as `{ identifier, name, product, version, isLatest, isVisible, prices, entitlements, licenseKeys }`. |

A plan with no prices is flagged, since it can't be bought. The API reports a plan's version number rather than a draft/published state, so that's what `status` shows.

***

## kelviq webhook

Registers the app's webhook endpoint and gets the signing secret into the app's env file without it ever appearing on screen.

```shell theme={null}
kelviq webhook list
kelviq webhook add https://app.example.com/api/kelviq/webhooks \
  --events checkout.completed,subscription.created,subscription.updated,subscription.cancelled,invoice.payment_failed \
  --write-secret .env.local
```

### kelviq webhook add

| Flag | Description |
| - | - |
| `<url>` | The public https URL that receives events. Localhost and private addresses are rejected by the API. |
| `--events <list>` | Comma-separated event types — see the [event list](https://docs.kelviq.com/guides/webhooks.md#event-types). Required. |
| `--write-secret <file>` | Write the signing secret into this dotenv file, replacing or appending a `KELVIQ_WEBHOOK_SECRET=` line. The value is never printed. |
| `--variable <name>` | Variable name to write instead of `KELVIQ_WEBHOOK_SECRET`. |
| `--print-secret` | Print the secret to stdout instead. Off by default. |
| `--prod` | Target production instead of sandbox. |
| `--yes` | Skip the confirmation prompt (required in non-interactive sessions). |
| `--json` | Machine-readable output. The endpoint's `secret` is always `[hidden]` unless `--print-secret` is passed. |

`add` is idempotent on the URL: an endpoint that already exists for the same URL is reused instead of registered twice, and its events are extended when the ones you pass aren't all covered. With neither `--write-secret` nor `--print-secret`, the secret stays hidden and the output tells you how to get it.

### kelviq webhook list

Lists endpoints with their URL, state, id and events. Secrets are never shown. `--prod` and `--json` as above.

***

## kelviq discount

Creates and lists discount codes. Only enabling or disabling a code can change after creation, so `create` restates everything and asks before writing.

```shell theme={null}
kelviq discount list
kelviq discount create --name "Launch offer" --code LAUNCH20 --percent 20 \
  --duration repeating --months 3 --product my-app --plans pro-monthly
kelviq discount create --name "Ten off" --code TENOFF --amount 10 --currency USD
```

### kelviq discount create

| Flag | Description |
| - | - |
| `--name <text>` | Shown on the customer's invoice. Required. |
| `--code <CODE>` | What customers enter at checkout: uppercase letters and digits. Required. |
| `--percent <n>` | Percentage off, 1–100. Exactly one of `--percent` or `--amount`. |
| `--amount <x>` | Fixed amount off in normal currency units; needs `--currency`. |
| `--currency <code>` | ISO currency code for `--amount`. |
| `--duration <once\|repeating\|forever>` | How long the discount applies. Default `once`. |
| `--months <n>` | With `--duration repeating`: how many **billing periods** it applies for. Not calendar months — `3` on a yearly plan is three years, so scope a "first 3 months" code to monthly plans. |
| `--product <identifier>` | Limit the code to one product, by identifier or UUID. The CLI resolves the identifier to the UUID the API wants. |
| `--plans <list>` | With `--product`: comma-separated plan identifiers. Omit to cover every plan of the product. |
| `--max-redemptions <n>` | Total number of uses across all customers. |
| `--redeem-by <datetime>` | ISO 8601 date/time after which the code stops working. |
| `--prod` / `--yes` / `--json` | As for `webhook add`. |

Discount codes need a Merchant of Record organization.

### kelviq discount list

Lists codes with amount, duration and state. `--search <text>` filters by name or code; `--prod` and `--json` as above.


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