Skip to content

Ollama inference API setup without running a server

Sometimes you need Ollama inference API access without running a full ollama serve daemon on your local machine. This is common in CI/CD pipelines, remote workstations, or when you want to conserve resources while keeping the HTTP endpoint available. This note shows how to get a working API via the OLLAMA_HOST environment variable and SSH tunneling, without leaving unnecessary processes running.

Why API without a server

Using Ollama without a persistent server is useful in several scenarios. In containerized environments, you often only need HTTP access to a model without running a daemon. Over SSH tunnels or bastion hosts, port forwarding is preferable to exposing port 11434 to the internet. It also lets you run models on powerful hosts while issuing requests from lightweight workstations. The API protocol is identical to the running-server case; the difference is only in where the socket is bound.

Ollama serve and ollama run commands

The Ollama CLI separates server startup from interactive model execution. Key flags and their meaning:

FlagDescription
ollama serveStarts the HTTP API server on 127.0.0.1:11434. Without this flag, CLI commands have no address to send requests to.
ollama run <model>Interactive mode: loads the model (if not already cached) and waits for prompt input from stdin. Uses the currently running server.
ollama pull <model>Saves the model to the local cache ~/.ollama without starting a server.
ollama show <model>Outputs model metadata: size, version, required dependencies.

If you only need to call inference from scripts or other programs, having ollama serve running or configuring OLLAMA_HOST to point at a remote/tunneled port is sufficient. Reserve ollama run for manual testing and debugging.

SSH port tunneling

By default, Ollama binds its socket to 127.0.0.1:11434, making it inaccessible to other processes on the host. SSH tunneling lets you export that port into a local network or, conversely, redirect an external port to a local socket on a remote host.

Command for a local tunnel (assumes Ollama is already running on the remote host): ssh -L 11434:127.0.0.1:11434 user@remote-host

After running this, port 11434 on localhost becomes a passage to the Ollama socket on remote-host. Any HTTP client can connect: curl -X POST http://localhost:11434/api/generate -d '{"model":"mistral","prompt":"Hello"}'

For reverse tunneling (exporting a local port to the external network), use -R: ssh -R 11434:localhost:11434 user@gateway-host

Note: the firewall on gateway-host must allow inbound connections on the forwarded port. In production scenarios, -L is preferred and keeping API bound to loopback only protects it via SSH.

OLLAMA_HOST variable

The OLLAMA_HOST environment variable overrides the address to which CLI sends requests. This is the simplest way to work with the API without running