AI Model Intelligence
Share
Local Deployment & Hardware

Setting Up Ollama Local API Server (Port 11434 & HTTPS)

The Ollama local API server turns any model you have downloaded into a REST endpoint your own apps can call. If you are already running local AI models through the Ollama chat command, the same engine can also listen for HTTP requests on port 11434. This guide walks you through starting it, testing it, securing it, and shutting it down.

Everything below works on Windows, macOS, and Linux. We will cover the default loopback address, the most useful endpoints, LAN exposure, an HTTPS front end with Caddy, and the correct way to stop the server on each operating system.

Quick answer: Ollama starts a local API server on http://127.0.0.1:11434 when you install it or run ollama serve. Test it with curl http://127.0.0.1:11434/api/tags. Set OLLAMA_HOST=0.0.0.0:11434 for LAN access, and put Caddy in front for HTTPS. Stop it with taskkill, systemctl stop ollama, or pkill.

What Is the Ollama Local API Server?

Ollama is more than a command-line chat tool. Under the hood it runs a small HTTP server that loads models into memory and answers requests from any program that can speak JSON over HTTP.

That server is what powers the CLI, desktop apps, and third-party front ends. Once you understand it, you can connect anything from a Python script to a full chat UI.

ollama serve Explained

The ollama serve command starts the API server in the foreground. On most desktop installs the server already runs in the background, so running it manually prints a message that the address is already in use.

ollama serve

You typically only need this command on a headless Linux box without systemd, or when you want to see server logs directly in your terminal. Otherwise the background service is enough.

The Default Address: http://127.0.0.1:11434

By default the server binds to the loopback interface at http://127.0.0.1:11434. That means only programs on the same machine can reach it, which is a sensible safe default.

Port 11434 is Ollama’s registered default and almost never conflicts with other software. You can change the bind address and port with the OLLAMA_HOST variable, which we cover below.

Testing the Server with curl

The fastest health check is the tags endpoint, which lists every model you have pulled. If the server responds with JSON, the API is alive and ready.

curl http://127.0.0.1:11434/api/tags

A working server returns a JSON object with a models array, including each model’s name, size, and modification date. A connection error means the server is not running or is bound to a different address.

You can also open http://127.0.0.1:11434 in a browser. A plain “Ollama is running” message confirms the listener is up, even though the browser cannot render the API itself.

Key Ollama API Endpoints

Ollama exposes a compact REST API. The three endpoints you will use most are /api/generate for one-shot completions, /api/chat for multi-turn conversations, and /api/tags for listing models.

EndpointMethodPurpose
/api/generatePOSTSingle prompt completion
/api/chatPOSTMulti-turn chat with history
/api/tagsGETList downloaded models
/v1/chat/completionsPOSTOpenAI-compatible chat

/api/generate

This endpoint takes a model name and a prompt, then streams back the completion. Setting stream to false returns one complete JSON response instead of token-by-token chunks.

curl http://127.0.0.1:11434/api/generate -d '{"model":"llama3.1","prompt":"Why is the sky blue?","stream":false}'

The response field holds the generated text. Extra fields like eval_count and total_duration are useful for benchmarking tokens per second on your hardware.

/api/chat

For conversations, /api/chat accepts a messages array with role and content pairs. Send the full history on each request, because the server itself is stateless.

curl http://127.0.0.1:11434/api/chat -d '{"model":"llama3.1","messages":[{"role":"user","content":"Hello, who are you?"}],"stream":false}'

The reply arrives under message.content, ready to append to your history for the next turn. This endpoint also supports tool calling on models that advertise that capability.

/api/tags

We already used /api/tags as a health check. It is a GET request, so no body is needed, and it doubles as an inventory of what is installed locally.

curl -s http://127.0.0.1:11434/api/tags | python -m json.tool

Piping through a JSON formatter makes the output readable. Each entry shows the digest and parameter size, which helps when you script model management.

Using the OpenAI-Compatible Endpoint

Ollama also speaks the OpenAI chat completions dialect at /v1/chat/completions. This lets existing tools and SDKs talk to your local server with almost no changes.

curl http://127.0.0.1:11434/v1/chat/completions -H "Content-Type: application/json" -d '{"model":"llama3.1","messages":[{"role":"user","content":"Write a haiku about GPUs."}]}'

Point the OpenAI Python SDK at base_url http://127.0.0.1:11434/v1 and pass any placeholder as the API key. Most libraries only require the key to be non-empty.

This compatibility layer is also the easiest way to connect Ollama to Open WebUI or AnythingLLM, since both ship with OpenAI-style connectors out of the box.

Exposing Ollama on Your LAN with OLLAMA_HOST

Loopback binding means other devices on your network cannot reach the server. To serve your phone, laptop, or a homelab box, bind to all interfaces by setting OLLAMA_HOST to 0.0.0.0:11434.

This is one of several Ollama environment variables that control server behavior. How you set it depends on your operating system.

Windows

Quit Ollama from the system tray first, then set the variable with setx. Restart Ollama afterward so it picks up the new value.

setx OLLAMA_HOST "0.0.0.0:11434"

macOS

On macOS the app reads variables set with launchctl. Run the following, then quit and relaunch the Ollama app.

launchctl setenv OLLAMA_HOST "0.0.0.0:11434"

Linux (systemd)

On Linux the server runs as a systemd unit, so add the variable with a drop-in override. Editing the unit this way survives package upgrades.

sudo systemctl edit ollama
# Add under [Service]:
# Environment="OLLAMA_HOST=0.0.0.0:11434"
sudo systemctl daemon-reload
sudo systemctl restart ollama

Firewall Notes

Binding to 0.0.0.0 is only half the job; your firewall must also allow inbound TCP on port 11434. On Windows, approve the prompt or add a rule with netsh; on Ubuntu with ufw, run one command.

sudo ufw allow from 192.168.1.0/24 to any port 11434 proto tcp

Restrict the rule to your LAN subnet instead of opening the port to the world. Ollama has no built-in authentication, so anyone who can reach the port can run your models and burn your GPU time.

Putting HTTPS in Front of Ollama with Caddy

The Ollama server speaks plain HTTP only. For encrypted traffic — or browser apps that refuse mixed content — place a reverse proxy in front of it.

Caddy is the simplest option because it fetches and renews TLS certificates automatically. A minimal Caddyfile for a machine with a public DNS name looks like this.

ollama.example.com {
    reverse_proxy 127.0.0.1:11434
}

Start Caddy with caddy run in the same directory, or install it as a service. It obtains a Let’s Encrypt certificate and proxies https://ollama.example.com to your local server on port 11434.

Keep Ollama itself bound to 127.0.0.1 so the only public path in is through Caddy. For extra safety, add Caddy’s basic_auth directive so the endpoint also requires a password.

How to Stop Ollama Serve

Stopping the server frees the GPU and system memory that loaded models hold. The right command depends on how the server is running on your OS.

Windows

Right-click the Ollama tray icon and choose Quit, or force it from an elevated terminal. The taskkill command ends the app and its background server process.

taskkill /F /IM ollama.exe

If a model still shows as loaded afterward, also kill ollama app.exe or simply sign out and back in. A full reboot clears any stuck GPU allocation.

Linux

On systemd-based distributions the server is a managed service. Stop it cleanly with systemctl, and add disable if you do not want it starting at boot.

sudo systemctl stop ollama
sudo systemctl disable ollama

macOS and Manual Sessions

Quit the menu bar app on macOS, or use pkill for any ollama serve process you started by hand. This also works on Linux for foreground sessions launched outside systemd.

pkill ollama

Verify the server is gone by curling the tags endpoint again. A connection refused error confirms the port is closed.

Bottom line

The Ollama local API server needs almost no setup: it listens on http://127.0.0.1:11434 the moment Ollama is installed, and curl http://127.0.0.1:11434/api/tags tells you it is healthy. From there, /api/generate, /api/chat, and the OpenAI-compatible /v1/chat/completions cover nearly every integration need.

Open it to your LAN with OLLAMA_HOST=0.0.0.0:11434 and a scoped firewall rule, or put Caddy in front for proper HTTPS. When you are done, stop the server with taskkill, systemctl stop ollama, or pkill so the GPU is free for other work.