LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

llm-keys

Manage stored API keys for the llm CLI

TLDR

List stored key names
$ llm keys list
copy
Save an OpenAI key (prompts for the secret)
$ llm keys set openai
copy
Save a key without a prompt
$ llm keys set openai --value [sk-...]
copy
Print a stored key (useful in scripts)
$ export OPENAI_API_KEY=$(llm keys get openai)
copy
Show the keys.json path
$ llm keys path
copy

SYNOPSIS

llm keys [options] [command]llm keys listllm keys set [--value secret] namellm keys get namellm keys path

DESCRIPTION

llm keys stores provider API keys for llm in a JSON file in the LLM user directory. After llm keys set openai, prompts such as llm "Five names for a pet pelican" use that key automatically.Resolution order for a prompt: --key on llm / llm prompt (raw secret or a stored alias), then keys.json, then the provider environment variable (OPENAI_API_KEY for OpenAI). --key personal uses a stored alias named personal.

PARAMETERS

list

Print the names of keys in keys.json. Default subcommand if none is given (llm keys).
set name
Store a key under name. Prompts on stdin unless --value is given. Common names include openai; plugins document their own (for example anthropic).
--value secret
Pass the secret on the command line instead of prompting. Visible in process listings.
get name
Print the stored secret. Typical use: export OPENAI_API_KEY=$(llm keys get openai).
path
Print the absolute path of keys.json.
-h, --help
Help for llm keys or a subcommand.

CONFIGURATION

keys.json

Default locations: ~/.config/io.datasette.llm/keys.json on Linux, ~/Library/Application Support/io.datasette.llm/keys.json on macOS. llm keys path prints the resolved file.
LLM_USER_PATH
Override the whole LLM user directory (keys, logs, templates).

INSTALL

brew install llm
copy
nix profile install nixpkgs#llm
copy

CAVEATS

Subcommand of llm. keys.json holds secrets in plaintext. llm keys get and --value expose secrets to the terminal and process table. Homebrew llm may lag PyPI; llm install -U llm upgrades the tool inside that environment.

SEE ALSO

llm(1), llm-models(1), llm-logs(1), ollama(1)

RESOURCES

Copied to clipboard
Kai