Skip to main content

llama.cpp Cheatsheet

llama.cpp is a high-performance C/C++ local LLM inference engine supporting GGUF format models. It offers `llama-cli` (command-line inference) and `llama-server` (HTTP server with OpenAI-compatible API), supporting CPU/GPU/Metal inference and model quantization.

Updated: 2026-07-20·25 commands

Quick Start

``bash # Download a GGUF model huggingface-cli download bartowski/Llama-3.2-3B-Instruct-GGUF --include 'Q4_K_M/*' --local-dir ./models

# Chat inference llama-cli -m ./models/Llama-3.2-3B-Instruct-Q4_K_M.gguf -p "Hello, how are you?"

# HTTP Server (OpenAI-compatible API) llama-server -m ./models/Llama-3.2-3B-Instruct-Q4_K_M.gguf --port 8080

# Query the server (from another terminal) curl -s http://localhost:8080/v1/chat/completions \ -d '{"model":"model","messages":[{"role":"user","content":"Hello"}]}' `

CLI Inference (llama-cli)

Use llama-cli for direct terminal inference. Key flags: -m (model file), -p (prompt), -n (max tokens), --temp (temperature), -ngl (GPU layers), -t (threads). Add --no-display-prompt for clean output.

HTTP Server (llama-server)

llama-server exposes an OpenAI-compatible API. Supports chat completions (/v1/chat/completions), text completions (/v1/completions), embeddings (/v1/embeddings), tokenization, and model management endpoints.

Model Quantization

Use llama-quantize to convert models between GGUF quantization levels. Typical command: llama-quantize input.gguf output.gguf Q4_K_M. Common types: Q4_0 (fastest), Q4_K_M (best balance), Q5_K_M (higher quality), Q8_0 (near lossless).

Embeddings

llama.cpp supports text embeddings for RAG pipelines. Enable the embeddings endpoint in server mode with --embeddings, or use the standalone llama-embedding CLI tool.

GPU Acceleration

Control GPU offload with -ngl N. -ngl 99` offloads all layers. Apple Silicon uses Metal automatically. NVIDIA GPUs use CUDA. AMD GPUs use Vulkan or HIP.

Startup & Modes(11)

CommandLevel
llama-cli --help
Show llama.cpp CLI help
Basic
llama-cli -m
Specify model file path (GGUF format)
Basic
llama-cli -p
Specify input prompt
Basic
llama-cli -f
Read prompt from file
Basic
llama-cli -n
Set max generated tokens
Basic
llama-cli -t
Set thread count (CPU inference)
Intermediate
llama-cli --temp
Set temperature (0-2)
Intermediate
llama-cli --top-p
Set top-p sampling
Intermediate
llama-cli --ctx-size
Set context window size
Intermediate
llama-cli -ngl
Specify GPU offload layers (GPU acceleration)
Intermediate
llama-cli --no-display-prompt
Output only generated text (no prompt echo)
Basic

ai-server(8)

CommandLevel
llama-server --help
Show HTTP server help
Basic
llama-server -m
Start model in HTTP server mode
Intermediate
llama-server --port
Specify server listening port
Basic
llama-server --host
Specify bind host address
Intermediate
llama-server -ngl
GPU offload in server mode
Intermediate
llama-server --embeddings
Enable embeddings endpoint
Expert
llama-server --chat-template
Specify chat template file
Expert
curl localhost:8080/v1/chat/completions
Send OpenAI-compatible request to llama-server
Intermediate

ai-model(3)

CommandLevel
llama-cli --hf-token
Use HuggingFace token to download models
Intermediate
llama-cli --hf
Load model directly from HuggingFace
Intermediate
llama-quantize
Quantize model to specified precision
Expert

ai-eval(1)

CommandLevel
llama-perplexity -m
Evaluate model perplexity
Expert

ai-embedding(2)

CommandLevel
llama-embedding
Generate text embeddings
Intermediate
curl -X POST http://localhost:8080/v1/embeddings
Get embeddings via API
Intermediate

FAQ

This cheatsheet is compiled from official tool documentation. Last updated: 2026-07-20.