GPT4All’s local server speaks the OpenAI API, so the standard OpenAI Python client works against it with one change: the base URL. Point it at http://localhost:4891/v1 and your script chats with the model on your own machine.
Point the OpenAI client at localhost:4891
Enable the local server in GPT4All’s Settings, then install the old-style OpenAI client with pip install openai~=0.28 and set its base URL: openai.api_base = "http://localhost:4891/v1" and openai.api_key = "not needed". Then call openai.ChatCompletion.create(model="<model-name>", messages=[{"role": "user", "content": "Hello"}]) with the model name exactly as GET /v1/models reports it.
pip install openai~=0.28
import openai
openai.api_base = "http://localhost:4891/v1"
openai.api_key = "not needed"
resp = openai.ChatCompletion.create(
model="<model-name>",
messages=[{"role": "user", "content": "Hello"}])
print(resp.choices[0].message.content)
The version pin matters: the wiki’s example uses the 0.28 client, whose api_base style differs from the 1.x client. If you use the 1.x client, pass base_url="http://localhost:4891/v1" to the OpenAI() constructor instead. Either way, the model name must match the server’s list exactly.
Try it: four checks
| Check | What you should see | If you do not see it |
|---|---|---|
| Server on | The local server is enabled in Settings | Port 4891, localhost |
| Client installed | pip install openai~=0.28 succeeds | Or use the 1.x client with base_url |
| Base URL set | api_base points at localhost:4891/v1 | Check the URL spelling |
| Reply returns | The chat call returns a reply | Check the model name from /v1/models |
Expected result. We checked the GPT4All Local API Server wiki, which gives the Python example with openai~=0.28, api_base http://localhost:4891/v1, and the ChatCompletion call. We did not run the code on this machine.
Limits
This guide covers the Python client setup only. The 0.28 and 1.x clients set the base URL differently. We did not test any code ourselves.
