Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/simonw/LLM/llms.txt

Use this file to discover all available pages before exploring further.

LLM is a Python package available on PyPI and via Homebrew. Once installed, it exposes the llm command globally, ready to accept prompts, manage API keys, and run plugins. This page walks through installation, upgrading, key management, and common configuration options.

Installation

1

Choose your package manager and install

Pick the installation method that fits your workflow. All methods install the same llm binary.
pip install llm
Homebrew and PyTorch conflict. The Homebrew version of LLM currently uses Python 3.12, and PyTorch does not yet have a stable release for that Python version. Plugins that depend on PyTorch — such as llm-sentence-transformers — may not install cleanly via Homebrew.To work around this, manually install PyTorch before the plugin:
llm install llm-python
llm python -m pip install \
  --pre torch torchvision \
  --index-url https://download.pytorch.org/whl/nightly/cpu
llm install llm-sentence-transformers
2

Verify the installation

Confirm llm is on your PATH and check the installed version:
llm --version

Upgrading to the Latest Version

Use the upgrade command that matches your original install method:
pip install -U llm
If the latest version is not yet available on Homebrew, you can upgrade directly through llm itself:
llm install -U llm

Using uvx for One-Off Runs

If you have uv installed, you can run LLM without a permanent installation using uvx. This spins up a temporary virtual environment on the fly:
export OPENAI_API_KEY='sk-...'
uvx llm 'fun facts about skunks'
You can include plugins with the --with flag. For example, to run an Anthropic model without installing anything permanently:
export ANTHROPIC_API_KEY='...'
uvx --with llm-anthropic llm -m claude-3.5-haiku 'fun facts about skunks'
All standard llm commands work with uvx. You can even store your API key persistently this way:
uvx llm keys set openai
# Paste key here

API Key Management

Most LLM providers require an API key. LLM supports three ways to supply keys, applied in this precedence order: stored keys → --key flag → environment variable.

Saving Keys with llm keys set

The recommended approach is to store keys once using the interactive llm keys set command:
llm keys set openai
You will be prompted to paste the key:
% llm keys set openai
Enter key:
Once stored, the key is used automatically for all subsequent calls. Keys are saved to a keys.json file. Find its location with:
llm keys path
On macOS this is ~/Library/Application Support/io.datasette.llm/keys.json. On Linux it is typically ~/.config/io.datasette.llm/keys.json. To list the names of all currently stored keys:
llm keys

Passing Keys Per Command with --key

Pass a key directly on the command line with the --key option. You can provide a raw key value or the alias of a stored key:
# Raw key value
llm "Five names for pet weasels" --key sk-my-key-goes-here

# Alias of a stored key
llm keys set personal
llm "Five friendly names for a pet skunk" --key personal

Keys via Environment Variables

LLM reads API keys from environment variables when no stored key or --key flag is present. The variable name is determined by each model’s plugin. For the built-in OpenAI support, the variable is OPENAI_API_KEY. For third-party plugins, check the plugin’s documentation for its specific environment variable name. To use an environment variable explicitly (overriding a stored key):
llm 'my prompt' --key $OPENAI_API_KEY

Configuration

Setting a Default Model

LLM defaults to gpt-4o-mini when no -m flag is provided. Change the default with:
llm models default gpt-4o
View the current default:
llm models default
Any supported model alias can be passed to this command. Run llm models to see all available models and their aliases.

Custom Directory Location

LLM stores prompt templates, API keys, preferences, and the SQLite log database in a platform-specific directory:
  • macOS: ~/Library/Application Support/io.datasette.llm/
  • Linux: ~/.config/io.datasette.llm/
Override this location with the LLM_USER_PATH environment variable:
export LLM_USER_PATH=/path/to/my/custom/directory
Add this to your shell profile (.bashrc, .zshrc, etc.) to make it permanent.

Turning SQLite Logging On and Off

By default, LLM logs every prompt and response to a local SQLite database. Disable logging globally:
llm logs off
Re-enable it:
llm logs on
Check the current logging state:
llm logs status
Even with global logging disabled, you can log a single prompt by passing --log on the command line. See the Logging documentation for details on viewing and searching your log history.

Build docs developers (and LLMs) love