LocalAI Deployment Guide: A Self-Hosted OpenAI-Compatible API
LocalAI gives you an OpenAI-compatible API backed by local models, so switching means changing one base_url. Docker setup, model YAML, parameter table and four common pitfalls.
📜 Table of Contents
📖 Keep reading
What LocalAI actually does
It is not a new inference engine. It runs an HTTP server that speaks the OpenAI API shape, backed by local models. Change https://api.openai.com/v1 to http://localhost:8080/v1 and your code keeps working.
Good fit: developers tired of token bills, teams whose data cannot leave the intranet, offline demos.
LocalAI vs Ollama vs vLLM
| Tool | Role | Strength | Weakness |
|---|---|---|---|
| LocalAI | OpenAI-compatible multimodal server | One service for text, image, audio, embeddings | More config to learn |
| Ollama | Local model manager | One-command pulls, best ecosystem | Service layer is DIY |
| vLLM | High-throughput engine | Best concurrency | Strict GPU/model requirements |
Solo use: Ollama. Team API: LocalAI. Heavy concurrency: vLLM.
Step 1: Run it
docker run -p 8080:8080 -v $PWD/models:/models \
-e MODELS_PATH=/models localai/localai:latest-aio-cpu
With an Nvidia card, use the CUDA image with --gpus all and a tag matching your CUDA version. Confirm current tags on localai.io rather than copying old tutorials.
Step 2: Add a model
Drop a GGUF into models/ and write a matching YAML:
name: qwen2.5-7b
backend: llama-cpp
parameters:
model: qwen2.5-7b-instruct-q4_k_m.gguf
context_size: 8192
temperature: 0.7
context_size is the field people get wrong. A too-small default silently truncates multi-turn conversations, which looks like the model has a bad memory.
Step 3: Verify
curl -s http://localhost:8080/v1/models
curl http://localhost:8080/v1/chat/completions -H "Content-Type: application/json" \
-d '{"model":"qwen2.5-7b","messages":[{"role":"user","content":"What is RAG?"}]}'
The official Python SDK works unchanged with base_url="http://localhost:8080/v1" and any dummy api_key.
Step 4: Make it a service
Use compose with restart: unless-stopped, bind to 127.0.0.1:8080:8080 and put Nginx in front. LocalAI has no auth by default; exposing port 8080 publicly hands your GPU to the internet.
Four pitfalls
- Model name mismatch: the request's
modelmust equal the YAMLname, not the filename - GPU image without
--gpus all: silently falls back to CPU - First start is slow: model load takes tens of seconds to minutes
- Context too small: raise
context_sizeto 8192 before blaming the model
FAQ
Q: Is it free? A: The project is open source; hosted services and enterprise support are separate. Check localai.io for license terms.
Q: Does it support non-GGUF models? A: Yes, via the transformers and diffusers backends. Support varies by version.
Q: How is Chinese quality? A: It depends on the model, not LocalAI. Qwen models handle Chinese far better than English-first models at the same size.
Written by our editorial team; tools listed here are tested or verified against public sources. Links point to official sites or GitHub repos for reference only — no paid placements.