New Tool Radar

Local AI

How to Ask a LocalAI Model Through Its OpenAI-Compatible API

List the models on your LocalAI server and send a chat completion with curl, reading the reply from the JSON response.

Schematic diagram with three steps: list models with GET /v1/models, send a chat completion to /v1/chat/completions, then read the reply from choices[0].message.content.

LocalAI serves an API that speaks the OpenAI format, so any OpenAI SDK or client works when you point it at http://localhost:8080. The chat endpoint is POST /v1/chat/completions, and the model list is GET /v1/models. You can call both with curl once LocalAI is running and a model is installed.

List the models

Start by asking the server which models it has:

curl http://localhost:8080/v1/models

GET /v1/models returns the model names you can use as the model value in a chat request. The default port is 8080; set it with --address or LOCALAI_ADDRESS if you run LocalAI elsewhere. If you send a model name that is not installed, LocalAI looks it up in your installed models and returns 404 with model "<name>" not found. If a request has no model name at all, LocalAI uses the first available chat model.

Send a chat completion

This request uses the model installed in the quickstart, gemma-4-e2b-it-qat-q4_0:

curl http://localhost:8080/v1/chat/completions -H "Content-Type: application/json" -d '{"model": "gemma-4-e2b-it-qat-q4_0", "messages": [{"role": "user", "content": "Hello!"}]}'

The text of the reply is in choices[0].message.content. If you turned on API keys, add -H "Authorization: Bearer <your-key>" to the request. If you start LocalAI without an API key, the API is open and any key value works; if you set LOCALAI_API_KEY, every request needs a valid key, which LocalAI reads from the Authorization: Bearer <key> header, the x-api-key header, or the xi-api-key header.

Try it: four checks from list to reply

Check What you should see If you do not see it
Models list curl http://localhost:8080/v1/models returns JSON listing gemma-4-e2b-it-qat-q4_0 Start LocalAI and install the model first
Chat completion The curl request returns JSON with a choices list Check the model name matches a name from GET /v1/models exactly
Read the reply The answer text is in choices[0].message.content Check the response is JSON and the request used Content-Type: application/json
Unknown model A wrong model name returns 404 with model "<name>" not found Use a name from GET /v1/models

Expected result. We checked the LocalAI quickstart, which gives the chat completions curl example for gemma-4-e2b-it-qat-q4_0, the choices[0].message.content reply field, and the API key header, and the LocalAI coding agents page, which gives the GET /v1/models and POST /v1/chat/completions endpoints, the default port 8080, the 404 message for an unknown model, and the API key rules. We did not run LocalAI or call its API on this machine.

Limits

This guide covers the models list and one chat completion only. LocalAI also speaks the Anthropic Messages API and the Open Responses API, at /v1/messages and /v1/responses, and those have their own request shapes. Tool calling needs a model trained for tool calls: LocalAI does not reject a request that has tools when the model has no tool support, so the model answers with plain text and the calling app sees no tool call. The default port is 8080, and LocalAI listens on all interfaces with authentication off unless you set an API key, so do not expose it beyond your own machine without one. We did not test any of this ourselves.

Sources

See all