ollama-queue-proxy
Multi-tenant admission control for a shared Ollama. One endpoint that authenticates each consumer, binds its queue priority to its credential, caps its concurrency, and caches its embeddings — so that several tenants can share one GPU without the loudest one winning. Drop-in compatible: one config change in your consumers:
OLLAMA_HOST=http://localhost:11435
Everything else works as before. Streaming, /api/tags, /api/version — all pass through transparently, and metadata reads skip the queue entirely.
What it does
| Feature |
What it gives you |
| Per-client API keys |
Each consumer gets its own key with a priority ceiling — no shared secret |
| Authenticated priority |
The ceiling is enforced against the key, so a client cannot promote itself by sending a header |
| Priority queuing |
Three tiers (high / normal / low) with per-tier depth limits and expiry |
| Client injection |
Port-based auth bypass for clients that can't send Bearer headers |
| Model-aware routing |
Prefer a host that already has the model installed (/api/tags), else weighted round-robin |
| Embedding cache |
Hash-keyed Valkey cache for /api/embed and /api/embeddings — repeated RAG requests skip upstream |
| keep_alive defaulting |
Prevent Ollama from unloading models between bursty requests |
| Per-client concurrency caps |
Hard ceiling per client so batch workloads can't starve interactive ones |
| Failover |
On host failure, retry on the next configured host transparently |
The product only exists with auth.enabled: true. With auth disabled — the shipped
default, and the quick-start path — client_id comes from a caller-supplied
X-Client-ID header and the priority ceiling is not applied. Any client can then claim
any identity and any priority, which also defeats the per-client concurrency caps. That
is correct behaviour for a single-tenant quick start, but everything on this page
describing policy assumes auth is on.
Just need auth? See ollama-auth-sidecar — a simpler tool if queuing, routing, and caching aren't needed.
Why this exists
The top r/ollama post of the past year was someone's open Ollama being exploited for weeks. Ollama ships with no authentication. This proxy puts auth in front with per-client keys and priority ceilings — without requiring any changes to consumers like Open WebUI, LangChain, or Continue.dev.
The other reality: in a homelab, one Ollama host quickly becomes a shared resource. Open WebUI, agent swarms, embedding workers, and overnight batch jobs all hit the same GPU. Without per-client policy and a queue, the loudest workload wins. This proxy makes one Ollama into a multi-tenant endpoint with an admission policy.
And the starvation problem: if you run embeddings at night and interactive chat hits the same server, the chat waits. One header fixes this:
X-Queue-Priority: high
Background jobs send low. Interactive tools send normal or high. The queue handles the rest.
The header is a request, not a grant. Each API key carries a max_priority, and the
requested tier is capped to it before the request is enqueued. A key issued at low
cannot obtain high by asking, so a batch worker cannot promote itself out of the tier
it was given. That distinction is the point of the whole design — see below.
How this compares to alternatives
The short version: several tools in this space queue, and several authenticate. The
combination — a priority tier bound to an authenticated credential and enforced
server-side — is what is hard to find elsewhere.
|
Inbound client auth |
Priority |
Priority bound to identity |
| ollama-queue-proxy |
per-client API keys |
3 tiers, X-Queue-Priority |
yes — max_priority per key |
| Olla |
none |
— |
n/a |
| ollamaMQ |
none |
VIP / Boost per user |
no — X-User-ID is an unauthenticated header |
| LiteLLM |
virtual keys |
priority in request body (beta) |
no — caller-declared |
| ollama_proxy_server, LoLLMs Hub |
API keys |
none |
n/a |
vs. Olla. Olla is the strongest tool here for fleet routing — Go, ~12 native
backends, circuit breakers, sticky KV-cache sessions, sub-millisecond selection, under
50 MB RAM. If routing intelligence across many backends is your problem, use Olla. What
it does not do is authenticate inbound clients at all; its docs are explicit that the
auth: block "has no bearing on how clients authenticate to Olla". So it cannot express
a per-tenant policy, because it has no notion of which tenant is calling.
vs. ollamaMQ. Closest in spirit — it has a real priority queue with VIP/Boost tiers
and a decaying fair-share score (which is better than this project's anti-starvation
story today). But priority is keyed off X-User-ID, an ordinary request header with
nothing verifying it, so any client can claim any tier.
vs. LiteLLM. The enterprise default for multi-provider proxying. If you run mixed
providers, use LiteLLM. Its scheduler does have a priority field, but it is
caller-declared rather than bound to the virtual key, it is marked beta, and it covers
only acompletion / atext_completion — not embeddings, which is precisely the
workload that starves interactive chat on a shared GPU. LiteLLM issue #13405,
"Support for Priority-Based Request Handling via API Keys", is an open request for
what this project already does.
vs. DIY Nginx + Redis. The "rate-limit Ollama with Nginx" pattern is in every blog
post, and it handles request-rate fine. It cannot express priority within a single key,
keep_alive injection, or an embedding cache — those need awareness of the Ollama
protocol, not just HTTP counts.
vs. ollama-auth-sidecar. The right
tool when you have one Ollama host and just want auth, with no queue or policy.
How it works
flowchart TD
subgraph Entry["Entry Points"]
C1["Consumers\n(LibreChat, LangChain, agents)\nport 11435"]
C2["No-auth clients\nport 11436 / 11437"]
end
C1 -->|"Bearer token"| AUTH
C2 -->|"no header"| INJ["Client Injection\ninjects client_id + priority ceiling"]
INJ --> AUTH
AUTH{"Auth\ncheck"}
AUTH -->|"invalid"| E401["401 Unauthorized"]
AUTH -->|"pass"| EMBED
EMBED{"Embedding\nrequest?\n/api/embed\n/api/embeddings"}
EMBED -->|"yes"| CACHE{"Valkey cache\nSHA-256 key"}
EMBED -->|"no"| PRI
CACHE -->|"HIT"| HIT["Return cached response\nX-Cache: HIT\nskips queue + upstream"]
CACHE -->|"MISS"| PRI
PRI["Priority Queue\nhigh › normal › low\n(capped to key's max_priority)"]
PRI -->|"depth exceeded"| E503["429 / 503 + Retry-After"]
PRI --> WORKERS["Worker Pool\nmax_concurrent slots\nper-client semaphore"]
WORKERS --> KA["Inject keep_alive\ninto request body"]
KA --> ROUTER{"Model-aware\nrouter"}
POLLER["Background poller\nGET /api/tags every 30 s\n(every host, every interval)"]
POLLER -->|"installed model inventory"| ROUTER
ROUTER -->|"model installed on host"| H1["Ollama Host A\nprimary · weight 2"]
ROUTER -->|"model installed on host"| H2["Ollama Host B\nsecondary · weight 1"]
ROUTER -->|"no match → weighted\nround-robin"| H1
H1 -->|"connection failure"| H2
H2 -->|"all hosts failed"| E502["503 X-Failover-Exhausted"]
H1 --> RESP["Response\nX-Queue-Wait-Time\nX-Failover-Host\nX-Queue-Position"]
H2 --> RESP
Requests from multiple consumers enter the proxy, are authenticated (or identity-injected for consumers without Bearer support), and placed into one of three priority tiers — capped to the ceiling on the presented key. A worker pool drains the tiers in order. For each request, the router prefers a host that has the model installed. Embedding requests check the cache first — hits skip the queue and upstream entirely. keep_alive is injected into request bodies so Ollama doesn't unload models between requests. Per-client concurrency caps prevent any single client from monopolizing the queue.
Proxy overhead is roughly 1–2ms per request in local testing — negligible compared to Ollama inference time.
Quick start
git clone https://github.com/TadMSTR/ollama-queue-proxy
cd ollama-queue-proxy
cp config.example.yml config.yml
# Edit config.yml — set your Ollama host URL (see comment in file)
docker compose up -d
If Ollama runs natively (not in a container): set the host URL to http://host.docker.internal:11434 (Mac/Windows) or http://172.17.0.1:11434 (Linux).
Then point your consumers at http://localhost:11435 instead of http://localhost:11434.
Warning: Default config has no authentication. If exposing beyond localhost, set auth.enabled: true and configure API keys. The docker-compose example binds to 127.0.0.1 for this reason.
Authentication
Set auth.enabled: true and add keys to config.yml:
auth:
enabled: true
keys:
- key: "sk-my-interactive-key"
client_id: "openwebui"
description: "Open WebUI"
max_priority: high
scope: inference # the default — may proxy, may not manage the queue
max_concurrent: 0 # unlimited (subject to proxy.max_concurrent)
- key: "sk-my-batch-key"
client_id: "memsearch-watch"
description: "Background embedding jobs"
max_priority: low
max_concurrent: 2 # cap at 2 concurrent so it can't starve interactive users
- key: "sk-my-admin-key"
client_id: "admin"
description: "Admin"
max_priority: high
scope: management
- key: "sk-my-readonly-key"
client_id: "homepage"
description: "Status widget — cannot spend GPU time"
scope: read
Consumers pass their key as a Bearer token:
Authorization: Bearer sk-my-interactive-key
Versus Ollama's built-in OLLAMA_API_KEY: Ollama supports a single shared key — one key for all consumers, no per-client control. This proxy gives each consumer its own key with its own priority ceiling, concurrency cap, and optional management access.
Priority ceilings: a key with max_priority: low that sends X-Queue-Priority: high is silently capped to low. The caller doesn't know — it just gets queued at its allowed tier.
Per-client concurrency caps: max_concurrent: N limits a client to N simultaneous in-flight requests. Setting to 0 is unlimited. The cap must be ≤ proxy.max_concurrent. Different clients have independent semaphores — a capped batch client never blocks an interactive client.
Key scopes
scope is one ordered axis with three cumulative levels. Each includes everything below it.
| Scope |
Read status, summary, metrics, dashboard |
Proxy inference to Ollama |
Pause / resume / drain / flush |
read |
yes |
no |
no |
inference (default) |
yes |
yes |
no |
management |
yes |
yes |
yes |
inference is the default because it is what every key did before 0.5.0 — an existing config keeps working with no edit.
scope: read is the point of the feature. Before 0.5.0 there was no key that could not buy GPU time: management: false gated the four queue-control endpoints and nothing else, so any credential handed to a status widget also bought inference. A read key can see the proxy's own state and nothing upstream — it is refused at /api/generate, and also at cheap metadata reads like /api/tags, so the rule is "read sees the proxy, not Ollama" with no per-path exceptions to remember.
A valid key that is not authorized gets 403, not 401 — authenticated, but not enough. The refusal names only the scope that was required, never the one the caller holds.
Deprecated in 0.5.0: management: true. It still works and maps to scope: management, logging a warning at startup that names the client_id. Setting both management: true and a scope that is not management is a startup error rather than a silent precedence rule — a config that contradicts itself about a privilege should not boot and pick a winner. An explicit management: false is not a contradiction with any scope: it is the field's default, so it asserts nothing, and leaving those lines in place while adding scope: elsewhere is a supported migration.
With auth.enabled: false nothing is enforced. No key is presented, so there is no scope to check — the same caveat that has always applied to management, now covering scope too. Every endpoint is open to anyone who can reach the port.
MCP consumer support: jobsearch-mcp and searxng-mcp both read OLLAMA_API_KEY from their environment and forward it as a Bearer token on all outgoing Ollama requests. Point them at the proxy and set their OLLAMA_API_KEY to their assigned key — no code changes required.
Where API keys come from
A key may be given three ways, and exactly one per entry: