Skip to main content
The llama.cpp server provides a fast, lightweight REST API for LLM inference. It implements OpenAI-compatible endpoints, allowing you to use existing OpenAI client libraries with llama.cpp models.

Features

  • OpenAI-compatible API: Drop-in replacement for OpenAI’s API endpoints
  • High Performance: Pure C/C++ implementation for maximum speed
  • GPU Acceleration: Support for CUDA, Metal, and other backends
  • Streaming Responses: Real-time token generation with Server-Sent Events
  • Multiple Models: Router mode for managing multiple models simultaneously
  • Multimodal Support: Vision and audio capabilities (experimental)
  • Function Calling: Tool use support for compatible models
  • Flexible Deployment: Docker, native binaries, or cloud platforms

Quick Start

Starting the Server

The server will start on http://127.0.0.1:8080 by default.

Common Server Arguments

string
required
Path to the model file (GGUF format)
number
default:"0"
Size of the prompt context (0 = loaded from model)
number
default:"-1"
Number of tokens to predict (-1 = infinity)
string
default:"auto"
Number of layers to store in VRAM (auto, all, or specific number)
string
default:"127.0.0.1"
IP address to bind to
number
default:"8080"
Port to listen on
number
default:"-1"
Number of parallel slots for concurrent requests (-1 = auto)
string
API key for authentication (can be comma-separated list for multiple keys)

Authentication

To enable API key authentication, start the server with the --api-key flag:
Then include the key in the Authorization header:
Without --api-key, the server runs in open mode. The health endpoint (/health) is always public regardless of authentication settings.

Using with OpenAI Client Libraries

The llama.cpp server is compatible with OpenAI’s client libraries:

Available Endpoints

OpenAI-Compatible Endpoints

Native llama.cpp Endpoints

  • POST /completion - Native completion endpoint (not OAI-compatible)
  • POST /embedding - Native embeddings endpoint (not OAI-compatible)
  • POST /tokenize - Tokenize text
  • POST /detokenize - Convert tokens to text
  • GET /health - Health check endpoint
  • GET /props - Server properties and configuration
  • GET /slots - Monitor slot status and performance

Additional Features

  • POST /infill - Code infilling for completion
  • POST /reranking - Document reranking
  • GET /metrics - Prometheus-compatible metrics (requires --metrics flag)

Model Configuration

Setting Model Alias

By default, the model ID is the file path. You can set a custom alias:
Then use it in API requests:

Downloading Models from Hugging Face

This automatically downloads the model and multimodal projector (if available).

Health Check

Check if the server is ready:
Responses:
  • 200 OK with {"status": "ok"} - Server is ready
  • 503 Service Unavailable with error message - Model is still loading

Environment Variables

Many arguments can be configured via environment variables:

Error Handling

The server returns OpenAI-compatible error responses:
Common error types:
  • authentication_error - Invalid or missing API key
  • invalid_request_error - Malformed request
  • unavailable_error - Server not ready (model loading)
  • not_supported_error - Feature not enabled (e.g., metrics endpoint)

Next Steps