2026-01-24 22:38:52 +00:00
---
2026-03-11 14:00:22 -07:00
summary: "Run OpenClaw with Ollama (cloud and local models)"
2026-01-24 22:38:52 +00:00
read_when:
2026-03-11 14:00:22 -07:00
- You want to run OpenClaw with cloud or local models via Ollama
2026-01-24 22:38:52 +00:00
- You need Ollama setup and configuration guidance
2026-01-31 16:04:03 -05:00
title: "Ollama"
2026-01-24 22:38:52 +00:00
---
2026-01-31 21:13:13 +09:00
2026-01-24 22:38:52 +00:00
# Ollama
2026-03-11 20:08:45 +00:00
Ollama is a local LLM runtime that makes it easy to run open-source models on your machine. OpenClaw integrates with Ollama's native API (`/api/chat` ), supports streaming and tool calling, and can auto-discover local Ollama models when you opt in with `OLLAMA_API_KEY` (or an auth profile) and do not define an explicit `models.providers.ollama` entry.
2026-01-24 22:38:52 +00:00
2026-02-27 15:21:13 -08:00
< Warning >
**Remote Ollama users**: Do not use the `/v1` OpenAI-compatible URL (`http://host:11434/v1` ) with OpenClaw. This breaks tool calling and models may output raw tool JSON as plain text. Use the native Ollama API URL instead: `baseUrl: "http://host:11434"` (no `/v1` ).
< / Warning >
2026-01-24 22:38:52 +00:00
## Quick start
2026-03-11 14:00:22 -07:00
### Onboarding wizard (recommended)
The fastest way to set up Ollama is through the onboarding wizard:
```bash
openclaw onboard
```
Select **Ollama** from the provider list. The wizard will:
1. Ask for the Ollama base URL where your instance can be reached (default `http://127.0.0.1:11434` ).
2. Let you choose **Cloud + Local** (cloud models and local models) or **Local** (local models only).
3. Open a browser sign-in flow if you choose **Cloud + Local** and are not signed in to ollama.com.
4. Discover available models and suggest defaults.
5. Auto-pull the selected model if it is not available locally.
Non-interactive mode is also supported:
```bash
openclaw onboard --non-interactive \
--auth-choice ollama \
--accept-risk
```
Optionally specify a custom base URL or model:
```bash
openclaw onboard --non-interactive \
--auth-choice ollama \
--custom-base-url "http://ollama-host:11434" \
--custom-model-id "qwen3.5:27b" \
--accept-risk
```
### Manual setup
2026-03-11 20:08:45 +00:00
1. Install Ollama: [https://ollama.com/download ](https://ollama.com/download )
2026-01-24 22:38:52 +00:00
2026-03-11 20:08:45 +00:00
2. Pull a local model if you want local inference:
2026-01-24 22:38:52 +00:00
```bash
2026-03-11 20:08:45 +00:00
ollama pull glm-4.7-flash
# or
2026-02-06 01:35:38 +01:00
ollama pull gpt-oss:20b
# or
2026-01-24 22:38:52 +00:00
ollama pull llama3.3
```
2026-03-11 14:00:22 -07:00
3. If you want cloud models too, sign in:
2026-03-11 20:08:45 +00:00
```bash
ollama signin
```
4. Run onboarding and choose `Ollama` :
```bash
openclaw onboard
```
- `Local` : local models only
2026-03-11 14:00:22 -07:00
- `Cloud + Local` : local models plus cloud models
2026-03-11 20:08:45 +00:00
- Cloud models such as `kimi-k2.5:cloud` , `minimax-m2.5:cloud` , and `glm-5:cloud` do **not** require a local `ollama pull`
OpenClaw currently suggests:
- local default: `glm-4.7-flash`
- cloud defaults: `kimi-k2.5:cloud` , `minimax-m2.5:cloud` , `glm-5:cloud`
5. If you prefer manual setup, enable Ollama for OpenClaw directly (any value works; Ollama doesn't require a real key):
2026-01-24 22:38:52 +00:00
```bash
# Set environment variable
export OLLAMA_API_KEY="ollama-local"
# Or configure in your config file
2026-01-30 03:15:10 +01:00
openclaw config set models.providers.ollama.apiKey "ollama-local"
2026-01-24 22:38:52 +00:00
```
2026-03-11 20:08:45 +00:00
6. Inspect or switch models:
```bash
openclaw models list
openclaw models set ollama/glm-4.7-flash
```
7. Or set the default in config:
2026-01-24 22:38:52 +00:00
```json5
{
agents: {
defaults: {
2026-03-11 20:08:45 +00:00
model: { primary: "ollama/glm-4.7-flash" },
2026-01-31 21:13:13 +09:00
},
},
2026-01-24 22:38:52 +00:00
}
```
2026-01-24 23:05:53 +00:00
## Model discovery (implicit provider)
2026-01-24 22:38:52 +00:00
2026-01-30 03:15:10 +01:00
When you set `OLLAMA_API_KEY` (or an auth profile) and **do not** define `models.providers.ollama` , OpenClaw discovers models from the local Ollama instance at `http://127.0.0.1:11434` :
2026-01-24 23:05:53 +00:00
2026-03-11 20:08:45 +00:00
- Queries `/api/tags`
- Uses best-effort `/api/show` lookups to read `contextWindow` when available
- Marks `reasoning` with a model-name heuristic (`r1` , `reasoning` , `think` )
- Sets `maxTokens` to the default Ollama max-token cap used by OpenClaw
2026-01-24 23:05:53 +00:00
- Sets all costs to `0`
2026-03-11 20:08:45 +00:00
This avoids manual model entries while keeping the catalog aligned with the local Ollama instance.
2026-01-24 22:38:52 +00:00
To see what models are available:
```bash
ollama list
2026-01-30 03:15:10 +01:00
openclaw models list
2026-01-24 22:38:52 +00:00
```
To add a new model, simply pull it with Ollama:
```bash
ollama pull mistral
```
The new model will be automatically discovered and available to use.
2026-01-24 23:05:53 +00:00
If you set `models.providers.ollama` explicitly, auto-discovery is skipped and you must define models manually (see below).
2026-01-24 22:38:52 +00:00
## Configuration
2026-01-24 23:05:53 +00:00
### Basic setup (implicit discovery)
2026-01-24 22:38:52 +00:00
The simplest way to enable Ollama is via environment variable:
```bash
export OLLAMA_API_KEY="ollama-local"
```
2026-01-24 23:05:53 +00:00
### Explicit setup (manual models)
2026-01-24 22:38:52 +00:00
2026-01-24 23:05:53 +00:00
Use explicit config when:
2026-01-31 21:13:13 +09:00
2026-01-24 23:05:53 +00:00
- Ollama runs on another host/port.
- You want to force specific context windows or model lists.
2026-03-11 20:08:45 +00:00
- You want fully manual model definitions.
2026-01-24 22:38:52 +00:00
```json5
{
models: {
providers: {
ollama: {
2026-02-14 09:20:42 +09:00
baseUrl: "http://ollama-host:11434",
2026-01-24 22:38:52 +00:00
apiKey: "ollama-local",
2026-02-14 09:20:42 +09:00
api: "ollama",
2026-01-24 23:05:53 +00:00
models: [
{
2026-02-06 01:35:38 +01:00
id: "gpt-oss:20b",
name: "GPT-OSS 20B",
2026-01-24 23:05:53 +00:00
reasoning: false,
input: ["text"],
cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
contextWindow: 8192,
maxTokens: 8192 * 10
}
]
2026-01-24 22:38:52 +00:00
}
}
}
}
```
2026-01-30 03:15:10 +01:00
If `OLLAMA_API_KEY` is set, you can omit `apiKey` in the provider entry and OpenClaw will fill it for availability checks.
2026-01-24 23:05:53 +00:00
### Custom base URL (explicit config)
If Ollama is running on a different host or port (explicit config disables auto-discovery, so define models manually):
```json5
{
models: {
providers: {
ollama: {
apiKey: "ollama-local",
2026-02-27 15:21:13 -08:00
baseUrl: "http://ollama-host:11434", // No /v1 - use native Ollama API URL
api: "ollama", // Set explicitly to guarantee native tool-calling behavior
2026-01-31 21:13:13 +09:00
},
},
},
2026-01-24 23:05:53 +00:00
}
```
2026-02-27 15:21:13 -08:00
< Warning >
Do not add `/v1` to the URL. The `/v1` path uses OpenAI-compatible mode, where tool calling is not reliable. Use the base Ollama URL without a path suffix.
< / Warning >
2026-01-24 23:05:53 +00:00
### Model selection
2026-01-24 22:38:52 +00:00
Once configured, all your Ollama models are available:
```json5
{
agents: {
defaults: {
model: {
2026-02-06 01:35:38 +01:00
primary: "ollama/gpt-oss:20b",
fallbacks: ["ollama/llama3.3", "ollama/qwen2.5-coder:32b"],
2026-01-31 21:13:13 +09:00
},
},
},
2026-01-24 22:38:52 +00:00
}
```
2026-03-11 14:00:22 -07:00
## Cloud models
Cloud models let you run cloud-hosted models (for example `kimi-k2.5:cloud` , `minimax-m2.5:cloud` , `glm-5:cloud` ) alongside your local models.
To use cloud models, select **Cloud + Local** mode during onboarding. The wizard checks whether you are signed in and opens a browser sign-in flow when needed. If authentication cannot be verified, the wizard falls back to local model defaults.
You can also sign in directly at [ollama.com/signin ](https://ollama.com/signin ).
2026-01-24 22:38:52 +00:00
## Advanced
2026-01-24 23:05:53 +00:00
### Reasoning models
2026-01-24 22:38:52 +00:00
2026-03-11 20:08:45 +00:00
OpenClaw treats models with names such as `deepseek-r1` , `reasoning` , or `think` as reasoning-capable by default:
2026-01-24 22:38:52 +00:00
```bash
ollama pull deepseek-r1:32b
```
### Model Costs
Ollama is free and runs locally, so all model costs are set to $0.
2026-02-06 01:35:38 +01:00
### Streaming Configuration
2026-02-14 09:20:42 +09:00
OpenClaw's Ollama integration uses the **native Ollama API** (`/api/chat` ) by default, which fully supports streaming and tool calling simultaneously. No special configuration is needed.
2026-02-06 01:35:38 +01:00
2026-02-14 09:20:42 +09:00
#### Legacy OpenAI-Compatible Mode
2026-02-06 01:35:38 +01:00
2026-02-27 15:21:13 -08:00
< Warning >
**Tool calling is not reliable in OpenAI-compatible mode.** Use this mode only if you need OpenAI format for a proxy and do not depend on native tool calling behavior.
< / Warning >
2026-02-14 09:20:42 +09:00
If you need to use the OpenAI-compatible endpoint instead (e.g., behind a proxy that only supports OpenAI format), set `api: "openai-completions"` explicitly:
2026-02-06 01:35:38 +01:00
```json5
{
2026-02-14 09:20:42 +09:00
models: {
providers: {
ollama: {
baseUrl: "http://ollama-host:11434/v1",
api: "openai-completions",
2026-02-27 17:20:47 -08:00
injectNumCtxForOpenAICompat: true, // default: true
2026-02-14 09:20:42 +09:00
apiKey: "ollama-local",
models: [...]
}
}
}
2026-02-06 01:35:38 +01:00
}
```
2026-02-27 15:21:13 -08:00
This mode may not support streaming + tool calling simultaneously. You may need to disable streaming with `params: { streaming: false }` in model config.
2026-02-06 01:35:38 +01:00
2026-02-27 17:20:47 -08:00
When `api: "openai-completions"` is used with Ollama, OpenClaw injects `options.num_ctx` by default so Ollama does not silently fall back to a 4096 context window. If your proxy/upstream rejects unknown `options` fields, disable this behavior:
```json5
{
models: {
providers: {
ollama: {
baseUrl: "http://ollama-host:11434/v1",
api: "openai-completions",
injectNumCtxForOpenAICompat: false,
apiKey: "ollama-local",
models: [...]
}
}
}
}
```
2026-01-24 23:05:53 +00:00
### Context windows
2026-01-24 22:38:52 +00:00
2026-03-11 20:08:45 +00:00
For auto-discovered models, OpenClaw uses the context window reported by Ollama when available, otherwise it falls back to the default Ollama context window used by OpenClaw. You can override `contextWindow` and `maxTokens` in explicit provider config.
2026-01-24 22:38:52 +00:00
## Troubleshooting
### Ollama not detected
2026-01-24 23:05:53 +00:00
Make sure Ollama is running and that you set `OLLAMA_API_KEY` (or an auth profile), and that you did **not** define an explicit `models.providers.ollama` entry:
2026-01-24 22:38:52 +00:00
```bash
ollama serve
```
And that the API is accessible:
```bash
curl http://localhost:11434/api/tags
```
### No models available
2026-03-11 20:08:45 +00:00
If your model is not listed, either:
2026-01-31 21:13:13 +09:00
2026-03-11 20:08:45 +00:00
- Pull the model locally, or
2026-01-24 23:05:53 +00:00
- Define the model explicitly in `models.providers.ollama` .
To add models:
2026-01-24 22:38:52 +00:00
```bash
ollama list # See what's installed
2026-03-11 20:08:45 +00:00
ollama pull glm-4.7-flash
ollama pull gpt-oss:20b
2026-02-06 01:35:38 +01:00
ollama pull llama3.3 # Or another model
2026-01-24 22:38:52 +00:00
```
### Connection refused
Check that Ollama is running on the correct port:
```bash
# Check if Ollama is running
ps aux | grep ollama
# Or restart Ollama
ollama serve
```
## See Also
- [Model Providers ](/concepts/model-providers ) - Overview of all providers
2026-01-25 00:05:33 +00:00
- [Model Selection ](/concepts/models ) - How to choose models
- [Configuration ](/gateway/configuration ) - Full config reference