In this categoryDify ยท 9
How to Use Ollama Local Models in Dify
Point a self-hosted Dify at a local Ollama server, register a model like Llama 3.1 or Qwen, and run your apps fully offline with no per-token cost.
Dify can use a local model served by Ollama instead of a hosted provider. This keeps your prompts and data on your own machine, removes per-token cost, and lets you build apps that run with no internet. The setup is short: run Ollama, pull a model, add the Ollama provider in Dify, and give it the right base URL so the containers can reach your host.
What you need
- A self-hosted Dify instance (the Ollama provider needs a local model server, so this does not apply to hosted Dify Cloud)
- Ollama installed and running from ollama.com
- Enough RAM or VRAM for the model you plan to run
- About 12 minutes
Step 1: Pull a model in Ollama
Install Ollama, then pull a model. Start with something small enough for your hardware so the first test is quick. Ollama serves an HTTP API on port 11434 once it is running, which is what Dify will talk to.
Step 2: Add the Ollama provider in Dify
In Dify, open Settings and then Model Provider. Find Ollama in the provider list, install its plugin if it is not already there, and click Add Model. You fill in the model name exactly as Ollama knows it and the base URL where Ollama is listening.
| Field | What to enter |
|---|---|
| Model name | The exact Ollama tag, for example llama3.1 or qwen2.5 |
| Base URL | http://host.docker.internal:11434 when Dify runs in Docker |
| Model type | Chat, for a conversational model |
| Context size | Match the model's context window, for example 8192 |
Step 3: Select the local model in an app
Open any app, or create a new Chatbot from blank, and pick your Ollama model from the model selector in the prompt editor. Send a test message in the Debug and Preview pane. The response now comes from the model running on your machine, and nothing leaves your network.
Caveats to plan around
Local models trade cost for resources and speed. A model that fits your RAM or VRAM will run; one that does not will be very slow or fail to load. Latency is higher than a hosted API on modest hardware, so keep prompts tight. Context windows on small local models are limited, which matters for RAG and long documents, so match the context size you enter in Dify to what the model actually supports.
Result: a Dify app running entirely on a local Ollama model, with no per-token billing and no prompt data leaving your machine.
Watch related tutorials
14:00
18:00
1:42:18
28:14
41:09
9:47New guides in your inbox
Fresh step-by-step how-to guides as we publish them. One email a week, no more.