Skip to main content
Ollama runs large language models (LLMs) on your own machine and serves them on localhost:11434. That address only works on that machine. Apps in the cloud, a laptop on another network, and tools like Cursor can’t reach it. This guide shows you how to give Ollama a stable public HTTPS URL with ngrok and require a token, so only you and the apps you choose can call your models. It works on every ngrok plan, including free.
Ollama has no built-in authentication. Don’t put it online without the token rule in step 2.

What you’ll need

1. Check that Ollama responds

Make sure Ollama is running and answers on its default port:
You should see a JSON list of the models you’ve pulled.

2. Create a Traffic Policy that requires a token

Generate a long random token:
On the machine where Ollama runs, save this as ollama.yaml, replacing YOUR_TOKEN with the value you generated:
What’s happening here? The first rule rejects any request that doesn’t carry Authorization: Bearer YOUR_TOKEN. ngrok enforces it in its cloud, so rejected requests never reach your machine. The second rule rewrites the Host header to localhost, because Ollama rejects requests addressed to other hostnames. A bearer token is what OpenAI-compatible clients send in their API key field, so the same token works in curl, the OpenAI SDKs, Cursor, and Open WebUI.

3. Put Ollama online

ngrok prints your public URL, such as https://your-assigned-name.ngrok-free.dev. This is your account’s dev domain. It stays the same every time you restart ngrok http, so you configure each client once.

4. Try it out

From any machine, send a prompt to your model, replacing YOUR_TOKEN and the model name with your own:
Send the same request without the Authorization header and you get 401 Unauthorized. Open http://localhost:4040 on the Ollama machine to watch each request and response in the ngrok inspector.

5. Connect your apps

Any app that speaks the OpenAI API can use your Ollama models. Set its base URL to your ngrok URL plus /v1, and its API key to your token.

Use a custom domain

On a paid plan, you can use your own domain, such as llm.example.com, instead of your dev domain. Reserve the domain, then pass it with --url:

Frequently asked questions

Run ngrok http 11434 with a Traffic Policy that requires a token, then call your ngrok URL from anywhere with Authorization: Bearer YOUR_TOKEN. Ollama keeps listening on localhost, so nothing on your machine is exposed beyond what ngrok lets through.
That makes Ollama listen on your local network, not the internet. It also has no authentication or HTTPS, so anyone on the same network can use your models. ngrok gives you a public HTTPS URL and enforces the token before traffic reaches your machine.
No. Every ngrok account, including free, gets a dev domain that ngrok http reuses on every run.
Ollama rejects requests whose Host header isn’t localhost. Keep the add-headers rule in your policy, or start ngrok with --host-header=localhost:11434 instead.
Yes. Point ngrok http at their port instead, such as 1234 for LM Studio or 8000 for vLLM, and keep the token rule. To route across several model servers with failover, use the AI Gateway.

What’s next