KoboldCpp speaks several API dialects from one port, and the OpenAI one is the most useful: any tool or script written for OpenAI’s chat completions can talk to your local model by changing the base URL. The setup guide puts the OpenAI-compatible API at http://localhost:5001/v1/, alongside KoboldCpp’s own API at http://localhost:5001/api/ and the web UI on the same port.
Related guide: How to Run SillyTavern with a Local Model
Call it like OpenAI
from openai import OpenAI
client = OpenAI(base_url="http://localhost:5001/v1", api_key="not-needed")
response = client.chat.completions.create(
model="koboldcpp",
messages=[{"role": "user", "content": "Why is the sky blue?"}],
)
print(response.choices[0].message.content)
The model name is not strict — KoboldCpp serves whichever model you loaded — but keep it consistent. If your model has its own chat template, add --jinja at launch: the flags reference says it formats chat requests with the model’s own chat template instead of KoboldCpp’s adapter tags, and it applies to OpenAI chat endpoints. Without it, some instruct models answer in the wrong format.
Lock it down before sharing it
By default KoboldCpp listens on every network interface, so the API is reachable from other devices on your network with no password. For a local test that is fine; before you rely on it, set --host 127.0.0.1 to bind it to this computer only, or set --password — the companion guide covers the password step.
Expected result. We checked the KoboldCpp flags reference for the port and the –jinja flag, and the linked guides for the /v1 base URL and the default listen behaviour. We did not run this software ourselves for this guide, so no output here is a recorded result; steps marked UNTESTED were checked against the sources below, not run.
Limits
KoboldCpp’s OpenAI compatibility covers chat completions; not every OpenAI endpoint or parameter is supported, and tool calling has its own quirks — the flags reference notes that with tools, temperature defaults to 0.5 and is capped at 1.0. We did not run KoboldCpp or send a request, so the example is from the sources, not a recorded run.
Sources
- KoboldCpp flags reference — –port: the web UI and API listen on port 5001 by default; –jinja: formats chat requests with the model’s own chat template, applies to OpenAI chat endpoints
- KoboldCpp setup guide — OpenAI-compatible API at http://localhost:5001/v1/ for chat completions; Kobold API at http://localhost:5001/api/
- KoboldCpp as a local backend — OpenAI-compatible server on http://localhost:5001/v1; –gpulayers defaults to autofit; by default it listens on every network interface
Checked 2026-11-28.
