Skip to main content

Overview

llama-server is a fast, lightweight HTTP server for serving LLM models with an OpenAI-compatible API. Built on pure C/C++ with minimal dependencies, it provides enterprise-grade features like parallel decoding, continuous batching, and multi-user support.

Quick Start

The server will start on http://localhost:8080 with a web UI accessible via browser.

Key Features

  • OpenAI API Compatible: Drop-in replacement for OpenAI chat completions and embeddings
  • Anthropic Messages API: Compatible with Claude API format
  • Parallel Decoding: Multi-user support with continuous batching
  • Multimodal: Process images and audio through API endpoints
  • Reranking: Built-in reranking endpoint for search applications
  • Function Calling: Tool use support for compatible models
  • Speculative Decoding: Accelerated generation with draft models
  • Web UI: Built-in interface for testing and debugging

Server Configuration

Basic Server Options

string
default:"127.0.0.1"
IP address to bind to. Use 0.0.0.0 to allow external connections.Can also bind to a UNIX socket by ending the address with .sock.Environment: LLAMA_ARG_HOST
integer
default:"8080"
Port to listen on.Environment: LLAMA_ARG_PORT
string
Path to serve static files from.Environment: LLAMA_ARG_STATIC_PATH
string
Prefix path the server serves from (without trailing slash).Environment: LLAMA_ARG_API_PREFIX

Model Loading

string
Path to the GGUF model file.Environment: LLAMA_ARG_MODEL
string
Hugging Face repository in format <user>/<model>[:quant].Automatically downloads mmproj for multimodal models unless disabled with --no-mmproj.Example: unsloth/phi-4-GGUF:q4_k_mEnvironment: LLAMA_ARG_HF_REPO
string
Model name aliases (comma-separated) to be used by API.Environment: LLAMA_ARG_ALIAS

Parallel Processing

integer
default:"-1"
Number of parallel slots (concurrent requests). -1 means auto.Environment: LLAMA_ARG_N_PARALLEL
integer
default:"0"
Size of the prompt context. 0 loads from model.For parallel requests, multiply by number of slots. Example: -c 16384 -np 4 supports 4 concurrent requests with 4096 context each.Environment: LLAMA_ARG_CTX_SIZE
boolean
default:"true"
Enable continuous batching (dynamic batching) for efficient parallel processing.Environment: LLAMA_ARG_CONT_BATCHING

Authentication & Security

string
API key for authentication. Multiple keys can be comma-separated.Environment: LLAMA_API_KEY
string
Path to file containing API keys (one per line).
string
Path to PEM-encoded SSL private key for HTTPS.Environment: LLAMA_ARG_SSL_KEY_FILE
string
Path to PEM-encoded SSL certificate for HTTPS.Environment: LLAMA_ARG_SSL_CERT_FILE

Usage Examples

Starting the Server

1

Basic startup

Start with default configuration:
Access the web UI at http://localhost:8080
2

Multiple concurrent users

Support up to 4 concurrent requests:
3

Enable speculative decoding

Use a draft model for faster generation:

Docker Deployment

Docker Compose

API Endpoints

Health Check

GET /health or /v1/health Public endpoint (no API key required).

Chat Completions (OpenAI Compatible)

POST /v1/chat/completions

Completions (Non-OAI Format)

POST /completion Llama.cpp native completion endpoint with extended features.

Embeddings

POST /v1/embeddings Generate embeddings with embedding models:
cURL

Reranking

POST /reranking Rerank documents for search applications:

Advanced Configuration

Multimodal Support

Serve vision or audio models:
The /v1/chat/completions endpoint accepts images in base64 format:

Monitoring Endpoints

boolean
default:"false"
Enable Prometheus-compatible metrics endpoint at /metrics.Environment: LLAMA_ARG_ENDPOINT_METRICS
boolean
default:"true"
Expose slot monitoring endpoint for viewing active requests.Environment: LLAMA_ARG_ENDPOINT_SLOTS
boolean
default:"false"
Enable POST /props endpoint for changing global properties.Environment: LLAMA_ARG_ENDPOINT_PROPS

Grammar & JSON Schemas

Constrain all outputs with a grammar:
Clients can also specify grammars per-request in the API.

Caching & Performance

boolean
default:"true"
Enable prompt caching to reuse KV cache from previous requests.Environment: LLAMA_ARG_CACHE_PROMPT
integer
default:"0"
Minimum chunk size to attempt reusing from cache via KV shifting.Requires prompt caching to be enabled.Environment: LLAMA_ARG_CACHE_REUSE
float
default:"0.1"
How much a request prompt must match a slot’s prompt to reuse that slot.0.0 disables this feature.

Router Mode

Serve multiple models simultaneously:
string
Directory containing models for router server.Environment: LLAMA_ARG_MODELS_DIR
integer
default:"4"
Maximum number of models to load simultaneously. 0 = unlimited.Environment: LLAMA_ARG_MODELS_MAX
boolean
default:"true"
Automatically load models on demand.Environment: LLAMA_ARG_MODELS_AUTOLOAD

Timeout & Throttling

integer
default:"600"
Server read/write timeout in seconds.Environment: LLAMA_ARG_TIMEOUT
integer
default:"-1"
Number of threads to process HTTP requests.Environment: LLAMA_ARG_THREADS_HTTP
integer
default:"-1"
Seconds of idleness before server sleeps to save resources. -1 disables.

Web UI Configuration

boolean
default:"true"
Enable the built-in web interface.Environment: LLAMA_ARG_WEBUI
json
JSON configuration for WebUI defaults.Environment: LLAMA_ARG_WEBUI_CONFIG
string
Path to JSON file with WebUI configuration.Environment: LLAMA_ARG_WEBUI_CONFIG_FILE

Environment Variables

Boolean options use these values:
  • Enabled: true, 1, on, enabled
  • Disabled: false, 0, off, disabled
  • Negation: LLAMA_ARG_NO_MMAP disables mmap regardless of value
Example:

Performance Optimization

Best Practices
  • Use --cont-batching for multiple concurrent users
  • Enable --cache-prompt to reuse computation across similar requests
  • Set --cache-reuse for improved performance with shared prefixes
  • Use --flash-attn on on supported hardware
  • Adjust -np (parallel slots) based on your concurrency needs
  • Monitor with --metrics endpoint for production deployments

Building with SSL

To enable HTTPS support:
Then use with SSL certificates:

See Also