New Tool Radar

Local AI

How to Run GPT4All in Server Mode and Ask It from Another App

Turn on GPT4All's built-in server mode and ask your local model from another app through its OpenAI-compatible API on localhost:4891.

Schematic diagram with three boxes: GPT4All with a model loaded and server mode on, the local server at localhost:4891, and your own app pointing its client at that address to get a reply.

GPT4All’s chat window is only half the story. The app also has a built-in server mode that lets any other program on your computer talk to your local model through a familiar HTTP API — the same OpenAI-compatible shape that cloud code already uses. That is how a local model stops being a chat window and starts being a backend for your own apps, scripts, and tools, with nothing leaving your computer.

Turn on server mode

First, download a model inside GPT4All and load it in a chat, as in the first-chat guide. Then enable the web server in the app’s settings: GPT4All Chat > Settings > Enable web server. Enabling server mode spins up an HTTP server running on localhost port 4891 — the reverse of 1984.

From another app, you then change a single line of code: the base path for requests. The docs’ own example, using the OpenAI Python library, points it at the local server and says the API key is not needed for a local model:

import openai
openai.api_base = "http://localhost:4891/v1"
openai.api_key = "not needed for a local LLM"

That example uses the older OpenAI Python library’s openai.Completion.create() call, with the model name, a prompt, and max_tokens=50. Newer code should use the chat-completions shape instead, but the address and the idea are the same: point your client at http://localhost:4891/v1 and name the model you loaded in GPT4All.

Try it: ask the server from another program

With GPT4All running, a model loaded, and server mode on, check that the server answers before you wire it into anything bigger. Ask for the list of models the server knows about:

curl http://localhost:4891/v1/models

Then send one chat request naming your loaded model and a short fictional question, and check the result against this table:

Check What you should see If you do not see it
Server answers The /v1/models reply lists your loaded model Server mode is off — turn on Enable web server in Settings
Chat reply A short answer to your question, returned as JSON The model name in the request does not match the loaded model
No key needed The request works with no API key You pointed the client at a cloud address instead of localhost:4891

If the models list and a reply both come back from localhost:4891, another app can now use your local model. Expected result. We checked the GPT4All docs page on server mode. We did not run GPT4All in server mode.

Limits

The server only listens on localhost, so only programs on your own computer can reach it — that is a safety feature, not a bug, and there is no login or API key on it, so do not expose the port to a network. The server answers with the model currently loaded in GPT4All’s chat client, so switching models means switching them in the app first. The docs page this guide follows is GPT4All’s older documentation, and the setting’s label may read “Local API Server” in newer versions of the app — the port, 4891, is the same. We did not run the server, so no reply here is a measured result.

Sources

See all