SabaKore

Home / Articles / AI guides

What Is LocalAI? Set Up an OpenAI-Compatible API on Your Own Server

LocalAI is a free inference server built to match the OpenAI API format. This explains how its role differs from Ollama and the benefit of reusing your existing AI apps as they are.

Ren, a junior infrastructure engineer

Ren

I built an app that calls the ChatGPT API, but I'm bothered that it costs money every time I use it...
Procura, a cloud AI robot who explains

Procura

Then you should look at LocalAI. It's a free, open-source inference server that accepts requests in the same format as the OpenAI API.

What LocalAI offers

  • It matches the OpenAI API's way of calling (the endpoint format)
  • Besides text generation, it can also handle speech recognition and image generation models
  • It runs on your own server, so there's no per-call billing
  • You can choose a setup that runs on the CPU alone, with no GPU
Ren, a junior infrastructure engineer

Ren

How is it different from Ollama? They sound similar.
Procura, a cloud AI robot who explains

Procura

Both run models on your own server, but they aim at different things. Ollama is mainly about running models easily, and its OpenAI-compatible endpoint is provided on top of that. LocalAI was built from the start as a replacement for the OpenAI API, and tries to offer image and audio features in the same form as well as text.

This difference matters when you've already built an app with the OpenAI SDK or libraries. For text generation alone, Ollama's OpenAI-compatible endpoint is enough. If you want to point code written for OpenAI at your own server as is, including images and audio, LocalAI can be the better fit. If you're building from scratch, Ollama's ease of use is also quite attractive.

What to check before installing

  • Because it supports a wide range of formats, the memory needed varies by feature. Narrow it down to the features you use and test those
  • It is distributed with Docker, so setup isn't difficult in any environment where containers run
  • If you expose it to the outside, anyone can call the API unless you add authentication
Procura, a cloud AI robot who explains

Procura

It's easier to choose if you think of it as a tool for people who want to keep an OpenAI-format API on their own server as is, not for people who want something more capable than Ollama.

How to migrate

You don't need to switch your whole production app at once. A safe approach is to first change the API target only in your development environment, check that the response format and speed are fine, and then consider switching production. Even though the way of calling is the same, a model's performance and strengths differ from OpenAI's service, so judge by looking at actual responses.

  • Point the endpoint at LocalAI in your development environment and check that your existing calls go through as they are
  • Look at the actual responses and judge whether the accuracy is enough for your use
  • If there are no problems, switch production too, and keep only some processing on the original API if needed
Ren, a junior infrastructure engineer

Ren

So: LocalAI if I want to keep my existing OpenAI code, Ollama if I'm building something new. I can choose between them that way.

Running a local LLM on a VPS?

The plan finder shows which plans have enough memory for a model, and Run AI on a VPS covers the steps.

This article is translated from the Japanese original. If the two differ, the Japanese version is the one we keep up to date.