# Local models (/docs/fleet/local)

> For AI agents, the [documentation index](https://bitrouter.ai/llms.txt) lists all pages. Append .md to a documentation URL to read its Markdown.

Run any model on your own GPUs and call it through the Spare API, next to Spare's models and
[your own Claude or OpenAI key](https://bitrouter.ai/docs/fleet/byok). Your hardware answers first. When it's busy or
offline, requests can overflow to the Spare market at the [live price](https://bitrouter.ai/docs/pricing), so your app
never waits on a full server.

* **Any model.** Whatever you run in vLLM, SGLang, Ollama or another OpenAI-compatible server.
* **Free.** Requests your GPUs answer cost nothing. Only overflow to the market is billed.
* **No open ports.** The [CLI proxy](https://bitrouter.ai/docs/fleet/local#proxy-configuration) connects out to Spare from your network.

## How it works \[#how-it-works]

1. **Connect your server.** Run the CLI proxy, `spare-proxy`, next to it. It registers your model under
   a name you choose, and reports how much load your server can take.
2. **Call it by name.** Your local model's id is `local/<name>`. It shows up in
   [`GET /v1/models`](https://bitrouter.ai/docs/api/models) for your key, and works on every endpoint.
3. **Overflow when full.** If you set an overflow model, requests go there whenever your server is at
   its limit or offline.

```python
resp = client.chat.completions.create(
    model="local/my-coder",
    messages=[{"role": "user", "content": "Write a unit test for parse_date"}],
)
```

The proxy knows your server's load before a request is sent, so a full server doesn't cost a failed
attempt: the request goes straight to the overflow model.

Setting up takes three steps: serve the model, write a `spare-proxy.yaml` for your engine, then
[run the proxy](https://bitrouter.ai/docs/fleet/local#run-the-proxy).

## vLLM \[#vllm]

```bash
vllm serve Qwen/Qwen3-Coder-30B-A3B-Instruct \
  --served-model-name my-coder \
  --tensor-parallel-size 2 \
  --port 8000
```

* Use any model vLLM supports. `--served-model-name` is the name your server answers to.
* vLLM listens on `http://localhost:8000/v1` and exposes Prometheus metrics at `/metrics`, which the
  proxy reads to know how busy the server is.
* **Leave prefix caching on.** It's on by default in vLLM, and agents that reuse long prompts get much
  faster.
* **Keep vLLM private.** The proxy reaches it on localhost, so there's no need to bind vLLM to a public
  address or open its port.

```yaml title="spare-proxy.yaml"
mode: private
name: my-coder                         # your model's id becomes local/my-coder
upstream: http://localhost:8000/v1
upstream_model: my-coder               # the --served-model-name above

load:
  engine: vllm                         # reads vllm:num_requests_running,
  metrics: http://localhost:8000/metrics  # vllm:num_requests_waiting, vllm:kv_cache_usage_perc
  max_waiting: 4                       # full when more requests than this are queued

overflow: deepseek-v4.1-flash          # optional
```

## SGLang \[#sglang]

```bash
python -m sglang.launch_server \
  --model-path Qwen/Qwen3-Coder-30B-A3B-Instruct \
  --served-model-name my-coder \
  --tp 2 \
  --port 30000 \
  --enable-metrics
```

* Use any model SGLang supports. `--served-model-name` is the name your server answers to.
* `--enable-metrics` exposes Prometheus metrics at `/metrics`, which the proxy reads to know how busy
  the server is. With a config file (`--config config.yaml`), set `enable-metrics: true` there.
* SGLang binds to `127.0.0.1` by default. Keep it that way: the proxy reaches it locally.
* **RadixAttention caches shared prefixes** automatically, so agents that reuse long prompts get much
  faster.

```yaml title="spare-proxy.yaml"
mode: private
name: my-coder                          # your model's id becomes local/my-coder
upstream: http://localhost:30000/v1
upstream_model: my-coder                # the --served-model-name above

load:
  engine: sglang                        # reads sglang:num_running_reqs,
  metrics: http://localhost:30000/metrics  # sglang:num_queue_reqs, sglang:token_usage
  max_waiting: 4                        # full when more requests than this are queued

overflow: deepseek-v4.1-flash           # optional
```

## Ollama \[#ollama]

Ollama is the quickest way to run a model on a laptop or a single workstation, with Spare's market as
overflow when your machine is busy, asleep or off.

```bash
ollama pull qwen3-coder
ollama serve
```

Ollama serves an OpenAI-compatible API at `http://localhost:11434/v1`.

```yaml title="spare-proxy.yaml"
mode: private
name: my-coder                         # your model's id becomes local/my-coder
upstream: http://localhost:11434/v1
upstream_model: qwen3-coder            # the Ollama model name

load:
  engine: none                         # Ollama has no load metrics
  max_concurrency: 2                   # full above this many requests in flight

overflow: deepseek-v4.1-flash          # optional
```

Ollama doesn't publish load metrics, so the proxy counts requests in flight instead. Match
`max_concurrency` to `OLLAMA_NUM_PARALLEL` if you've set it.

## Run the proxy \[#run-the-proxy]

```bash
docker run -d --name spare-proxy --network host \
  -e SPARE_API_KEY \
  -v "$PWD/spare-proxy.yaml:/etc/spare-proxy.yaml" \
  ghcr.io/spareinference/spare-proxy:latest
```

`SPARE_API_KEY` is the same key you use to call the API.

## Check it works \[#check-it-works]

```bash
docker exec spare-proxy spare-proxy status
```

```bash
curl -si https://api.spareinference.ai/v1/chat/completions \
  -H "Authorization: Bearer $SPARE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model":"local/my-coder","messages":[{"role":"user","content":"Reply with OK"}]}' \
  | grep -i '^x-bitrouter-request-id'
```

Open the console's **Activity** page: the request's model shows `local/my-coder` when your server answered.
Stop your server and send it again: with `overflow` set, the request is answered by `deepseek-v4.1-flash`
instead.

## Overflow \[#overflow]

Set `overflow` in the proxy config to send requests to a Spare model when your server can't take them:

```yaml
overflow: deepseek-v4.1-flash
```

For a longer chain, such as your server, then Spare, then your Claude model, define it in the CLI; see
[Fall back to a different model](https://bitrouter.ai/docs/fleet/fallbacks). The console's
**Activity** page shows which model answered each request.

## Proxy configuration \[#proxy-configuration]

```yaml title="spare-proxy.yaml"
mode: private                    # private, or sell
name: my-coder                   # private: your model's id becomes local/<name>
upstream: http://localhost:8000/v1
upstream_model: my-coder         # the model name your server answers to

load:
  engine: vllm                   # vllm, sglang, or none
  metrics: http://localhost:8000/metrics
  max_waiting: 4                 # vllm, sglang: full above this many queued requests
  max_concurrency: 8             # none: full above this many requests in flight

overflow: deepseek-v4.1-flash    # private: where requests go when your server is full
```

| Option                 | Required     | What it does                                                                                                                                                       |
| ---------------------- | ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `mode`                 | yes          | `private` serves only your own requests. `sell` also offers spare capacity to the market; see [Sell spare capacity](https://bitrouter.ai/docs/sell-spare-capacity) |
| `name`                 | private      | Your model's id is `local/<name>`. Proxies with the same name share the traffic                                                                                    |
| `upstream`             | yes          | Your server's OpenAI-compatible base URL                                                                                                                           |
| `upstream_model`       | yes          | The model name sent to your server                                                                                                                                 |
| `load.engine`          | yes          | Where load comes from: the engine's Prometheus metrics, or `none` to count requests in flight                                                                      |
| `load.metrics`         | vllm, sglang | Your server's metrics URL                                                                                                                                          |
| `load.max_waiting`     | no           | Queued requests above which the server counts as full. Default 4                                                                                                   |
| `load.max_concurrency` | none         | Requests in flight above which the server counts as full                                                                                                           |
| `overflow`             | no           | A Spare model to send requests to when your server is full or offline                                                                                              |

Changes to the file are picked up within a few seconds.

```bash
docker exec spare-proxy spare-proxy status   # connection, load, requests served today
docker exec spare-proxy spare-proxy pause    # stop taking requests; in-flight ones finish
docker exec spare-proxy spare-proxy resume
```

While paused, requests to `local/<name>` go to the overflow model, or fail with a 503 if none is set.

## Billing \[#billing]

| Who answered                  | Cost                                      |
| ----------------------------- | ----------------------------------------- |
| Your GPUs                     | Free                                      |
| A Spare model, after overflow | The live price of the window              |
| Your Claude or OpenAI model   | Billed by your provider, through your key |

## Good to know \[#good-to-know]

* **Outbound only.** The proxy connects to Spare over TLS; your server and its port stay private.
* **Your key, your model.** Only requests made with keys in your account can reach `local/<name>`.
* **We don't store requests.** Bodies pass through Spare to your server without being logged; we keep
  token counts and timings for your usage records.
* **One extra hop.** Requests travel from your app to Spare and back to your server, which adds network
  latency compared with calling your server directly. Run the proxy close to your server.
* **Several servers, one name.** Run a proxy on each and give them the same name; requests spread across
  them by load.
* **Sell what you don't use.** If you serve a model Spare sells with vLLM or SGLang, the same proxy can
  [sell your spare capacity](https://bitrouter.ai/docs/sell-spare-capacity) too: serve the exact snapshot Spare lists and
  declare its precision. Ollama models can be used privately only.