Setting Up Ollama & Local Models with OpenClaw
Complete guide to configuring Ollama for local LLM inference with OpenClaw, including Docker setup, WSL2 configuration, and troubleshooting common issues like 0/200k tokens and empty responses.
⚠️ The Problem
You're trying to use Ollama with OpenClaw for local LLM inference, but experiencing issues like: the TUI sits at "0/200k tokens" with no response, models don't appear in the provider list, or you get empty responses despite the connection appearing successful. Common symptoms include:
- TUI shows
tokens 0/200k (0%)and never progresses - "Say hello in one sentence" produces no output
clawdbot doctorpasses but model doesn't respond- Docker setup fails with validation errors
- Model works with Python/curl but not OpenClaw
🔍 Why This Happens
There are several common causes for Ollama integration failures:
-
Missing or incorrect API format: Ollama requires
api: "openai-responses"orapi: "openai-completions"in your config, not the default format. -
Wrong baseUrl format: The URL must include
/v1suffix:http://127.0.0.1:11434/v1— not justhttp://127.0.0.1:11434. -
Docker networking: When running OpenClaw in Docker,
127.0.0.1refers to the container, not your host. You needhost.docker.internal(Docker Desktop) or--network=host(Linux). -
Incomplete config validation: Setting
apiKeyalone withoutbaseUrlcauses:Config validation failed: models.providers.ollama.baseUrl: Invalid input: expected string, received undefined -
Model too large for hardware: Large models (32B+) consume RAM needed for context, causing timeouts or empty responses.
-
Ollama not running: The Ollama service must be actively serving, not just installed.
✅ The Fix
Step 1: Verify Ollama is Running
First, confirm Ollama is running and has models available:
# Check if Ollama is running and list modelsollama list# If not running, start the serviceollama serve# Test that the API respondscurl http://127.0.0.1:11434/api/tagsYou should see your installed models listed. If ollama list fails, Ollama isn't running.
Step 2: Configure OpenClaw Correctly
The most critical setting is the API format. Add this to your ~/.openclaw/openclaw.json:
{ "models": { "providers": { "ollama": { "baseUrl": "http://127.0.0.1:11434/v1", "apiKey": "ollama-local", "api": "openai-responses", "models": [ { "id": "llama3.2:latest", "name": "Llama 3.2", "contextWindow": 32768, "maxOutput": 8192 } ] } } }, "agents": { "defaults": { "model": { "primary": "ollama/llama3.2:latest" } } }}Critical points:
baseUrlMUST end with/v1apiMUST be set to"openai-responses"or"openai-completions"- Model ID must match exactly what
ollama listshows (including the:tag) apiKeycan be any non-empty string (Ollama doesn't validate it)
Step 3: Docker-Specific Configuration
If running OpenClaw in Docker, you need different networking:
# For Docker Desktop (macOS/Windows)docker compose exec openclaw-gateway node dist/index.js config set 'models.providers.ollama={"baseUrl":"http://host.docker.internal:11434/v1","apiKey":"ollama-local","api":"openai-responses"}'Alternative: Environment variable approach (add to docker-compose.yml):
environment: - OLLAMA_API_KEY=ollama-local - OLLAMA_BASE_URL=http://host.docker.internal:11434/v1For Linux without Docker Desktop:
- Use
--network=hoston the container, OR - Add Ollama's container IP to
/etc/hostsand reference by hostname
Step 4: WSL2-Specific Setup
WSL2 has networking quirks. Use these settings:
# Create/edit ~/.openclaw/.envecho 'OLLAMA_API_KEY=ollama-local' >> ~/.openclaw/.env# Ensure Ollama is accessible from WSL2curl http://localhost:11434/api/tagsIf localhost doesn't work, try 127.0.0.1 or check your WSL2 networking configuration.
Step 5: Choose the Right Model Size
Hardware recommendations from community experience:
| VRAM | RAM | Recommended Models |
|---|---|---|
| 6GB (RTX 2060) | 16GB | Llama 3.2 3B, Phi-4, Qwen 2.5 3B |
| 8GB | 16GB | Llama 3.1 8B, Mistral 7B |
| 12GB+ | 32GB | Qwen 2.5-coder:14B, DeepSeek-R1:14B |
| 24GB+ | 64GB+ | 32B models (with limited context) |
Warning: A 32B model on 32GB RAM leaves little space for context, causing empty responses or timeouts.
Step 6: Restart and Verify
# Restart the gateway to apply changesopenclaw gateway restart# Run diagnosticsopenclaw doctor --fix# Verify model is configuredopenclaw models list# Check model status shows your Ollama modelopenclaw models statusStep 7: Test the Connection
# Start the TUI and send a test messageopenclaw tui# Type a simple prompt> Say hello in one sentence.If you still see 0/200k tokens after 30+ seconds, check the gateway logs:
# In another terminalopenclaw gateway logs --followLook for error messages like connection refused, timeout, or model loading errors.
Alternative: Implicit Auto-Discovery
If you don't want to explicitly define models, OpenClaw can auto-discover them:
# Just set the API key, don't define providers.ollama explicitlyexport OLLAMA_API_KEY=ollama-local# OpenClaw will discover models at http://127.0.0.1:11434 automaticallyopenclaw models listThis works when you DON'T have an explicit models.providers.ollama block in your config.
🔥 Your AI should run your business, not just answer questions.
We'll show you how.Free to join.
📋 Quick Commands
| Command | Description |
|---|---|
| ollama list | List installed Ollama models and verify service is running |
| ollama serve | Start the Ollama service if not running |
| curl http://127.0.0.1:11434/api/tags | Test Ollama API is responding |
| openclaw gateway restart | Restart gateway after config changes |
| openclaw doctor --fix | Run diagnostics and auto-fix common issues |
| openclaw models list | Show all configured models including Ollama |
| openclaw models status | Check model connectivity and auth status |
| openclaw gateway logs --follow | Stream gateway logs to debug connection issues |
| ollama ps | Show currently loaded/running models in Ollama |
Related Issues
📚 You Might Also Like
🐙 Your AI should run your business.
Weekly live builds + template vault. We'll show you how to make AI actually work.Free to join.
Join Vibe Combinator →