A walkthrough for connecting the Pi coding agent CLI to a local model served by LM Studio — no API key, no cloud, fully offline inference.

Why do this

Pi defaults to cloud providers (Anthropic, OpenAI, etc.) that need OAuth or an API key. If you’d rather run a model locally — for privacy, cost, or offline use — you can point Pi at any OpenAI-compatible local server instead. LM Studio is one of the easiest ways to stand one up.

Prerequisites

  • Pi installed (npm install -g --ignore-scripts --min-release-age=0 @earendil-works/pi-coding-agent)
  • LM Studio installed
  • A model downloaded in LM Studio (this guide uses Qwen3.5 9B)

Step 1: Start LM Studio’s local server

  1. Open LM Studio and go to the Developer tab in the left sidebar.
  2. Load your model at the top of the panel (in this case, qwen/qwen3.5-9b).
  3. Toggle Status to Running. LM Studio confirms it’s reachable at http://127.0.0.1:1234.

Verify it’s actually serving requests:

bash

curl http://localhost:1234/v1/models

This should return JSON listing your loaded model. If you get curl: (7) Failed to connect, the server toggle isn’t on yet — go back and flip it.

Note the exact model identifier from the response (or from LM Studio’s API Usage → API Model Identifier field, shown under the model’s Info panel). It has to match exactly — for Qwen3.5 9B in MLX format, that’s qwen/qwen3.5-9b.

Step 2: Tell Pi about the local provider

Pi reads custom providers from ~/.pi/agent/models.json. Create it:

bash

mkdir -p ~/.pi/agent
nano ~/.pi/agent/models.json

Contents:

json

{
  "providers": {
    "lmstudio": {
      "baseUrl": "http://127.0.0.1:1234/v1",
      "api": "openai-completions",
      "apiKey": "lm-studio",
      "models": [
        { "id": "qwen/qwen3.5-9b" }
      ]
    }
  }
}

A few notes on this config:

  • baseUrl points at LM Studio’s local server, with /v1 appended.
  • api: "openai-completions" — LM Studio speaks the OpenAI Chat Completions format.
  • apiKey is required by Pi’s config schema even though LM Studio ignores it. Any non-empty string works; "lm-studio" is just a convention.
  • id must match the identifier LM Studio reports exactly, or Pi won’t find the model.
  • No // comments in this file — Pi’s JSON parser fails silently if you add any.

Save and exit (in nano: ctrl+o, enter, ctrl+x).

Step 3: Run Pi against the local model

bash

pi --provider lmstudio --model qwen/qwen3.5-9b

Or launch pi plain and switch providers interactively with /model — the config file reloads automatically each time you open that menu, so edits don’t require a restart.

Troubleshooting

“No API key found for the selected model” (looping) Pi is still trying to use a cloud provider because it doesn’t see a working local config yet. Exit with ctrl+c, confirm models.json exists and is valid JSON, and confirm the LM Studio server is running (curl http://localhost:1234/v1/models).

curl: (7) Failed to connect to localhost port 1234 The LM Studio server toggle is off. Go to Developer → Local Server and turn it on.

Model doesn’t show up in /model Double check the id in models.json matches LM Studio’s reported model id exactly, and that the JSON is valid (no trailing commas, no comments).

Recap

  1. Load model + start server in LM Studio (Developer tab).
  2. Confirm reachability with curl http://localhost:1234/v1/models.
  3. Write ~/.pi/agent/models.json with a custom lmstudio provider pointing at http://127.0.0.1:1234/v1.
  4. Run pi --provider lmstudio --model <id>.