apivault CLI

The apivault command-line client talks to your ApiVault instance over HTTP. Manage encrypted API keys from the terminal, inject secrets into local processes, or export dotenv files for frameworks that require them.

Requirements

  • Node.js 18.17.0 or newer

Installation

Shell
npm install -g apivault

Or run on-demand without a global install:

On-demand executionShell
npx apivault <command>

Quick start

The most common workflow is using apivault run to securely inject secrets into your local development server without ever writing them to disk.

Daily workflowShell
# 1. Authorize your terminal
apivault login

# 2. Set your default environment (optional)
apivault config set run.env Development

# 3. Inject secrets and start your app
apivault run -- npm run dev

Global options

Available on every command:

OptionDescription
-V, --versionOutput the version number
-h, --helpDisplay help for command
--jsonEmit machine-readable JSON output instead of styled text
--timeout <s>Seconds to wait for browser login approval (default: 300)

Running apivault with no arguments prints sign-in status and exits.

Authentication

Sign-in happens in your browser, not the terminal. CLI tokens are separate from MCP OAuth tokens — revoking one does not affect the other.

login

Opens a browser to approve the CLI's connection to your account.

LoginShell
apivault login

whoami

Show the currently signed-in user.

Who am IShell
apivault whoami

logout

Revoke this device's token and sign out.

LogoutShell
apivault logout

The CLI manages the following local data files:

FilePurpose
token.jsonAuth token from login (removed by logout)
config.jsonCLI defaults for run and optional stored vault key

keys — Manage stored API keys

keys list

Lists all vault keys for the connected account. Key values are masked by default.

List keysShell
apivault keys list

keys add

Interactive by default. Fully non-interactive for scripting:

Non-interactive addShell
apivault keys add \
  --name STRIPE_SECRET \
  --service Stripe \
  --environment Production \
  --key "sk_live_..." \
  --notes "Billing API"

Interactive defaults: service = Custom, environment = Production.

OptionDescription
--name <name>Key name
--service <service>Service name
--environment <env>Environment
--key <value>API key / secret value to store
--vault-key <passphrase>Custom vault passphrase (for custom-mode accounts)
--notes <notes>Optional notes

keys get

Get keyShell
# View key details (value is masked)
apivault keys get <id>

# Decrypt and show the raw value
apivault keys get <id> --reveal
OptionDescription
--revealDecrypt and print the raw secret value
--vault-key <passphrase>Custom vault passphrase (custom encryption mode)

keys update

Interactive wizard to edit a key's name, service, environment, notes, or value.

Update keyShell
apivault keys update <id>

keys delete

Deletes a key. You will be prompted to confirm before deletion.

Delete keyShell
# Interactive deletion
apivault keys delete <id>

# Force delete without prompt
apivault keys delete <id> -f
OptionDescription
-f, --forceSkip the confirmation prompt

Custom vault passphrase

If you set a custom encryption key on the website (Settings → Encryption Key), operations that encrypt or decrypt need that passphrase. Resolution order:

  1. --vault-key flag
  2. APIVAULT_KEY environment variable
  3. Config value vaultKey
  4. Interactive hidden prompt
Vault key examplesShell
# 1. Pass explicitly via flag
apivault keys get <id> --reveal --vault-key "your passphrase"

# 2. Use an environment variable
APIVAULT_KEY="your passphrase" apivault keys get <id> --reveal

# 3. Store locally in config (prompts securely)
apivault config set vaultKey

run — Inject secrets and run a command

Run with secretsShell
# Run with the Production environment
apivault run --env Production -- npm start

# Run with Staging
apivault run --env Staging -- node server.js

Loads all keys for an environment, decrypts them, and injects each key's name as an environment variable into the child process. Local dotenv files (.env, .env.local, etc.) are temporarily renamed to *.apivault-run-hidden while the command runs, then restored on exit. Nothing is written to disk.

Resolution precedence

SettingOrder (first wins)
Environment--env → config run.env → error
Commandargs after -- → config run.command → error
Vault key--vault-keyAPIVAULT_KEY → config vaultKey → prompt
Config defaultsShell
apivault config set run.env Production
apivault config set run.command "npm start"
apivault run                          # uses both defaults

env — Export and restore dotenv files

env export

Decrypt keys for an environment and write them to a local .env file:

Dotenv exportShell
# Export to .env (merges with existing variables)
apivault env export --env Production

# Export to a custom file
apivault env export --env Staging -o .env.local

# Replace the file entirely instead of merging
apivault env export --env Production --force
OptionDescription
--envEnvironment to export (or config run.env)
-o, --outputOutput file (default: .env)
-f, --forceReplace file instead of merging
--vault-keyCustom vault passphrase

By default, existing variables in the target file are preserved — vault keys are updated in place and new keys appended. Always add .env to .gitignore.

env restore

Restore hidden dotenv backups created by apivault run:

Restore env filesShell
# Restore in the current directory
apivault env restore

# Restore in a specific directory
apivault env restore -C /path/to/project
OptionDescription
-C, --directoryProject directory for restore (default: cwd)

config — Local CLI defaults

The CLI supports three configuration keys. Explicit command flags always override these defaults:

KeyDescription
run.commandThe default command to execute for apivault run (e.g. "npm start")
run.envThe default environment to pull secrets from (e.g. Production)
vaultKeyThe custom vault passphrase used to decrypt secrets for custom-mode accounts

config list

Show all config values. Secrets like vaultKey are masked.

List configShell
apivault config list

config get

Print a specific config value (e.g. run.command).

Get configShell
apivault config get run.command

config set

Set a config value. vaultKey is stored in plaintext in config.json — skip storing it if you prefer --vault-key, APIVAULT_KEY, or the interactive prompt. If you omit the value for a secret key, you will be prompted securely.

Set configShell
# Set default environment
apivault config set run.env Production

# Set default command
apivault config set run.command "npm start"

# Prompt securely for the passphrase
apivault config set vaultKey

config delete

Remove a config value.

Delete configShell
apivault config delete run.env

Scripting with --json

Pass the --json flag to any command to emit machine-readable JSON output to stdout instead of styled text. This makes it easy to integrate the CLI into automated scripts, CI/CD pipelines, and tools like jq.

When --json is enabled, standard success messages and UI formatting are disabled. Errors are also emitted to stdout as a JSON object containing an error key (e.g. {"error": "message"}) so your script can reliably parse the output.

JSON outputJSON
# Extract just the IDs of all keys
apivault --json keys list | jq '.[] | .id'

# Decrypt a specific key and output raw text
apivault --json keys get <id> --reveal | jq -r .rawKey

# Export an environment programmatically
apivault --json env export --env Production

Security

LayerDetail
TransportHTTPS with token-header authentication
Local storagetoken.json and config.json are stored locally
Process isolationSecrets exist only in child-process memory during apivault run — nothing written to disk

Troubleshooting

SymptomFix
HTTP 401Run apivault login
VAULT_KEY_REQUIREDProvide vault passphrase via --vault-key, APIVAULT_KEY, or config
Secrets not loading in runCheck environment name matches keys in vault (keys list)
.env files missing after runRun apivault env restore
PowerShell strips --CLI falls back to remaining args; quote the command if needed