Pi School

Lesson 6

Models

Choose and configure AI models in Pi.

The model you choose is probably the single most important factor in how successful your Pi sessions will be. State-of-the-art models from Anthropic, OpenAI, and Google are highly capable — they write better code, reason through complex problems, and make fewer mistakes. But they cost money per request. Free models cost nothing but don’t match the top models on difficult tasks. Using Pi well means finding the right balance between cost and capability for what you’re trying to do.

An AI model is the engine behind that capability. When you type a message, it’s a model that reads it and figures out how to respond — whether that’s writing code, explaining an error, or running a command.

See which model you’re using

Your current model is shown in the footer at the bottom of the terminal, along with your working directory, session name, and context usage.

Change the model

Type /model to open the model picker, or press Ctrl+L. Your choice applies to the current session; press Ctrl+S in the picker to save it as the default for new sessions.

If the model supports extended thinking, /thinking picks a thinking level, and Shift+Tab cycles through levels. The editor’s border color changes to show the current level.

Once you’ve picked a shortlist of models you switch between often (via /scoped-models or the enabledModels setting), Ctrl+P and Shift+Ctrl+P cycle through just that list, which is faster than opening the full picker every time.

Connecting a model

As covered in the Installation lesson, /login is how you connect a model provider:

  • ChatGPT Plus or Pro: choose OpenAI, then Sign in with ChatGPT. This is OpenAI’s official way to use your plan in third-party tools like Pi. The safest subscription path.
  • A free OpenRouter account: choose OpenRouter, sign in through your browser, and pick a model tagged :free (for example google/gemma-4-31b-it:free). Zero cost, no local compute required.
  • Claude Pro/Max and GitHub Copilot both show up as /login options, but using them through Pi violates Anthropic’s and GitHub’s terms of service, respectively — both have real enforcement history. Stick with Sign in with ChatGPT, OpenRouter, or an API key.

Cloudflare

If you already have a Cloudflare account, you can use it as a model provider. One bill, no extra subscriptions.

AI Gateway routes requests to OpenAI, Anthropic, and Workers AI through a single Cloudflare bill. Set CLOUDFLARE_API_KEY via /login, plus CLOUDFLARE_ACCOUNT_ID and CLOUDFLARE_GATEWAY_ID as environment variables:

export CLOUDFLARE_API_KEY=...           # or use /login
export CLOUDFLARE_ACCOUNT_ID=...
export CLOUDFLARE_GATEWAY_ID=...        # create at dash.cloudflare.com → AI → AI Gateway
pi --provider cloudflare-ai-gateway --model "claude-sonnet-5"

Workers AI runs open-source models directly on Cloudflare’s network. It’s more limited than AI Gateway since it only hosts the models Cloudflare provides, but it’s there if you want it:

export CLOUDFLARE_API_KEY=...           # or use /login
export CLOUDFLARE_ACCOUNT_ID=...
pi --provider cloudflare-workers-ai --model "@cf/moonshotai/kimi-k2.6"

The “Use an AI gateway” exercise covers the full setup once you’ve finished the lessons.

Local models

If you’d rather run models on your own computer, Pi connects directly to the llama.cpp router. Start llama-server without a model (router mode), then inside Pi:

  • /login llama.cpp stores the router’s URL (http://127.0.0.1:8080 by default).
  • /llama loads and unloads models, and can search Hugging Face and download new ones.
  • /model picks a loaded model.

Ollama, LM Studio, vLLM, and other OpenAI-compatible servers work too, configured in ~/.pi/agent/models.json. Local models are free and private, but they need a capable machine, and small ones are noticeably weaker at agentic work than flagship models. See Pi’s llama.cpp guide for the full setup.

Every model also has a context window — a limit on how much conversation it can hold at once. The next lesson covers what that means in practice and how Pi manages it.