Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ verified, tried, and decided belongs in the commit message and the PR body.
- **Don't widen the AMD matcher to a bare `amdgpu` match.** ROCm fails on integrated Radeon, and StartOS's regex engine has no lookahead to exclude them, so it stays a positive allowlist of discrete product names.
- **Don't shorten the health check's one-hour grace period.** It covers the model download on first start.
- **New presets go in `startos/actions/presets.ts`**, with `minMemoryGB` set to the weights plus roughly 25% for the KV cache.
- **Keep the Web UI host on Basic auth and the API host on Bearer.** One binding takes one `ProxyAuth`, and StartOS enforces it on the bridge address too, so moving siblings to `api-multi` or merging the hosts locks out browsers or other services.
57 changes: 38 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,23 @@ The AMD requirement matches discrete cards by product name rather than excluding

One volume, and most of it is downloaded models.

| Volume | Mount Point | Purpose |
| ------ | ----------- | ------------------------------------------------------------------------------- |
| `main` | `/data` | `store.json`, the GGUF model cache under `models/`, and HuggingFace's own cache |
| Volume | Mount Point | Purpose |
| -------- | ----------- | ------------------------------------------------------------------------------------------ |
| `main` | `/data` | `store.json`, the GGUF model cache under `models/`, and HuggingFace's own cache |
| `public` | (none) | `credentials.json` with the API key; dependent services mount it read-only to read the key |

Models are the bulk of it — a single quantized model runs from roughly one to forty gigabytes depending on size.

llama.cpp keeps the cache in the HuggingFace hub layout: each repo is `models/models--<org>--<repo>/`, with the weights in `blobs/` and `snapshots/<commit>/<file>.gguf` as symlinks into them. Deleting a file under `snapshots/` frees nothing; a model's space is reclaimed by removing its whole repo folder.

## File Models

One model. Two of its keys decide whether the service can run at all; the third only exists so a form can remember what you last told it.
Two models. Two of `store.json`'s keys decide whether the service can run at all; the others only exist so a form can remember what you last told it.

| File | Format | Modelled | Written by |
| ------------ | ------ | ----------------------- | ----------------------------------------- |
| `store.json` | JSON | Yes — `FileHelper.json` | The Set Model and Set UI Password actions |
| File | Format | Modelled | Written by |
| ------------------ | ------ | ----------------------- | ------------------------------------------ |
| `store.json` | JSON | Yes — `FileHelper.json` | The Set Model and Set UI Password actions |
| `credentials.json` | JSON | Yes — `FileHelper.json` | Init (when missing) and the API Key action |

| Key | Notes |
| ---------------- | ----------------------------------------------------------------------------------------------- |
Expand All @@ -82,6 +84,8 @@ One model. Two of its keys decide whether the service can run at all; the third

Nothing else writes the file, and neither `serveArgs` nor `uiPassword` is defaulted — both are absent until you run their action, and each absence raises a task.

`credentials.json` on the `public` volume holds one key, `apiKey`: the Bearer token for the OpenAI-compatible API interface. Init generates it (32 alphanumeric characters) whenever it is missing — on install, on update from a version without it, or after it is deleted — so it is never empty while the service runs.

`modelSelection` holds the chosen `selection` plus a `custom` object with the last Custom submission's fields; picking another entry leaves `custom` in place so Custom stays prefilled. `modelSettings` is a list of `{hfRepo, hfFile, ctx, ngl, extraArgs}`, one per model, replaced on each submit of that model. Entries are matched to the list by the weights they resolve to — the same cached file, or the same quant tag before download — so a Custom model keeps its settings once it shows up as a downloaded entry. Stores from before `modelSettings` fall back to `modelSelection.custom`. The daemon reads neither, so they cannot disagree with `serveArgs` about what is actually running — at worst they prefill a form with a stale answer.

**No configuration file reaches the application.** Two environment variables are set, both redirecting caches onto the volume so downloaded weights survive a container rebuild:
Expand All @@ -99,15 +103,17 @@ None.

## Network Access and Interfaces

One interface, serving both the OpenAI-compatible API and llama.cpp's built-in chat UI.
Two interfaces, on two hosts that both forward to llama-server's internal port 8080. They serve the same thing — the OpenAI-compatible API and the built-in chat UI — and differ only in the credential the StartOS proxy demands.

| Interface | Id | Type | Port | Description |
| ---------------- | ----- | ---- | ---- | ------------------------------------ |
| llama.cpp Server | `api` | ui | 8080 | The API and the built-in chat client |
| Interface | Id | Host | Type | Internal port | Auth at the proxy |
| --------------------- | ------------ | ----------- | ---- | ------------- | ---------------------------------------- |
| Web UI | `api` | `api-multi` | ui | 8080 | Basic, `admin` + `uiPassword` |
| OpenAI-compatible API | `openai-api` | `api-key` | api | 8080 | Bearer, `apiKey` from `credentials.json` |

**Authentication is added by StartOS, not by llama.cpp.** The server itself runs keyless; the binding declares HTTP basic auth at the edge, with the username `admin` and the password from `store.json`. Until a password is set the binding is configured with an empty one — which never serves anything, because the service is blocked from starting by a `critical` task at the same time.
**Authentication is added by StartOS, not by llama.cpp.** The server itself runs keyless. Since StartOS 0.4.1 the proxy enforces a binding's auth on its plaintext bridge address (`10.0.3.1:<port>`) as well as on the LAN, so other services are challenged like any other client. Browsers can only answer a Basic challenge and OpenAI clients only send a Bearer key, which is why there are two hosts.

An OpenAI-compatible client therefore needs those basic-auth credentials as well as whatever it would normally send.
- **Web UI:** until a password is set the binding is configured with an empty one — which never serves anything, because the service is blocked from starting by a `critical` task at the same time.
- **OpenAI-compatible API:** the binding exists only once the key does; init creates it before the interfaces are set. Dependent services resolve this host's bridge address (`apiKeyHostId`, `apiPort` from `startos/utils.ts`) and read the key from the `public` volume. A key of the wrong type or value gets `401` with `WWW-Authenticate: Bearer`.

## Installation and First-Run Flow

Expand All @@ -122,7 +128,7 @@ The first start after choosing a model **downloads it**, which is why the health

## Actions

Three actions, all user-facing.
Four actions, all user-facing.

### Set Model

Expand All @@ -146,6 +152,15 @@ Generates the password for the API and chat UI.
- **Repeat safety:** safe to re-run, but it **replaces** the existing password — every saved client login has to be updated. When a password already exists it asks for confirmation first; the first run does not.
- **Outputs:** the username `admin` and the new password.

### API Key

Shows the Bearer key for the OpenAI-compatible API interface.

- **Input:** one toggle, **Generate a new key**, off by default.
- **What it changes:** nothing when the toggle is off. When on — or when no key exists — it writes a new `apiKey` to `credentials.json`, which rebinds the API host with the new token. llama-server does not restart.
- **Repeat safety:** safe to re-run. Rotating breaks every client still sending the old key; dependent StartOS services that read the key reactively pick up the new one when they restart.
- **Outputs:** the key, masked and copyable.

### Delete Model Cache

Removes one downloaded model to reclaim disk.
Expand Down Expand Up @@ -181,16 +196,16 @@ With no model selected the daemon idles rather than exiting, and the check's fai

## Backups and Restore

The `main` volume is backed up — `sdk.Backups.ofVolumes('main')` — with one exclusion: `setOptions({ exclude: ['models/'] })` leaves out `/data/models`, the model cache. No dump step.
The `main` and `public` volumes are backed up — `sdk.Backups.ofVolumes('main', 'public')` — with one exclusion: `setOptions({ exclude: ['models/'] })` leaves out `/data/models`, the model cache. No dump step.

- **Included:** `store.json` with the model selection and password.
- **Included:** `store.json` with the model selection and password, and `credentials.json` with the API key, so dependent services keep working after a restore.
- **Excluded:** every downloaded model. Weights are re-downloadable from upstream, so the backup stays small rather than being dominated by the cache.
- **Restore:** the selection and password come back and no tasks are raised. The selected model is downloaded again on the first start, inside the health check's one-hour grace.
- **Restore:** the selection, password and API key come back and no tasks are raised. The selected model is downloaded again on the first start, inside the health check's one-hour grace.

## Limitations and Differences

1. **Two settings are required before the service does anything**, and each is enforced by a blocking task rather than defaulted.
2. **Authentication is the reverse proxy's, not llama.cpp's.** Every client, including API clients, must send basic-auth credentials.
2. **Authentication is the reverse proxy's, not llama.cpp's.** Browsers log in to the Web UI interface with Basic auth; API clients send the API key as a Bearer token to the OpenAI-compatible API interface. Neither credential works on the other interface.
3. **Which accelerator variant you get is decided by StartOS**, from the hardware present; it is not a setting.
4. **Integrated AMD graphics fall back to the generic CPU build.** ROCm is matched only for discrete cards.
5. **The Vulkan variant matches Intel GPUs only**, on the `i915` driver.
Expand All @@ -217,17 +232,21 @@ subcontainers:
- detect-mem # temporary; preset sizing
volumes:
main: /data
public: null # credentials.json, read by dependents
file_models:
- store.json
- credentials.json
startos_managed_env_vars:
- LLAMA_CACHE
- HF_HOME
dependencies: []
interfaces:
api: { type: ui, port: 8080 } # basic auth enforced at the edge, username "admin"
api: { type: ui, host: api-multi, port: 8080 } # Basic at the edge, username "admin"
openai-api: { type: api, host: api-key, port: 8080 } # Bearer at the edge, key in public/credentials.json
actions:
- set-model
- set-ui-password
- api-key
- delete-model-cache
tasks:
- { action: set-ui-password, severity: critical }
Expand Down
16 changes: 8 additions & 8 deletions instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@

## What you get on StartOS

- An OpenAI-compatible HTTP API at `<your-interface-url>/v1`, serving one GGUF model at a time.
- The upstream chat UI at the same URL — open the interface in a browser to chat without setting up a client.
- A password-protected login (username `admin`) on the UI and API, so only you can use them. Other StartOS AI apps that depend on llama.cpp (such as Open WebUI) connect over the internal network with no login to copy.
- The upstream chat UI on the **Web UI** interface — open it in a browser to chat without setting up a client. It asks for a login (username `admin`).
- An OpenAI-compatible HTTP API on the **OpenAI-compatible API** interface, at `<interface-url>/v1`, serving one GGUF model at a time. It takes an API key instead of a login. Other StartOS AI apps that connect to llama.cpp (such as Open WebUI) read the key themselves, so there is nothing to copy.
- Curated GGUF presets, plus a Custom option that accepts any HuggingFace GGUF repo.
- Persistent model cache on the package volume — downloads happen once and survive restarts. The cache is excluded from backups; after a restore, the selected model downloads again on first start.

Expand All @@ -24,20 +23,20 @@ Complete both tasks, then start the service from the dashboard. The first launch

### Chat UI

Open the **llama.cpp Server** interface from the Dashboard. Your browser will prompt for a login — enter `admin` and the password from **Set UI Password**. The upstream chat UI is at `/`; pick a conversation and start typing.
Open the **Web UI** interface from the Dashboard. Your browser will prompt for a login — enter `admin` and the password from **Set UI Password**. The upstream chat UI is at `/`; pick a conversation and start typing.

### OpenAI-compatible API

Point any OpenAI-compatible client at the same URL with `/v1` appended:
Use the **OpenAI-compatible API** interface for clients and apps, with `/v1` appended:

- **Base URL:** `<your-interface-url>/v1`
- **Authentication:** the interface is gated by HTTP basic auth — username `admin`, password from **Set UI Password**. Most OpenAI clients only offer an "API key" field (sent as a bearer token), which the proxy won't accept; for those, use a client that supports basic auth, or call the API with `curl -u admin:<password>`.
- **Base URL:** `<api-interface-url>/v1`
- **API key:** the key from the **API Key** action. The Web UI password does not work here, and the key does not work on the Web UI interface.
- **Model name:** llama.cpp serves a single model, so most clients accept any string or an empty value here.

Quick test from the command line:

```sh
curl -s -u admin:<your-ui-password> <your-interface-url>/v1/chat/completions \
curl -s -H "Authorization: Bearer <your-api-key>" <api-interface-url>/v1/chat/completions \
-H "Content-Type: application/json" \
-d '{"messages":[{"role":"user","content":"Say hello in one short sentence."}]}'
```
Expand All @@ -46,6 +45,7 @@ curl -s -u admin:<your-ui-password> <your-interface-url>/v1/chat/completions \

- **Set Model** — switch to a different preset, a model you already downloaded, or a custom GGUF. The form opens on the model you are running, with its settings filled in, so you can change its context size or flags and submit; submitting without changes does not restart anything. Each model remembers its own settings, so switching away and back keeps them. The service restarts with the new weights; uncached models download on this restart.
- **Set UI Password** — generate a new web UI password (username stays `admin`). Use it for first-time setup or to rotate the password later; when rotating, it asks you to confirm, since saved logins stop working.
- **API Key** — show the key for the OpenAI-compatible API interface. Turn on **Generate a new key** to replace it; clients outside StartOS then need the new key, and StartOS apps pick it up when they restart.
- **Delete Model Cache** — pick a downloaded model from the list, with its size, and remove it to reclaim disk space. The model you are currently running can't be deleted; switch to another one with Set Model first. A deleted model will be re-downloaded if you select it again.

## Limitations
Expand Down
61 changes: 61 additions & 0 deletions startos/actions/apiKey.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { credentialsJson } from '../fileModels/credentials.json'
import { i18n } from '../i18n'
import { sdk } from '../sdk'
import { generateApiKey } from '../utils'

const { InputSpec, Value } = sdk

const inputSpec = InputSpec.of({
rotate: Value.toggle({
name: i18n('Generate a new key'),
description: i18n(
'Replace the key. Clients outside StartOS must be updated with the new one; services on this server pick it up when they restart.',
),
default: false,
}),
})

export const apiKey = sdk.Action.withInput(
'api-key',

async ({ effects }) => ({
name: i18n('API Key'),
description: i18n(
'Show the key for the OpenAI-compatible API interface, or generate a new one.',
),
warning: null,
allowedStatuses: 'any',
group: null,
visibility: 'enabled',
}),

inputSpec,

async ({ effects }) => null,

async ({ effects, input }) => {
let key = await credentialsJson.read((c) => c.apiKey).once()
if (input.rotate || !key) {
key = generateApiKey()
await credentialsJson.merge(effects, { apiKey: key })
}

return {
version: '1',
title: i18n('API Key'),
message: i18n(
'Send this key as "Authorization: Bearer <key>" to the OpenAI-compatible API interface. In most clients, set the base URL to that interface\'s address with /v1 appended and paste this as the API key.',
),
result: {
type: 'single',
name: i18n('API Key'),
description: null,
value: key,
masked: true,
copyable: true,
qr: false,
launchable: false,
},
}
},
)
2 changes: 2 additions & 0 deletions startos/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ import { sdk } from '../sdk'
import { setModel } from './setModel'
import { setUiPassword } from './setUiPassword'
import { deleteModelCache } from './deleteModelCache'
import { apiKey } from './apiKey'

export const actions = sdk.Actions.of()
.addAction(setModel)
.addAction(setUiPassword)
.addAction(apiKey)
.addAction(deleteModelCache)
2 changes: 1 addition & 1 deletion startos/backups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { sdk } from './sdk'

export const { createBackup, restoreInit } = sdk.setupBackups(
async ({ effects }) =>
sdk.Backups.ofVolumes('main').setOptions({
sdk.Backups.ofVolumes('main', 'public').setOptions({
exclude: ['models/'],
}),
)
15 changes: 15 additions & 0 deletions startos/fileModels/credentials.json.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { FileHelper, z } from '@start9labs/start-sdk'
import { sdk } from '../sdk'

/**
* On the `public` volume, which dependent services mount read-only to read the
* API host's Bearer key.
*/
const shape = z.looseObject({
apiKey: z.string().optional().catch(undefined),
})

export const credentialsJson = FileHelper.json(
{ base: sdk.volumes.public, subpath: 'credentials.json' },
shape,
)
13 changes: 11 additions & 2 deletions startos/i18n/dictionaries/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ const dict = {
'No model selected. Run the "Set Model" action.': 4,

// interfaces.ts
'llama.cpp Server': 5,
'OpenAI-compatible API and built-in chat UI': 6,
'Web UI': 5,
'The built-in chat UI, for your browser. Log in as "admin" with the password from Set UI Password.': 6,
'OpenAI-compatible API': 54,
'For OpenAI-compatible clients and apps. Requires the key from the API Key action. Append /v1 to the address.': 55,

// actions/setModel.ts
'Set Model': 7,
Expand Down Expand Up @@ -65,6 +67,13 @@ const dict = {
Username: 51,
Password: 52,

// actions/apiKey.ts
'Generate a new key': 56,
'Replace the key. Clients outside StartOS must be updated with the new one; services on this server pick it up when they restart.': 57,
'API Key': 58,
'Show the key for the OpenAI-compatible API interface, or generate a new one.': 59,
'Send this key as "Authorization: Bearer <key>" to the OpenAI-compatible API interface. In most clients, set the base URL to that interface\'s address with /v1 appended and paste this as the API key.': 60,

// init/initializeService.ts
'Generate a password to log in to the llama.cpp web UI': 39,
'Select which AI model llama.cpp should serve': 40,
Expand Down
Loading
Loading