New Tool Radar

Local AI

How to Let a Browser App Call Ollama With OLLAMA_ORIGINS

Set OLLAMA_ORIGINS so a web app on another origin can call your local Ollama server without the browser blocking it.

Schematic diagram with four steps: stop Ollama, restart it with OLLAMA_ORIGINS set to the web app origin, call the API from the browser, then confirm other origins stay blocked.

Ollama’s API works fine from curl and scripts, but a web page calling it from JavaScript hits the browser’s cross-origin rules: the browser blocks the call unless the server says the page’s origin is allowed. OLLAMA_ORIGINS is the setting that lists the allowed origins.

Set the allowed origins and restart Ollama

Stop Ollama, then start it with the origins your web app uses, for example OLLAMA_ORIGINS=http://localhost:3000 ollama serve. The value is a comma-separated list of origins — scheme, host and port all matter, so http://localhost:3000 and http://localhost:5173 are different origins. Restart Ollama after changing it; the setting is read at startup.

OLLAMA_ORIGINS=http://localhost:3000 ollama serve
# then, from the web app:
# fetch("http://localhost:11434/api/tags")

Do not set the origins to a wildcard on a machine that also serves Ollama on the network: any website could then call your local models. Keep the list to the exact origins you develop against, and keep Ollama bound to localhost unless you have a reason — and a firewall — to do otherwise.

Try it: four checks

Check What you should see If you do not see it
Server restarted Ollama starts with the new setting The setting is read at startup, not per request
Browser call works The web app fetches /api/tags without a CORS error Check the origin string matches exactly
Wrong origin blocked A page on another origin is still blocked That is the protection working
No wildcard The setting lists exact origins only Remove any * entry

Expected result. We checked the Ollama API reference for the /api/tags shape used here; OLLAMA_ORIGINS is Ollama’s documented way to control which origins may call the server. We did not change the setting or call Ollama from a browser on this machine.

Limits

This guide covers the CORS setting only. Binding Ollama to a network address is a separate decision with its own risks. We did not test the setting ourselves.

Sources

See all