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 lets you run prompts directly from the command line with llm 'your prompt', or the equivalent llm prompt 'your prompt'. The default model is gpt-4o-mini (requires an OpenAI API key), but you can swap in any installed model with a single flag. Responses stream to your terminal as they arrive, and every exchange is automatically saved to a local SQLite database.

Executing a Prompt

1

Run a basic prompt

Tokens stream to your terminal as they arrive:
llm 'Ten names for cheesecakes'
Disable streaming and wait for the complete response:
llm 'Ten names for cheesecakes' --no-stream
2

Choose a model

Pass -m with a model ID or alias:
llm 'Ten names for cheesecakes' -m gpt-4o
Use -q once or more to fuzzy-search for a model by substring — LLM picks the shortest matching ID:
llm 'Ten names for cheesecakes' -q 4o -q mini
Set the LLM_MODEL environment variable to change the default for the current shell session:
export LLM_MODEL=gpt-4.1-mini
llm 'Ten names for cheesecakes'
3

Pipe content in

Send text to standard input directly:
echo 'Ten names for cheesecakes' | llm
Combine piped content with a prompt argument (piped content comes first):
cat myscript.py | llm 'explain this code'

Model Options

Some models expose configurable parameters. Pass them with -o name value:
llm 'Ten names for cheesecakes' -o temperature 1.5
List every model with its supported options:
llm models --options
Show options for a specific model only:
llm -m gpt-4o --options

Attachments

Multi-modal models such as gpt-4o and gpt-4o-mini accept images, PDFs, audio, and video as attachments. Pass them with -a:
llm "describe this image" -a https://static.simonwillison.net/static/2024/pelicans.jpg
Use llm models --options to see which attachment types each model supports. Any model that accepts images also accepts PDFs.

System Prompts

Use -s / --system to prepend a system prompt that instructs the model before your user prompt:
llm 'SQL to calculate total sales by month' \
  --system 'You are an exaggerated sentient cheesecake that knows SQL'
System prompts are especially useful when piping content:
git diff | llm -s 'Describe these changes'
Save a system prompt as a template to reuse it later:
llm -s 'write pytest tests for this code' --save pytest
cat llm/utils.py | llm -t pytest

Extracting Fenced Code Blocks

When you ask an LLM to write code, it typically wraps the output in a Markdown fenced block. The -x / --extract flag returns only the content of the first such block:
llm 'write a Python hello-world script' -x
Use --xl / --extract-last to return the last fenced block instead. The full response (including surrounding text) is still saved to the log database.

Schemas

Models from OpenAI, Anthropic, and Google Gemini can return structured JSON matching a schema. Pass the schema inline, as a file, or using LLM’s concise shorthand:
# Concise shorthand
llm --schema 'name,bio' 'invent a dog'

# Multiple items
llm --schema-multi 'name,bio' 'invent two dogs'

# From a file
llm --schema dogs.schema.json 'invent two dogs'
See the schemas documentation for the full schema DSL and how to query schema output from logs.

Fragments

Fragments let you inject reusable blocks of text (files, URLs, or saved aliases) into a prompt without duplicating the content in the database:
llm -f https://llm.datasette.io/robots.txt 'explain this'
llm -f cli.py 'a short poem inspired by this code'
See the fragments documentation for full details.

Continuing a Conversation

By default each llm invocation starts a fresh conversation. Pass -c / --continue to continue the most recent one:
llm 'More names' -c
--continue automatically uses the same model as the conversation you are continuing. To continue a specific past conversation, supply its ID:
llm 'More names' --cid 01h53zma5txeby33t1kbe3xk8q
Find conversation IDs with llm logs.

Additional Flags

FlagDescription
--no-streamWait for the full response before printing
--asyncRun the prompt asynchronously
-u / --usagePrint token usage after the response
-n / --no-logSkip saving this prompt to the database
--logForce logging even when logging is disabled globally

Starting an Interactive Chat

llm chat opens a persistent interactive session. This is especially useful for local models so they do not have to reload into memory for each prompt.
llm chat -m gpt-4o
Start a chat that continues your most recent conversation:
llm chat -c
Pass a system prompt and options the same way as with llm prompt:
llm chat -m gpt-4 -s 'You are a sentient cheesecake' -o temperature 0.5
Or use a saved template:
llm --system 'You are a sentient cheesecake' -m gpt-4 --save cheesecake
llm chat -t cheesecake

Chat Commands

Once inside a chat session, several special commands are available:
Type !multi to begin a multi-line block, then !end to submit it:
> !multi
Explain this error:
urllib.error.URLError: <urlopen error [Errno 8] nodename nor servname provided>
!end
Use a custom delimiter if your text contains !end:
> !multi custom-end
...your text...
!end custom-end
Type !edit to open the prompt in your $EDITOR before sending:
> !edit
Inject one or more fragments into the current turn:
> !fragment https://llm.datasette.io/en/stable/fragments.html
Combine with !multi:
> !multi
Explain the difference between fragments and templates
!fragment https://llm.datasette.io/en/stable/fragments.html https://llm.datasette.io/en/stable/templates.html
!end
Type exit or quit followed by Enter to leave the chat.
llm chat accepts the same --tool/-T and --functions options as llm prompt, letting you start a chat with specific tools already enabled.

Listing Available Models

llm models
Example output:
OpenAI Chat: gpt-4o (aliases: 4o)
OpenAI Chat: gpt-4o-mini (aliases: 4o-mini)
OpenAI Chat: o1-preview
OpenAI Chat: o1-mini
Search by substring with -q:
llm models -q gpt-4o
llm models -q 4o -q mini
Show specific models by ID or alias with -m:
llm models -m gpt-4o -m gpt-4.1
Add --options to display parameter documentation alongside each model:
llm models --options

Setting Default Options for Models

Configure a persistent default option for a model with llm models options set:
llm models options set gpt-4o temperature 0.5
The option is stored in model_options.json in the LLM config directory and applied automatically on every subsequent prompt.
# List all configured defaults
llm models options list

# Show defaults for one model
llm models options show gpt-4o

# Clear a single default
llm models options clear gpt-4o temperature

# Clear all defaults for a model
llm models options clear gpt-4o
Default model options apply to both llm prompt and llm chat but are not used when calling LLM as a Python library.

Build docs developers (and LLMs) love