---
title: "Deploy Ollama | Self-Hosted LLM API (OpenAI API Alternative)"
description: "Run open LLMs on CPU behind an API key: chat, embeddings, OpenAI-style API"
category: "AI/ML"
url: https://railway.com/deploy/ollama-or-self-hosted-llm-api-openai-api
---

# Deploy Ollama | Self-Hosted LLM API (OpenAI API Alternative)

Run open LLMs on CPU behind an API key: chat, embeddings, OpenAI-style API

**[Deploy Ollama | Self-Hosted LLM API (OpenAI API Alternative) on Railway](https://railway.com/template/ollama-or-self-hosted-llm-api-openai-api)**

Machine-readable deploy manifest (JSON, validated by TemplateCI): https://railway.com/deploy/ollama-or-self-hosted-llm-api-openai-api/manifest.json

- **Creator:** Railhost
- **Category:** AI/ML

## Template content

### Ollama

- **Source:** railhost/ollama-railway
- **Health check:** /health
- **Public domain:** Yes

## Documentation

# Deploy and Host Ollama (Self-Hosted LLM API, OpenAI API Alternative) on Railway

Ollama is a self-hosted server for open large language models. Run Qwen, Gemma, Llama, DeepSeek and other open models on your own server, and call them through Ollama's API or an OpenAI-compatible `/v1` API. Use it in place of the OpenAI API for chat and embeddings, with no per-token bill and no data leaving your server.

## About Hosting Ollama

This template runs the official Ollama build on CPU in one Railway service, with models on a volume. It keeps only the CPU parts of the upstream image, which drops most of its 3.4 GB.

Out of the box, Ollama has no login: anyone who finds the URL can use your models, pull new ones and delete them. This template keeps Ollama on localhost and puts Caddy in front, so every request needs a generated API key.

After deploying:

1. Wait for the starting model, `qwen3:1.7b`, to download; the logs say when.
2. Copy `API_KEY` from the Variables tab.
3. Send requests with `Authorization: Bearer `, or point an OpenAI client at `https:///v1`.

A GitHub Action checks for new Ollama releases every day and smoke-tests each one before it reaches you. Railway then shows an update notice in your project, and you apply it when it suits you.

## Common Use Cases

- A private LLM API for your apps, in place of the OpenAI API for light tasks
- Embeddings for search and RAG with models such as `nomic-embed-text`
- A model backend for Open WebUI, n8n, AnythingLLM or other tools in the same Railway project
- Trying open models without installing anything on your own machine

## Dependencies for Ollama Hosting

- Enough memory for the models you run: about their download size, plus some for the context. Small models (under 4B) suit a CPU best.
- A volume sized for your models: `qwen3:1.7b` takes 1.4 GB, 7B to 8B models about 5 GB.

### Deployment Dependencies

- Ollama: https://github.com/ollama/ollama
- Ollama API docs: https://docs.ollama.com/api
- Model library: https://ollama.com/library
- Template source: https://github.com/railhost/ollama-railway

### Implementation Details

The `MODELS` variable lists models to pull on boot, separated by commas; models already on the volume are skipped. You can also pull and delete models through the API with the key. Other services in the project can reach Ollama over the private network at `http://${{Ollama.RAILWAY_PRIVATE_DOMAIN}}:8080` with the same key.

`/health` answers without the key so Railway can check the service. Railway has no GPUs, so answers come slower than from a hosted API; Ollama unloads a model five minutes after the last request, so memory use drops when the API is idle.

## Why Deploy Ollama on Railway?

Railway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.

By deploying Ollama on Railway, you are one step closer to supporting a complete full-stack application with minimal burden. Host your servers, databases, AI agents, and more on Railway.


## Similar templates

- [Chat Chat](https://railway.com/deploy/-WWW5r) — Chat Chat, your own unified chat and search to AI platform.
- [Weaviate](https://railway.com/deploy/weaviate-1) — Vector database with hybrid search and an API key-protected API
- [Möbius Personal AI OS](https://railway.com/deploy/mobius-v01-personal-ai-os) — Self-hosted AI agent that builds and runs apps for you, with memory.

Open this page in a browser: https://railway.com/deploy/ollama-or-self-hosted-llm-api-openai-api
