The life agentic

The Python package llm

llm is both a command-line tool and a Python library for working with large language models. It is a good tool when you want prompts, chats, shell pipelines, or Python scripts that you can rerun and adapt.

Compared to GitHub Copilot CLI or OpenCode, llm is less of a full coding agent and more of a flexible interface for model access.

Intended learning outcomes covered on this page

After working through this page, students should be better able to:

What it is good for

Before you install it

You need two separate things:

  1. the llm package itself
  2. access to a model

That second part is important. Installing llm does not automatically give you model access. One common course path is to use the llm-github-copilot plugin so llm can use your GitHub Copilot access. But llm can also use direct API plugins and local-model plugins. See Model access.

Installation

The official docs list several installation methods:

pip

pip install llm

pipx

pipx install llm

uv

uv tool install llm

Homebrew

brew install llm

Use the method that fits how you normally install Python tools.

One common first setup: GitHub Copilot

A common student setup is:

  1. install llm
  2. install the GitHub Copilot plugin
  3. log in with GitHub device authentication
  4. pick a model
  5. run prompts or start a chat

Install the plugin:

llm install llm-github-copilot

Then log in:

llm github_copilot auth login

After that, list the available models:

llm models

Then try a prompt with one of the github_copilot/... models:

llm -m github_copilot/model-name "Give me three short study tips for learning a new CLI tool"

The plugin uses GitHub device login and can reuse GitHub Copilot access instead of requiring a separate API key for a different provider.

If you are using another access route, the exact plugin and authentication flow will differ. See Model access for the overview.

Other common access routes

OpenAI API

OpenAI models work directly in llm once you set a key:

llm keys set openai
llm models
llm -m gpt-4o-mini "Give me three short study tips for learning a new CLI tool"

Anthropic API

Claude models usually mean installing the Anthropic plugin first:

llm install llm-anthropic
llm keys set anthropic
llm models
llm -m claude-haiku-4.5 "Give me three short study tips for learning a new CLI tool"

Local models with Ollama

If you want a local route, install the Ollama plugin and use a model that is available on your Ollama server:

llm install llm-ollama
llm ollama models
llm -m gemma3 "Give me three short study tips for learning a new CLI tool"

The exact model name depends on what is available from your provider or local server. llm models is the quickest way to check.

If you want the deeper local workflow, read Local models and Ollama.

A simple first workflow

These examples use the GitHub-backed route above. If you are using another provider, replace github_copilot/model-name with one returned by llm models.

Some good starter patterns are:

A one-shot prompt

llm -m github_copilot/model-name "Summarize the difference between Copilot CLI and OpenCode in three bullet points"

Use a file as input

cat README.md | llm -m github_copilot/model-name -s "Explain this project to a new student"

Start an interactive chat

llm chat -m github_copilot/model-name

See which models are available

llm models

Look for model names that start with github_copilot/.

Why students often like it

llm is especially useful when you want work that is easy to rerun or turn into a script. With llm-github-copilot, students can often do that using the same GitHub account they already set up for student access. It is often the best choice when you want to:

A small Python example

After installing llm and configuring access to a model, a minimal Python script can look like this:

import llm

model = llm.get_model("your-model-name")
response = model.prompt(
    "Explain when a student should use OpenCode instead of GitHub Copilot CLI."
)
print(response.text())

Use one of the model names returned by llm models, such as a github_copilot/... model, claude-haiku-4.5, gpt-4o-mini, or a local Ollama model.

For guidance on which model fits which kind of task, see Which model should I use?.

That same package also supports attachments, tools, JSON schemas, and async usage.

Course-specific note about model names

In course material you may see examples such as:

llm chat -m kth-gpt-5.2

A model name like kth-gpt-5.2 is not part of the default llm installation. It is an example of a locally configured model or alias.

If you are following the GitHub-backed setup on this page, you will probably start with a model name under github_copilot/....

If you use a direct API or local route instead, you may see names such as claude-haiku-4.5, gpt-4o-mini, or a local Ollama model name.

So there are two separate questions:

  1. how to install and learn llm
  2. which provider, plugin, or local model configuration you will actually use

The first part is general. A common second step in this course is the llm-github-copilot plugin, but it is not the only route.

Privacy and logging

By default, llm logs prompts and responses to a local SQLite database. That is useful for experimentation, but it also means you should think about what data you send to it. For the broader picture of data exposure and the legal side, see Problematic cases of using AI.

Useful commands are:

llm logs status
llm logs off
llm logs on

Good habits

When a model explains a repository, summarises a file, or claims that a command output means something important, verify that claim against the actual files or commands. For a reusable student workflow, read Verification.

How it differs from the coding agents

llm helps most when you want direct control over prompts, scripts, logs, and structured output. That makes it a useful contrast case:

If you want the shared concepts across the coding-agent tools, read Agentic concepts.

Short version

  1. Install llm.
  2. Choose one access route: GitHub Copilot, direct API, or local plugin.
  3. Authenticate or set keys for that route.
  4. Run llm models and use one of the listed model names.
  5. Use the Python API when you want scripts or applications.

Next step