Updated: 28 September 2026 · Applies to: Ollama 0.34 on Ubuntu 24.04 / 26.04 LTS

Ollama has a built-in HTTP API on port 11434. Your own scripts, n8n workflows and apps can send questions to your private model with plain HTTP requests. Ollama also offers an OpenAI-compatible API, so most tools that expect an OpenAI endpoint work with just a new address. This guide uses the server itself as the client; for other machines see How to make Ollama reachable from other machines (OLLAMA_HOST) safely?.

Before you start

  1. Ollama is installed and running (How to install Ollama on Ubuntu and run your first private LLM?).
  2. You have downloaded a model, for example: ollama pull llama3.2

Send a question with curl

curl http://127.0.0.1:11434/api/chat -d '{
  "model": "llama3.2",
  "messages": [{ "role": "user", "content": "Explain DNS in one sentence." }],
  "stream": false
}'

The answer is a JSON document; the text is in message.content. With "stream": false you get the complete answer at once. Leave the line out to receive the answer piece by piece as it is generated.

Use the OpenAI-compatible endpoint

curl http://127.0.0.1:11434/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "llama3.2",
    "messages": [{ "role": "user", "content": "Say this is a test" }]
  }'

List the models that the API offers:

curl http://127.0.0.1:11434/v1/models

Use it from Python

Install the OpenAI library (pip install openai, inside a virtual environment) and point it to your server:

from openai import OpenAI

client = OpenAI(
    base_url="http://127.0.0.1:11434/v1/",
    api_key="ollama",   # required by the library, ignored by Ollama
)

reply = client.chat.completions.create(
    model="llama3.2",
    messages=[{"role": "user", "content": "Say this is a test"}],
)
print(reply.choices[0].message.content)

Other tools

  • In n8n, add an Ollama chat model node and enter the Ollama address as base URL. If n8n runs in Docker on the same server, 127.0.0.1 means the n8n container itself, so use http://host.docker.internal:11434 (on Linux add extra_hosts: - "host.docker.internal:host-gateway" to the n8n service) and see How to fix "Open WebUI cannot connect to Ollama"? for the setting that makes Ollama reachable from containers.
  • In tools with an "OpenAI-compatible" setting, use the base URL http://YOUR-SERVER:11434/v1/ and any text as the API key.

The API supports chat completions with streaming, JSON mode, tools and images, text completions, model lists and embeddings on the /v1 paths.

Common problems

  • model "..." not found: the name must match ollama list exactly, including the tag (for example llama3.2:latest).
  • Connection refused: Ollama is not running (systemctl status ollama) or you use the wrong address. From another machine you must first allow remote access: How to make Ollama reachable from other machines (OLLAMA_HOST) safely?.
  • The first answer takes long: the model is loaded into memory first; later answers are fast until Ollama unloads it after 5 minutes without use.

Frequently asked questions

Is there an API key or password?
No. The local API does not check credentials, which is why you should not leave the port open to the internet.

Where can I find all endpoints?
In Ollama's API reference and OpenAI compatibility page.

Want your own private AI without the setup work?

Prefer a hand with the setup? Our engineers can do it for you: Hire an Expert, or use our on-demand server management.

Was this answer helpful?

Still stuck? Open a ticket