How to run rustingstrata serve for other people, for example to sell API access to a model. Flags that are not
about hosting are in USAGE.md.
The license allows commercial services built on RustingStrata. Keep the license and the credit to the original author. You may not sell RustingStrata itself. The model has its own license (most Qwen models are Apache 2.0; check the model card).
On a Linux machine with an NVIDIA driver (or a Vulkan 1.3 driver):
# 1. The binary: a release binary, or one built on this machine.
cargo build --release
sudo install -m 755 target/release/rustingstrata /usr/local/bin/rustingstrata
# 2. A service user, a model, and the calibration (once per model and machine). Calibrate as the service user,
# with the --ctx and --kv of the server.
sudo useradd --system --create-home --home-dir /var/lib/strata strata
sudo usermod -aG video,render strata # GPU device access on most distributions
M=/srv/models/Qwen3.6-35B-A3B-UD-Q2_K_XL.gguf
sudo -u strata rustingstrata calibrate --model $M --ctx 32768 --kv q8
# 3. Keys: one admin key, and a file of customer keys.
openssl rand -hex 24 # run once per key
sudo mkdir -p /etc/strata
sudo tee /etc/strata/keys.txt >/dev/null <<'EOF'
# name key
acme 3f9c0d6e5b...
beta-corp a81e44f2c7...
EOF
sudo chown strata /etc/strata/keys.txt && sudo chmod 600 /etc/strata/keys.txt
# 4. Run it on the loopback address. Only the reverse proxy faces the network.
sudo -u strata env STRATA_API_KEY=<admin key> rustingstrata serve --model $M --gpu --ctx 32768 --addr 127.0.0.1:8080 \
--api-keys /etc/strata/keys.txt --usage-log /var/lib/strata/usage.jsonl --max-tokens 4096 --parallel 4 --kv q8 \
--max-per-key 4Clients use https://api.example.com/v1 (OpenAI) or https://api.example.com (Anthropic, POST /v1/messages) with
their key. The request fields are in USAGE.md. A streamed reply reports its usage in the last chunk.
| Key | Set with | Reaches |
|---|---|---|
| Admin | --api-key, or STRATA_API_KEY to keep it out of the process list |
every route |
| Customer | --api-keys FILE |
POST /v1/chat/completions, /v1/messages, /v1/messages/count_tokens, /tokenize, /detokenize and GET /v1/models |
- Other routes answer a customer key with
403, for example/api/stats,/metrics,/api/loadand/api/download. - Only the admin key loads another model: with
/api/load(a name from the models folder, or the path of any GGUF file the server can read), or with a chat request that names another model ofGET /v1/models. - With customer keys and no admin key, nobody can use the admin routes.
- With no key at all the server is open to anyone who reaches it. That is for a local machine only.
- Clients send
Authorization: Bearer <key>(Beareras written) orx-api-key: <key>(Anthropic). - Each key reuses only its own cached conversations (
--cache-ram), socached_tokensand response times tell a customer nothing about another. End users behind one key are not separated from each other. - Prompts and replies are never written to disk.
The key file has one name key pair a line, and the name goes into the usage log. # starts a comment, so a key
cannot contain #. A key has at least 16 characters. Names and keys must not repeat, and the admin key must not be
in the file.
A changed file applies from the next request. Rename the new file over the old one, so it is never read half written:
sudo sh -c 'cp /etc/strata/keys.txt /etc/strata/keys.new && echo "gamma $(openssl rand -hex 24)" >> /etc/strata/keys.new \
&& chown strata /etc/strata/keys.new && chmod 600 /etc/strata/keys.new && mv /etc/strata/keys.new /etc/strata/keys.txt'- A removed key gets
401from its next request on. - A file that cannot be read or parsed keeps the old keys. The server log says why.
- A file with no keys removes all customer keys. Without an admin key it is refused, as at start.
- To cut off a customer who used up a prepaid budget, sum the usage log per key and remove the key.
Without keys the server checks the Host header. For a LAN name on a server bound to 0.0.0.0, add
--allowed-hosts ai-server.lan,ai-server.local (or STRATA_ALLOWED_HOSTS). Names match exactly, ignoring case and
port.
| Limit | Default | A request over it |
|---|---|---|
--ctx, prompt plus reply |
4096 tokens | gets 400 when its prompt fills the context |
--max-tokens, reply length |
what the context leaves | has its reply capped |
| Body size | 8 MiB | is refused |
| Silence while sending | 30 s | is closed |
| Whole request, headers and body | 120 s | is refused |
--max-per-key, open requests of a customer key |
no limit | gets 429 Too Many Requests, Retry-After: 1, type rate_limit_error |
--max-waiting, open connections |
no limit | gets 503 Service Unavailable, Retry-After: 2 |
- Set
--max-tokens. Without it a reply may run until the context is full and hold the server for minutes. It is also the length when a request asks for none. - KV memory grows with
--ctx: about 650 MB at 32K for the 35B model, half that with--kv q8. --max-waitingcounts every open connection, health checks included:--max-waiting 16with one reply running leaves 15 places. Set it when strangers can reach the server.- Set
--max-per-keybelow--max-waiting, so one customer cannot fill the queue. The OpenAI and Anthropic SDKs retry the429.
By default one chat request runs at a time, and the others wait in arrival order. One request decodes at about 113 tok/s (Qwen3.6-35B-A3B Q2_K_XL, RTX 3060), so that is the total for all users. A long prompt blocks the queue for its prefill (about 2 s for 4K tokens on the 3060).
--parallel N keeps N conversations in GPU memory and decodes up to 4 of them together. Measured on the RTX 3060
with Qwen3.6-35B-A3B Q2_K_XL, --ctx 4096, short prompts and 200-token replies, all requests sent at once:
--parallel |
Requests | Total | Each request |
|---|---|---|---|
| 1 | 4 | 90 tok/s | one after the other |
| 2 | 2 | 139 tok/s | 69 tok/s |
| 4 | 4 | 164 tok/s | 41 tok/s |
| 4 | 8 | 163 tok/s | 41 tok/s, 4 wait |
| 8 | 8 | 149 tok/s | 19 tok/s |
A request alone on a --parallel 4 server decodes at 105 tok/s (106 with --parallel 1).
--parallel 4gives the most total speed. More slots let more users stream at once, each at a lower speed.- A free slot goes to the waiting request whose key holds the fewest slots, oldest first.
- MTP drafting is off (
--mtpis ignored). Without--gpu,--parallelis ignored. --ctxis per slot. N slots take N times the KV memory, so fewer experts fit in VRAM. TheGPU memory:line at start shows the split.--kv q8gets much of it back.
--parallel 4, 4 short requests at once on the 3060:
--ctx |
--kv |
KV for 4 slots | Resident experts | Total |
|---|---|---|---|---|
| 16384 | f16 | 1280 MB | 6876 of 10240 | 160 tok/s |
| 32768 | f16 | 2560 MB | 5567 | 114 tok/s |
| 32768 | q8 | 1360 MB | 6779 | 154 tok/s |
--kv q8 is about 6% slower to decode and 14% slower to prefill at 32K of actual context. Greedy output can differ
from --kv f16 at near-ties.
A model whose experts mostly do not fit in VRAM gains less. Qwen3-Next-80B-A3B IQ1_S on the same 3060 (9199 of 24576
experts resident with 4 slots), 4 requests: 56.5 tok/s with --parallel 1, 77.5 tok/s with --parallel 4.
Prompts are prefilled one at a time, in chunks (--chunk, from rustingstrata calibrate), and the streams decode
between chunks. A smaller --chunk gives shorter pauses and a slower prefill. A 10K-token prompt that arrives while
3 requests stream, on the 3060 with --parallel 4:
--chunk |
Longest pause of a stream | First token of the long prompt |
|---|---|---|
| 4096 (calibrated) | 2.2 s | 10.2 s |
| 1024 | 0.7 s | 13.9 s |
| 512 | 0.4 s | 16.4 s |
Prefilled in one piece, the same prompt took 6.5 s to its first token, and the three streams stopped for all of it.
RustingStrata speaks plain HTTP. Bind it to 127.0.0.1 and put a reverse proxy in front for TLS. With keys set, it
accepts any Host header.
- Turn off response buffering, so streamed replies arrive as they are written.
- The read timeout must cover the wait in the queue, the longest prefill and the longest reply. Nothing is sent, not even the headers of a stream, until the prompt is prefilled.
- If you cannot raise the timeout (Cloudflare gives up after 100 s without a response), use a
--ctxsmall enough that the longest prompt prefills in time, or a direct route.
Caddy (gets and renews the certificate itself):
api.example.com {
reverse_proxy 127.0.0.1:8080 {
flush_interval -1
transport http {
read_timeout 15m
}
}
}
nginx:
server {
listen 443 ssl;
server_name api.example.com;
ssl_certificate /etc/letsencrypt/live/api.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/api.example.com/privkey.pem;
client_max_body_size 8m; # RustingStrata refuses bodies over 8 MiB
location / {
proxy_pass http://127.0.0.1:8080;
proxy_http_version 1.1;
proxy_buffering off; # stream tokens as they come
proxy_read_timeout 900s; # a long reply, or a long wait in the queue
proxy_send_timeout 900s;
}
}To keep the chat page and the admin routes off the public address, serve only /v1/ and /health there:
location /v1/ { proxy_pass http://127.0.0.1:8080; proxy_http_version 1.1; proxy_buffering off; proxy_read_timeout 900s; }
location /health { proxy_pass http://127.0.0.1:8080; }
location / { return 404; }Reach the chat page through an SSH tunnel (ssh -L 8080:127.0.0.1:8080 server) at http://127.0.0.1:8080, with the
admin key.
A cap on requests per minute belongs in the proxy:
# in http { }
limit_req_zone $http_authorization zone=perkey_rate:10m rate=60r/m;
# in the location that passes /v1/ to RustingStrata
limit_req zone=perkey_rate burst=20 nodelay;
limit_req_status 429;Anthropic clients send the key as x-api-key, so key the zone on $http_x_api_key too if you serve them.
/etc/strata/env (mode 600):
STRATA_API_KEY=<admin key>
/etc/systemd/system/strata.service:
[Unit]
Description=RustingStrata inference server
After=network-online.target
Wants=network-online.target
[Service]
User=strata
EnvironmentFile=/etc/strata/env
ExecStart=/usr/local/bin/rustingstrata serve --model /srv/models/Qwen3.6-35B-A3B-UD-Q2_K_XL.gguf --gpu --ctx 32768 \
--addr 127.0.0.1:8080 --api-keys /etc/strata/keys.txt --usage-log /var/lib/strata/usage.jsonl --max-tokens 4096 \
--parallel 4 --kv q8 --max-per-key 4
StateDirectory=strata
Restart=on-failure
RestartSec=5
# Accepted requests (queued ones too) finish before the server stops; that needs more than the default 90 s.
TimeoutStopSec=300
[Install]
WantedBy=multi-user.targetWith the user, keys and calibration of the quick start:
sudo systemctl daemon-reload && sudo systemctl enable --now strata
journalctl -u strata -f- Run
calibrateas the service user: the calibration and the CUDA kernel cache live in its~/.cache/rusting_strata. - The first start after an update compiles the CUDA kernels (about 15 s).
/healthanswers503until the model has loaded. - When the GPU device is lost (a driver reset, a GPU hang),
serveexits with status 1 and systemd starts it again. - On
SIGTERM(systemctl stoporrestart), new requests and/healthget503withRetry-After: 5, and the accepted requests finish, queued ones too.TimeoutStopSecmust cover a full queue (or keep--max-waitinglow): after it systemd sendsSIGKILL. - Behind a load balancer, restarting one server at a time cuts no reply.
- Ctrl+C stops at once. On Windows there is no such drain.
The Dockerfile in the repository builds the server image: the binary, NVRTC for the CUDA kernels and the Vulkan
loader. The GPU driver comes from the host, for NVIDIA cards through the NVIDIA Container Toolkit.
docker build -t rustingstrata .
docker run -d --name strata --gpus all -p 127.0.0.1:8080:8080 \
-v /srv/models:/models -v /srv/strata-cache:/cache rustingstrata
# Calibrate once per model and machine, with the same mounts.
docker run --rm --gpus all -v /srv/models:/models -v /srv/strata-cache:/cache rustingstrata calibrate --model /models/model.gguf- The default command is
serve --gpu --addr 0.0.0.0:8080 --models-dir /models. No model is loaded at the start, so/healthanswers503. Pick a file of/modelson the chat page at http://127.0.0.1:8080. - Arguments after the image name replace the command, for example
serve --gpu --addr 0.0.0.0:8080 --model /models/model.gguf. /cachekeeps the calibration, the compiled CUDA kernels and the expert placement. Without that mount every new container compiles the kernels again and runs uncalibrated. Only thenot calibrated on this machineline says so.- The image sets
XDG_CACHE_HOME=/cache. In an image of your own, set it to a mounted path too. - The port is published on the loopback address only. For a LAN name, add
-e STRATA_ALLOWED_HOSTS=that-name. Set-e STRATA_API_KEY=...before the port faces a network. - For a Vulkan card (AMD, Intel), pass
--device /dev/driin place of--gpus alland add--backend vulkanto the command. This path has not been run on an AMD or Intel card yet.
GET /health needs no key and is answered at once, also while a reply is generated or a model loads.
| Answer | When |
|---|---|
200 {"status": "ok", "waiting": N, "slots": S} |
a model is loaded |
200 {"status": "ok", "unloaded": true, "waiting": N} |
--auto-unload freed the model; the next chat request loads it |
503 {"status": "loading"} |
a model loads, also after --auto-unload |
503 {"status": "no model"} |
no model is loaded |
503 with an error body, no status |
--max-waiting connections are open, or the server stops |
waiting counts the requests being read, generated or queued besides this one. slots is the --parallel value. A
load balancer can send the next request to the server with the lowest waiting / slots.
GET /metrics gives the same and more in Prometheus text format. It needs the admin key, like /api/stats:
strata_up, strata_uptime_seconds, strata_slots, strata_busy, strata_waiting, strata_requests_total,
strata_prompt_tokens_total, strata_cached_prompt_tokens_total, strata_completion_tokens_total,
strata_vram_used_bytes, strata_vram_total_bytes, strata_ram_cap_bytes and, for MoE models,
strata_expert_hits_total and strata_expert_misses_total (these two restart at each model load).
scrape_configs:
- job_name: strata
authorization:
credentials: sk-admin-... # the --api-key value
static_configs:
- targets: ["127.0.0.1:8080"]With --usage-log FILE, every chat request that reaches the model adds one JSON line:
{"at":1793917331,"key":"acme","model":"Qwen3.6-35B-A3B-UD-Q2_K_XL","prompt_tokens":1200,"cached_tokens":1100,"system_tokens":300,"completion_tokens":250,"prefill_ms":95.1,"decode_ms":2210.4,"finish":"stop"}at: Unix time in seconds when the request started.key: the name from the key file,adminfor the admin key, empty on a server without keys.cached_tokens: the part ofprompt_tokensthat came from the conversation cache and was not prefilled again. Many providers bill it at a lower price.prefill_ms: from when the model takes the request until its prompt is read, without the wait in the queue or for a slot.decode_ms: the reply after that.finish:stop,length(hitmax_tokensor the context),tool_calls,cutorerror.cut: the client left after its prefill started. All its prompt tokens are logged, andcompletion_tokenscounts the tokens decoded so far. A stream has sent nearly all of them, a reply withoutstreamnone.error: the request failed on the server. It got a500or a stream that stopped.- Not logged: requests refused before the model (bad key, bad JSON, a prompt that fills the context,
503,429) and requests whose client left while they waited in the queue.
Tokens per key and day, without failed requests:
jq -r 'select(.finish != "error") | [(.at | strftime("%Y-%m-%d")), .key, .prompt_tokens - .cached_tokens, .cached_tokens, .completion_tokens] | @tsv' usage.jsonl \
| awk '{k=$1" "$2; p[k]+=$3; c[k]+=$4; o[k]+=$5} END {for (k in p) print k, p[k], c[k], o[k]}' | sortThe file only grows. Rotate it with logrotate (copytruncate, because RustingStrata keeps it open).
For more users, start one server per card on its own port and balance between them:
rustingstrata serve --model $M --gpu --device 0 --addr 127.0.0.1:8081 --threads 6 ...
rustingstrata serve --model $M --gpu --device 1 --addr 127.0.0.1:8082 --threads 6 ...# max_fails=0: a busy 503 must not mark the server down for 10 s (with both busy, nginx would answer 502).
upstream strata { least_conn; server 127.0.0.1:8081 max_fails=0; server 127.0.0.1:8082 max_fails=0; }
# In the location block: a 503 (busy or stopping) is sent before any work, so another server may take the request.
proxy_next_upstream error http_503 non_idempotent;- Give each server half of the CPU cores (
--threads): each computes the experts outside its VRAM on the CPU. - Conversation caches are per server.
hash $http_authorization consistent;instead ofleast_connkeeps each customer on one server, so conversations are not prefilled again.
For a bigger model, --device 0,1 splits the layers of one server over the cards, so more experts fit in VRAM.
--parallel works here too. A split server does not park conversations in host memory: each slot keeps only its
last conversation. For many users on cards that each fit the model, one server per card is faster.
- RustingStrata listens on
127.0.0.1only; the firewall opens 443 (and 80 for the certificate), not 8080. - An admin key, and customer keys in a file with mode 600.
- The proxy streams without buffering and has a long read timeout.
-
--max-tokensand--ctxfit your price list and your GPU memory (times--parallel). -
--parallelfits the users you expect at once (4 for the most total speed). -
--max-waitingis set (no limit by default), and--max-per-keyis below it. -
--usage-logis on and rotated. -
/health(or/metrics) is monitored, and systemd restarts the server on failure. -
rustingstrata calibrateran on this machine as the service user.