Deploy Ollama

Ollama with Open WebUI chat, the public API behind a key, models on volume

Deploy Ollama

Deploy and Host Ollama on Railway

Ollama runs open language models (Qwen, Llama, Gemma, DeepSeek, Mistral and hundreds more from its library) behind an HTTP API, plus an OpenAI-compatible endpoint at /v1. This template runs it together with Open WebUI, so right after the deploy you can chat with your models in the browser, and other tools can use the API with a key.

About Hosting Ollama

There are two services. Ollama is the official image (pinned to 0.40.17) with Caddy in front and your models on a volume. Open WebUI (v0.13.4) is the chat page, with its accounts and chats on a second volume.

Sign in at OPEN_WEBUI_URL with the email you enter at deploy (WEBUI_ADMIN_EMAIL) and the generated WEBUI_ADMIN_PASSWORD. Open WebUI normally makes whoever signs up first the admin, which is a race on a public URL; here the admin exists before the URL goes live, and sign-up is off. Add people under Admin Settings, Users.

Ollama has no authentication. A public Ollama lets anyone who finds the address run your models, pull new ones onto your volume or delete them, all on your bill. So the public domain only reaches Caddy, which lets a request through when it carries Authorization: Bearer (generated at deploy). Ollama's own port, 11434, is reachable only on the project's private network, and that's how Open WebUI talks to it.

The model in OLLAMA_PULL_MODELS (qwen3:1.7b by default, 1.4 GB) is pulled on the first start and kept on the volume. Pull more from Open WebUI's model settings or add them to the variable. Models load on the first request and unload after OLLAMA_KEEP_ALIVE (30 minutes) without requests, so an idle service doesn't hold gigabytes of RAM. The tradeoff is the reload: reading qwen3:1.7b from the volume and preparing it for the CPU took 20 seconds in my tests, so the first message after a quiet half hour waits that long. Railway has no GPUs, so everything runs on the CPU, and bigger models are slower. On Hobby the volume holds 5 GB, enough for a few small models or one around 4 GB, such as gemma3:4b.

The problem that took longest to find: Railway's machines have 48 cores, and llama.cpp (which runs the models inside Ollama) started 48 threads, although a Hobby service gets 8 vCPUs. The threads fought over the CPU and a one-word answer took 180 seconds. The start script now reads the container's CPU limit and sets the thread count to match. With 8 threads qwen3:1.7b generated 71 to 91 tokens a second and read prompts at about 300 tokens a second, more than a hundred times faster than before.

Before publishing I tested it on Railway. Without the key, or with a wrong one, Ollama's API answered 401; with the key both /api/generate and /v1/chat/completions answered. In Open WebUI a sign-up attempt got 403, the admin signed in, qwen3:1.7b was listed and a chat answered in 3.5 seconds. Then I restarted both services at once: the model was still on the volume, the admin signed in and the saved chat was still there. Open WebUI used 1.1 to 1.7 GB of RAM, and Ollama 0.5 GB with no model loaded or 1.6 GB with qwen3:1.7b loaded, so expect roughly $16 to $33 a month at Railway's RAM price depending on how often the model is in memory. Pulling a second model from Open WebUI's admin settings worked too.

I also switched off three Open WebUI extras that call the model again after every message (autocomplete while typing, follow-up suggestions and tags). On a CPU each one queues behind your next question. Chat titles are still generated.

Common Use Cases

  • A private ChatGPT-style chat for yourself or a small team, on open models
  • A model endpoint for n8n, LibreChat, Dify or your own code, without sending data to a model provider
  • Embeddings for search or RAG with a small embedding model such as nomic-embed-text
  • Trying open models before you buy hardware to run them at home

Dependencies for Ollama Hosting

Nothing beyond the template. API clients need the key: in OpenAI-compatible tools set the base URL to OLLAMA_URL/v1 and the API key to OLLAMA_API_KEY; for Ollama's own API add the Authorization: Bearer header. Other services in the same Railway project can skip the key and use http://ollama.railway.internal:11434.

Deployment Dependencies

Implementation Details

curl $OLLAMA_URL/v1/chat/completions \
  -H "Authorization: Bearer $OLLAMA_API_KEY" -H "Content-Type: application/json" \
  -d '{"model": "qwen3:1.7b", "messages": [{"role": "user", "content": "Hello"}]}'
OPEN_WEBUI_URL              # the chat page
WEBUI_ADMIN_EMAIL/PASSWORD  # admin account, created on the first start
OLLAMA_URL / OLLAMA_API_KEY # public API, needs the key
OLLAMA_PULL_MODELS          # comma-separated, e.g. qwen3:1.7b,nomic-embed-text
OLLAMA_KEEP_ALIVE=5m        # unload after idle time; -1 keeps the model loaded
OLLAMA_CONTEXT_LENGTH=4096  # larger windows need more RAM
LLAMA_ARG_THREADS           # optional; set by the start script from the CPU limit

Why Deploy Ollama on Railway?

You get a private chat and an authenticated model API on HTTPS in one deploy, with models that survive restarts. RAM is billed while a model is loaded, so the idle unload keeps a lightly used setup cheap.


Template Content

More templates in this category

View Template
Chat Chat
Chat Chat, your own unified chat and search to AI platform.

okisdev
117
View Template
Weaviate
Vector database with hybrid search and an API key-protected API

GitHub Locker
1
View Template
Möbius Personal AI OS
Self-hosted AI agent that builds and runs apps for you, with memory.

Tracklayer
3