LLM CLI Cheatsheet
`llm` is a lightweight command-line LLM tool supporting OpenAI, Claude, Gemini, Ollama, GPT4All, and more via plugins. Features include prompt templates, interactive chat, embedding generation, and semantic search — the most convenient way to interact with LLMs from the terminal.
Quick Start
``bash
# Install
pip install llm
# Set an API key llm keys set openai
# Ask a question llm 'What is the capital of Japan?'
# Use a different model llm -m claude-3-haiku-20240307 'Write a haiku'
# Chat interactively llm chat
# Continue the conversation
llm -c 'Tell me more'
`
Supported Models
Out of the box: OpenAI (GPT-4o, GPT-4o-mini). Via plugins: Claude (llm-claude-3), Gemini (llm-gemini), Ollama (llm-ollama, for local models), GPT4All (llm-gpt4all, fully offline), and many community plugins.
Chat & Conversation
llm chat starts an interactive session. Use -c to continue any previous conversation. Use llm logs to browse history. Conversations include system prompts, user messages, and model responses in a persistent SQLite database.
Prompt Templates
Create reusable prompt templates with llm templates edit . Templates use Jinja-style {{variable}} syntax. Use them with llm -t 'value'. Pre-installed templates include various summarization and extraction patterns.
Embeddings & Semantic Search
llm includes a complete embedding workflow: llm embed for single texts, llm embed-multi for batch embedding documents, and llm similar for semantic search. Embeddings are stored in SQLite and can be exported for use in other tools.
Plugin System
llm's power comes from its plugin ecosystem. Install plugins with pip install llm-. List installed plugins with llm plugins`. Community plugins add models, embedding functions, template loaders, and more.
Startup & Modes(20)
| Command | Level | ||
|---|---|---|---|
llm --helpShow llm CLI help | Basic | llm --help | |
llm 'prompt'Query LLM directly with prompt argument (core usage) | Basic | llm 'What is the capital of France?' | |
llm -mSpecify which model to use | Basic | llm -m gpt-4o 'Explain quantum computing' | |
llm -m claude-3-opus-20240307Use Claude Opus model | Basic | llm -m claude-3-opus-20240307 'Write a poem' | |
llm -m gpt4allUse local GPT4All model (offline) | Intermediate | llm -m gpt4all 'What is Rust used for?' | |
llm -m ollamaUse Ollama-managed local model | Intermediate | llm -m ollama 'Tell me a joke' | |
llm -sSet system prompt | Basic | llm -s 'You are a pirate' 'How do I make coffee?' | |
llm logsView recent conversation history | Basic | llm logs | |
llm logs -nShow last N conversation records | Basic | llm logs -n 20 | |
llm -cContinue last conversation (appends to context) | Intermediate | llm -c 'Tell me more about that' | |
llm chatStart interactive chat mode | Basic | llm chat | |
llm chat -mSpecify model in interactive mode | Basic | llm chat -m claude-3-haiku-20240307 | |
llm keysList configured API keys | Basic | llm keys | |
llm keys setSet an API key | Basic | llm keys set openai | |
llm keys getGet stored API key value | Basic | llm keys get openai | |
pip install llmInstall llm CLI tool | Basic | pip install llm | |
pip install llm-claude-3Install Claude plugin | Basic | pip install llm-claude-3 | |
llm pluginsList installed plugins | Basic | llm plugins | |
llm templatesList prompt templates | Intermediate | llm templates | |
llm templates editEdit a prompt template | Intermediate | llm templates edit my-template |
ai-embedding(4)
| Command | Level | ||
|---|---|---|---|
llm embedGenerate text embeddings | Intermediate | llm embed -m text-embedding-3-small -i 'Hello world' | |
llm embed-multiBatch generate embeddings (from file) | Expert | llm embed-multi articles -m text-embedding-3-small -d articles.jsonl | |
llm embed-multi --filesBatch embed from directory files | Expert | llm embed-multi docs -m text-embedding-3-small --files ./docs/ '*.md' | |
llm similarQuery semantically similar text | Expert | llm similar articles -c 'machine learning' |