A lightweight FastAPI sidecar for llama.cpp (llama-server) that provides request queuing and unified metrics.
LlamaQueue sits in front of a llama-server instance to solve two main issues:
- Sequential Processing: It ensures that only one inference request (Chat Completions, Completions, etc.) reaches the backend at a time. This prevents crashes and interrupted generations when the server needs to swap models dynamically.
- Unified Monitoring: It intercepts the
/metricsendpoint to aggregate Prometheus data from all available models into a single, label-injected stream.
LlamaQueue behaves like a transparent wrapper for the llama-server API.
Requests to these endpoints are queued and processed one-by-one:
POST /v1/chat/completionsPOST /v1/completionsPOST /completionPOST /infill
If the queue is full (default: 100), LlamaQueue returns 503 Service Unavailable.
These endpoints bypass the queue and return immediately:
GET /v1/modelsGET /healthGET /metrics- All
OPTIONS(CORS) requests
Scraping GET /metrics returns aggregated Prometheus metrics for all models currently managed by the backend. Each metric is injected with a model="<model_id>" label for easy filtering in dashboards.
The custom metric llamaqueue:requests_deferred tracks the number of clients currently waiting in the queue.
The typical deployment pairs LlamaQueue with a llama-server container. LlamaQueue is the only exposed service; llama-server stays internal to the stack.
services:
llama-server:
image: ghcr.io/ggml-org/llama.cpp:server
volumes:
- ./models:/models
command: >
-m /models/your-model.gguf
--host 0.0.0.0
--port 8080
--ctx-size 4096
restart: unless-stopped
llamaqueue:
image: ghcr.io/stixes/llamaqueue:1
environment:
LLAMA_URL: http://llama-server:8080
ports:
- "8000:8000"
depends_on:
- llama-server
restart: unless-stoppedStart it with:
docker compose up -dYour OpenAI-compatible endpoint is then available at http://localhost:8000.
docker run -d \
-e LLAMA_URL=http://your-llama-server:8080 \
-p 8000:8000 \
ghcr.io/stixes/llamaqueue:1The following environment variables can be used to tune the proxy:
LLAMA_URL: URL of the backendllama-server(default:http://llama-server:8080).MAX_QUEUE_SIZE: Maximum number of requests allowed to wait in the queue (default:100).MAX_BODY_SIZE: Maximum allowed size for request bodies in bytes (default:50MB).
This project was designed and implemented with the assistance of Claude (Anthropic) via OpenCode. The code, architecture decisions, and documentation were produced through human-AI collaboration.
If you find a bug or have a concern about the implementation, please open an issue.