Guide

Ollama authentication: how to add API keys and share a server with your team

Ollama's local API has no authentication. Here's how to protect a shared Ollama server with a reverse proxy or a gateway, and give each person their own key.

Ollama's local API has no authentication. Anyone who can reach port 11434 can use every model on the machine. To share one Ollama server safely, keep it on a private network and put something in front of it that checks keys: a reverse proxy for one shared key, or an AI gateway for a key per person with limits.

Checked against Ollama's documentation on 2 December 2026.

What Ollama's API key actually is

This trips a lot of people up. Ollama's docs say it plainly: the local API at http://localhost:11434 does not require authentication. The OLLAMA_API_KEY you can create on ollama.com is for something else: calling Ollama's cloud models directly at https://ollama.com/api or https://ollama.com/v1.

So:

You want toWhat you need
Call Ollama's cloud modelsAn API key from ollama.com, sent as Authorization: Bearer
Protect your own Ollama serverA proxy or gateway in front of it; Ollama won't check keys itself

Even Ollama's OpenAI-compatible endpoint at http://localhost:11434/v1/ asks for an api_key value only because the OpenAI client requires one. Ollama ignores it (Ollama docs).

Step 1: stop exposing port 11434

Before adding keys, make sure the raw Ollama port isn't reachable from places it shouldn't be.

  1. Bind Ollama to localhost or a private interface only, not 0.0.0.0 on a public address.
  2. If it runs in Docker, don't publish port 11434 to the host's public interface.
  3. Allow traffic to the server only from the proxy or gateway that will sit in front of it.

A proxy is pointless if people can go around it.

Option A: a reverse proxy with one shared key

The quickest fix is a reverse proxy such as Caddy or Nginx that rejects any request without the right Authorization header and forwards the rest to Ollama.

A minimal Caddy example:

llm.example.com {
    @noauth not header Authorization "Bearer {$OLLAMA_GATEWAY_KEY}"
    respond @noauth 401

    reverse_proxy 127.0.0.1:11434 {
        flush_interval -1
        header_up Host localhost:11434
        header_up -Authorization
    }
}

flush_interval -1 keeps streaming responses flowing token by token. header_up -Authorization strips the key before the request reaches Ollama. The key comes from an environment variable when Caddy loads the config. Treat this as a starting point and test it in your environment before relying on it.

Good for: a handful of trusted users or one internal app.
Limits: everyone shares one key. You can't tell who sent what, set a budget per person, limit which models each person uses, or revoke one person without changing the key for everyone.

Option B: an AI gateway with a key per person

Once more than a few people share the server, you usually want what a proxy can't give you:

  • a separate key for each person or app, which you can revoke on its own
  • rate limits and token budgets per person
  • a list of models each person may call
  • usage and cost per person
  • a second server or a paid provider to take over when this one is busy or down

That's the job of an AI gateway (also called an LLM gateway). It sits in front of Ollama the same way a proxy does, but understands models, tokens and users. Read more in what is an LLM gateway.

Open-source options like LiteLLM and Bifrost can both route to Ollama and issue virtual keys with budgets. See best LLM gateways for the trade-offs.

AI Gateway by LayerX was built for exactly this setup: a team sharing its own GPU servers running Ollama or vLLM. You register each Ollama server as a provider, invite people by email (they sign in with a 6-digit code, no passwords), and each person gets their own keys, daily and monthly token budgets and a list of allowed models. Each key has a requests-per-minute limit. The gateway checks every server on a schedule and takes unhealthy ones out of rotation, and if your machines are busy it can move requests to a vendor like OpenAI, Groq or Together. Prompts and responses are never stored.

Which option should you pick?

SituationPick
Just you, on your own laptopNothing. Leave Ollama on localhost (local vs cloud models).
One app or a few trusted peopleA reverse proxy with one key
A team, several apps, or anyone outside your groupA gateway with a key per person
Several Ollama or vLLM serversA gateway, so requests are spread across them and failures are skipped

Pointing your apps at the protected server

Whichever option you pick, apps that use the OpenAI SDK only need two changes: the base URL and the key.

from openai import OpenAI

client = OpenAI(
    base_url="https://llm.example.com/v1",
    api_key="the-key-you-issued",
)

More on this pattern in an OpenAI-compatible API for your own models.

Questions

Does Ollama support API keys?

Only for its cloud service at ollama.com. The local API at port 11434 does not require authentication, so a server you host needs a proxy or gateway in front of it to check keys.

What is OLLAMA_API_KEY used for?

It authenticates direct calls to Ollama's cloud models at ollama.com/api and ollama.com/v1. It does not protect your own server.

How do I let multiple users share one Ollama server?

Keep Ollama on a private network and put a gateway in front of it that gives each person their own key, rate limit and token budget. A reverse proxy with one shared key works for a small, trusted group.

Can I see who used my Ollama server?

Not from Ollama itself. A gateway in front of it can record usage per key and per person, without storing the prompts.

More posts

Keep reading.

See how AI Gateway fits your setup.

Tell us what you run today and how many people need access. We'll get back to you to learn more about your setup.

See how AI Gateway fits your setup.

What do you run today?