# Local model providers

| Preset | Default | Notes |
| --- | --- | --- |
| [Ollama](https://docs.ollama.com/api/openai-compatibility) | `localhost:11434/v1` | Installed model identifiers. Native management APIs excluded. |
| [LM Studio](https://lmstudio.ai/docs/developer/openai-compat) | `localhost:1234/v1` | Models and streaming chat |
| [vLLM](https://docs.vllm.ai/en/latest/serving/online_serving/openai_compatible_server/) | `localhost:8000/v1` | Optional server API key |
| llama.cpp, generic endpoint | Configured address | Resolved offline |

All go through the Chat Completions transport cloud providers use: streaming, tool calls, cancellation, retries and structured output. The user starts the server, or a call starts it with the user's command when autostart is on; OpenProgram does not install models, allocate GPUs or stop servers.

## Contract

| Aspect | Rule |
| --- | --- |
| Address | Host-only URLs resolve to `/v1` the same way for discovery, validation and inference. Edits apply to later calls, including saved models. |
| Discovery | From the configured server, never a cloud catalogue |
| Credentials | Optional. Never inherits an unrelated OpenAI key. Sent only to the configured endpoint. |
| URL security | Existing configured-URL checks apply |
| Enablement | Persisted through the existing provider and model registry |
| Settings | Address, optional accounts, connectivity, discovery, manual model IDs and limits |
| Errors | Invalid URLs, missing servers, HTTP failures and non-JSON replies are reported as actionable failures |
| Compatibility | Conservative OpenAI compatibility settings |

**Request authentication**

Without a key: an explicit SDK placeholder prevents environment fallback, and each Chat Completions request omits the Authorization header. The omission must be per request, because the SDK authentication validator ignores removal of a default header alone. With a key: the configured server key. Cloud requests still need their own credential.

## Starting the server on demand

1. **Request to a local provider** `stream_simple_with_provider`, before the adapter
2. `providers.<id>.server.autostart` is true and the loopback address does not answer
3. **Start command** own session, output to `logs/local-server-<id>.log`
4. poll the model list every 0.25 s, up to 45 s
5. **The request goes on** or the turn ends with the reason

Code: `models/providers/streaming/local_server.py`; the hook in `models/providers/streaming/stream.py`; settings in `models/providers/settings/storage.py` and the Worker's provider config route; CLI `interfaces/cli/commands/providers/local_server.py`. Tests: `tests/component/providers/test_local_server_autostart.py`, with a fake server program that answers `/v1/models`. User page: [Local models](https://openprogram.io/docs/models/local-models.html).

### Rules

| Part | Rule |
| --- | --- |
| Setting | `providers.<id>.server`: `autostart` (bool, default off) and `command` (an argument list, or one string split like a shell). Only local providers accept it. Changing it clears a remembered failure |
| Default command | Ollama `ollama serve`, LM Studio `lms server start`, when `shutil.which` finds the program. vLLM, llama.cpp and custom servers have none: their command names the model |
| When it runs | Only with autostart on, only for a loopback address, only when the cached probe (at most 2 s old) says down. A remote address is never started. The cheap check reads the provider config before anything else, so a provider without the setting pays nothing |
| Concurrency | One lock per base URL; a call that waited probes again before starting, so parallel calls start the server once |
| Ready | The server lists its models. A launcher that exits 0 (`lms server start`) is waited for; a non-zero exit ends the wait at once with the log's last five lines |
| Failure | `LocalServerStartError` with the provider, address, command and the log path. It is remembered for 60 s, so a turn's retries do not each wait out the 45 s |
| Stopping | Never. A server that already answers is left alone; one started here runs in its own session and outlives the Worker, as if the person had started it from a terminal. The Worker only collects its exit |
| Approval | None. Turning the setting on is the consent; the command is the person's own |

### Why this shape

| Peer | What it does, and what we take |
| --- | --- |
| Hermes | `hermes_cli/local_runtime/supervisor.py` owns a llama-server: picks a port, downloads binaries, waits up to 120 s for `/health`, stops it and its children. That is a model runtime; OpenProgram connects to the server the person chose, so it takes only the bounded readiness wait and the log file |
| Pi | The llama.cpp router loads models on demand but the person starts the server (docs/llama-cpp.md). Autostart closes that gap without taking over the lifecycle |
| Copilot CLI | Discovers a running Ollama and does not start it. Discovery stays as it is; starting is opt-in per provider |

## Implementation status

Inference against a real locally deployed model has not been exercised end to end; it needs an operator-provided server.

The setting is set from the CLI (`openprogram providers local-server`) and the provider config route (`server_autostart`, `server_command`). The Web provider panel has no control for it yet.
