# Own providers and local models

> Your own provider in Buff Code: OpenRouter, Anthropic, OpenAI, LiteLLM, Ollama, LM Studio. What goes to Buff and what stays on the machine.

Besides the [organisation’s models](/en/docs/buff-code/models), Buff Code also works with your own
providers: a subscription or an API key with a cloud provider, a corporate proxy such as
LiteLLM, or a model running on your own machine. Signing in to Buff is not needed for this. If you sign in,
the organisation’s models are shown next to your own, and the model is chosen per session.

## What goes to Buff and what does not

A request to your own model goes from your machine straight to the provider, bypassing
the [connector gateway](/en/docs/buff-code/gateway). The provider gets no Buff headers (session, client, organisation,
project).

Turns on your own model do not reach Buff. There is no log, no tokens and no charges. Accounting is done
**strictly per turn**:

- **A session entirely on your own model** does not appear in [development sessions](/en/docs/buff-code/sessions/view).
- **A mixed session** (some turns on a Buff model, some on your own) is visible, but only with its Buff
  turns. Tokens and charges in it are also counted only for the Buff turns.
- Projects, settings and git marks are sent as usual if you are signed in to Buff.

Buff’s tools — the [knowledge base](/en/docs/buff-code/knowledge),
the [project’s repositories](/en/docs/buff-code/repositories) and
the [connection tools](/en/docs/buff-code/tools) — also work on your own model if you are signed in to
Buff and have chosen a context.

## A provider from the catalogue

The catalogue lists well-known providers: Anthropic, OpenAI, Google, OpenRouter, GitHub Copilot,
OpenCode Zen and others. The key or the subscription sign-in is stored only on your machine. OpenCode Zen
works with a key or a sign-in to OpenCode Console: OpenCode’s free tier is available only in
OpenCode itself, so its models are not in Buff Code.

- **In the window**: “Settings” → “Providers” → “Connect” next to the provider you need, or “Show
  all”. From the Buff sign-in window, “Connect another provider” leads to the same place.
- **In the terminal interface**: the `/connect` command.
- **In the console**:

```bash
buff auth login            # choose a provider from the list
buff auth login openrouter # go straight to the one you need
buff auth list             # what is connected
buff auth logout           # disconnect
```

The connected provider’s models appear in the model choice (`/models`, `buff models`) under its
name, for example `openrouter/qwen/qwen3-coder`.

## Your own address: LiteLLM, Ollama, LM Studio, vLLM

A server that speaks the OpenAI API is connected with a `provider` block in the configuration:

- on your machine, for all projects: `~/.config/buff/buffcode.jsonc`;
- in the project, for everyone who opens it: `buffcode.json` in the root. Do not put the key there — the file
  goes into the repository.

The older `opencode.json` / `opencode.jsonc` files are read too.

### LiteLLM or another proxy

```jsonc
{
  "provider": {
    "litellm": {
      "name": "LiteLLM",
      "npm": "@ai-sdk/openai-compatible",
      "options": {
        "baseURL": "https://litellm.example.com/v1",
        "apiKey": "{env:LITELLM_API_KEY}"
      },
      "models": {
        "gpt-4.1": { "name": "GPT-4.1 via LiteLLM" },
        "claude-sonnet": { "name": "Claude Sonnet via LiteLLM" }
      }
    }
  }
}
```

`{env:LITELLM_API_KEY}` substitutes the value of the environment variable, and `{file:~/.secrets/litellm}`
reads it from a file. This way the key does not end up in the config itself.

### Ollama

```jsonc
{
  "provider": {
    "ollama": {
      "name": "Ollama",
      "npm": "@ai-sdk/openai-compatible",
      "options": { "baseURL": "http://127.0.0.1:11434/v1" },
      "models": { "qwen2.5-coder:14b": { "name": "Qwen 2.5 Coder 14B" } }
    }
  }
}
```

The model name is the one it is loaded under in Ollama (`ollama list`).

### LM Studio and vLLM

The same, with a different address. LM Studio listens on `http://127.0.0.1:1234/v1` by default, vLLM —
on `http://127.0.0.1:8000/v1`. Models are named the way the server returns them in `/v1/models`.

For agentic work the model must support tool calling. Without it the model
answers in text, but does not edit files or run commands.

## Which model is chosen

- The model named in `model` in the configuration (for example, `"model": "ollama/qwen2.5-coder:14b"`)
  is chosen by default.
- Otherwise — the last model you chose.
- If you have not chosen anything yet, the Buff model is taken, and without a Buff sign-in — the first of the
  connected ones.

For a one-off command the model is set with a flag:

```bash
buff run --model ollama/qwen2.5-coder:14b "explain this module"
```

Without a Buff sign-in and without a connected provider, Buff Code tells you what to do: sign in to Buff
or connect your own provider.
