Summer Sale: up to 80% off Claim deal

How to set up OpenClaw with Ollama on a VPS

How to set up OpenClaw with Ollama on a VPS

To set up OpenClaw with Ollama on a VPS, install Ollama, connect it to OpenClaw as an AI model provider, choose a model to run, and test the connection before securing the setup.

Pairing OpenClaw with Ollama lets you create private, autonomous AI agents that run on your own server instead of a commercial AI provider’s infrastructure.

Many people start using OpenClaw with commercial large language models (LLMs), such as OpenAI’s GPT or Anthropic’s Claude models. However, these providers charge per token. Every prompt your agent sends and every response it generates adds to your usage costs.

Using OpenClaw with Ollama offers a different approach. Ollama lets you run open-source AI models on your own infrastructure. As a result, you only pay the hosting costs for OpenClaw and Ollama, such as the annual fee of a virtual private server (VPS).

Follow these steps to run OpenClaw with Ollama:

  1. Check and prepare the system prerequisites.
  2. Install Ollama on the same server as OpenClaw or on a separate server.
  3. Configure Ollama as an AI model provider in OpenClaw.
  4. Choose an Ollama model to run locally or access through a remote Ollama server.
  5. Confirm that the connection between OpenClaw and Ollama works.
  6. Secure OpenClaw and Ollama on your VPS.

How do OpenClaw and Ollama work together?

OpenClaw and Ollama work together by pairing an AI agent gateway (OpenClaw) with a local AI model runner (Ollama). This connection lets OpenClaw use Ollama to process prompts and run private AI workflows without commercial API fees.

When you send a message through Telegram, Slack, or another messaging channel connected to OpenClaw, the OpenClaw Gateway (a background process that manages messaging channels, agent sessions, tools, and model connections) forwards your request to Ollama.

Ollama then processes the request with your selected AI model and sends the response back through the Gateway to the messaging app.

This workflow lets you interact with the AI agent directly from your preferred messaging platform without opening the OpenClaw or Ollama interface.

This setup offers three main advantages:

  • Greater privacy. Ollama can process prompts and responses on your own infrastructure instead of sending them to a commercial AI provider.
  • More predictable costs. You don’t pay per-token API fees, although you still need to cover server, electricity, and maintenance costs.
  • More control. You can choose which supported model to run and manage where OpenClaw stores and processes your data.

How to configure OpenClaw with Ollama on a VPS

To configure OpenClaw with Ollama on a VPS, check the system requirements, install Ollama on the VPS, configure Ollama in OpenClaw, and choose an AI model. Then, test the connection and secure your setup if needed.

1. Check the prerequisites

Before setting up Ollama with OpenClaw on your VPS, make sure you have a working OpenClaw installation and enough RAM, CPU, and storage for your chosen AI model.

The table below lists the minimum and recommended server resources. Requirements vary because larger Ollama models need more memory, processing power, and storage.

ResourceMinimumRecommended
RAM4 GB8–16 GB, depending on the model size
CPU1 vCPU2–4 vCPUs
Storage50 GB NVMe100 GB or more of NVMe storage for local model files

If you don’t have a VPS to set up OpenClaw and Ollama, you can purchase one from a reliable provider such as Hostinger.

Hostinger offers a preconfigured OpenClaw template, so you don’t need to install OpenClaw manually through the command-line interface (CLI).

Simply choose a VPS plan based on the resource requirements of the model you want to run. After you complete the purchase, Hostinger will deploy the preconfigured OpenClaw environment for you.

2. Install Ollama on your VPS

You can install Ollama on the same VPS as OpenClaw, or on a separate one to isolate resource usage and give Ollama access to more powerful hardware.

The installation process is nearly identical for both setups. First, update the package index and install curl:

sudo apt update && sudo apt install curl -y

Then, run Ollama’s official installation script:

curl -fsSL https://ollama.com/install.sh | sh

Run the following command to confirm that Ollama was installed successfully:

ollama --version

The installation script configures Ollama as a system service. Check its status with:

systemctl status ollama

If the service isn’t running, start it with:

sudo systemctl start ollama

You can also configure Ollama to start automatically when the server boots:

sudo systemctl enable ollama

If you installed Ollama on a separate VPS, note its IP address. You’ll need it later when configuring Ollama as the AI model provider in OpenClaw. Hostinger VPS customers can find the IP address in hPanel by going to VPS → Manage → Overview → IP.

By default, Ollama listens for connections on 127.0.0.1:11434, which means only applications on the same server can access it. To let OpenClaw connect from another VPS, configure Ollama to listen on the server’s network interface.

Open the Ollama systemd configuration editor:

sudo systemctl edit ollama

Add the following configuration:

[Service]
Environment="OLLAMA_HOST=0.0.0.0:11434"

Save the file. Then, reload systemd and restart Ollama:

sudo systemctl daemon-reload
sudo systemctl restart ollama

Next, while still connected to the Ollama VPS, configure Uncomplicated Firewall (UFW) to allow connections to port 11434 only from your OpenClaw VPS. Replace openclaw-vps-ip with the OpenClaw VPS IP address:

sudo ufw allow from openclaw-vps-ip to any port 11434 proto tcp

Check the firewall rules:

sudo ufw status

3. Configure the Ollama provider in OpenClaw

After installing Ollama, connect it to OpenClaw as the AI model provider.

Important

Important! If you set up OpenClaw and Ollama on separate VPSs, run all commands in this step on your OpenClaw server, not on the Ollama server.

Access the OpenClaw container:

docker exec -it your-openclaw-container bash

Once you’re inside the container, start the onboarding tool:

openclaw onboard

The onboarding tool guides you through the configuration. When prompted, select Ollama as the model provider.

Then, choose one of these deployment modes:

  • Ollama. Use both local and cloud models, with cloud models available as a fallback for more demanding tasks.
  • Ollama Cloud. Use Ollama Cloud models without installing locally.

The tool then asks for the Ollama host address. Enter the address that matches your setup:

  • http://host.docker.internal:11434. Use this address if Ollama runs on the same VPS. It lets the OpenClaw container connect to Ollama on the host machine.
  • http://your-ollama-vps-ip:11434. Use this address if Ollama runs on a separate server. Replace your-ollama-vps-ip with the IP address you noted during installation.

Skip this prompt if you chose Ollama Cloud, because OpenClaw connects directly to ollama.com.

If the onboarding command doesn’t work or you need to customize specific settings, configure the connection manually. Open the OpenClaw configuration file inside the container with the nano text editor:

nano ~/.openclaw/config.json
{
   "models": {
      "providers": {
         "ollama": {
            "baseUrl": "http://host.docker.internal:11434",
            "apiKey": "ollama-local",
            "api": "ollama",
            "models": [
               {
                  "id": "gemma4",
                  "name": "gemma4",
                  "input": ["text"],
                  "params": {
                     "num_ctx": 65536
                  }
               }
            ]
         }
      }
   }
}

Adjust these settings based on your setup:

  • baseUrl. Use http://host.docker.internal:11434 if Ollama runs on the same VPS. If it runs on a separate server, use http://your-ollama-vps-ip:11434 instead.
  • Model name and API key. Replace gemma4 with the model you want to use. For cloud models, replace ollama-local with your Ollama API key and change the model name to a cloud model, such as kimi-k3:cloud.
  • params.num_ctx. Set this value to at least 65536 for local models. OpenClaw agents need at least 64,000 tokens of context to handle multi-step tasks without losing track of earlier steps. Cloud models manage context automatically, so you can remove this setting if you only use cloud models.

Save the file by pressing Ctrl + X → Y → Enter. Then, restart the OpenClaw Gateway to apply the changes:

openclaw gateway restart

Warning

Warning! Don’t append /v1 to the Ollama base URL. The /v1 path activates OpenAI-compatible mode, which breaks tool calling and can cause the agent to output raw JSON as plain text instead of producing functional responses.

4. Choose an Ollama model for OpenClaw

Choose a specific Ollama model for your agent. Your pick affects how well the agent reasons, how quickly it responds, and how much RAM it uses.

If OpenClaw and Ollama run on the same VPS, you can run these commands on that server. If they run on separate VPSs, pay close attention to where you run each command.

For local models, start by downloading the model. Run this command on the server where Ollama is installed:

ollama pull gemma4

Then, switch to your OpenClaw VPS. If you’re not already inside the container, enter it first, then set the model:

docker exec -it your-openclaw-container bash
openclaw models set ollama/gemma4

For cloud models, run these commands instead on your OpenClaw server:

docker exec -it your-openclaw-container bash
openclaw models set ollama/kimi-k3:cloud

If you chose a local model, test it before checking the OpenClaw connection. On your Ollama server and run the model directly:

ollama run gemma4

Start with a basic conversational prompt. Then, ask the model to complete a structured task, such as formatting data into a specific layout or following a multi-step instruction.

While the model runs, monitor your VPS memory usage and response speed.

If the system becomes unstable or too slow to use, the model is too large for your server. Switch to a smaller local model or a cloud model before continuing.

5. Test the OpenClaw and Ollama connection

Verify that OpenClaw can reach Ollama, send prompts, and receive responses. Run all these commands inside the OpenClaw container except the last one.

First, check that OpenClaw can reach Ollama over the network. Send a test request directly to the Ollama API:

curl http://host.docker.internal:11434/api/chat 
   -d '{"model":"gemma4","messages":[{"role":"user","content":"Reply with: pong"}]}'

Replace host.docker.internal with your Ollama server’s IP address if Ollama runs on a separate VPS. Also, replace gemma4 with the model you selected.

A JSON response containing “pong” confirms the network connection works. If the request fails, make sure the Ollama service is running, the firewall allows access, and the server address is correct.

Next, verify that OpenClaw is configured correctly. Run a test prompt through OpenClaw that bypasses the agent’s tools:

openclaw infer model run 
   --model ollama/gemma4 
   --prompt "Reply with exactly: pong"

If this command fails, check the baseUrl, api, and model name settings in ~/.openclaw/config.json.

Then, confirm that the model can handle tool calls. Enable a low-risk tool, such as file reading, then ask the agent to complete a task that requires it. For example, ask the agent to list the files in a directory.

If the agent completes the task correctly, your setup is working. If it makes up the result instead of calling the tool, the model doesn’t reliably support OpenClaw’s tool-calling format. Pull a different model and set it as the active model.

After all three checks pass, verify the context window configuration on your Ollama VPS:

ollama ps

The CONTEXT column should show 65536 or higher. If it shows 4096, the num_ctx setting in ~/.openclaw/config.json didn’t take effect. Update the value, save the file, and restart the OpenClaw Gateway.

6. Secure the Ollama API on your VPS

If you installed Ollama on a separate server, the firewall rules already restrict API access to your OpenClaw VPS. For same-server setups, Ollama’s default 127.0.0.1 binding automatically blocks external access.

The remaining concern is how secure OpenClaw is. When you enable tools, the agent can read files, run commands, and send messages on your behalf.

A misunderstood instruction or malicious prompt can cause real damage if the agent has unrestricted access.

Take these steps to secure OpenClaw:

  • Run the OpenClaw container under a dedicated user with limited file system access instead of running it as root.
  • Disable tools that your workflow doesn’t need, such as shell access, browser access, and file writing. Start with the minimum permissions required, then expand them only after testing the workflow safely.
  • Enable approval prompts for any action that modifies files, sends messages, or runs commands. Review the tool arguments in the approval prompt, not just the tool name, because the agent can call the correct tool with unsafe parameters.
  • Review OpenClaw logs regularly for unexpected tool calls, especially after tasks that produced unusual or incorrect results.

What are the best Ollama models for OpenClaw?

The best Ollama models for OpenClaw on a VPS are cloud models like kimi-k3:cloud and qwen3.5:cloud for complex agent tasks, or local models like gemma4 and qwen3.5 for greater data privacy.

The right choice depends on how much RAM your VPS has, whether you need your data to stay on the server, and how reliably the model handles OpenClaw’s tool calls.

Here are some recommended Ollama cloud models:

ModelContext windowBest for
kimi-k3:cloud1 million tokensResearch, multimodal tasks, and long agent workflows
kimi-k2.7-code:cloud256K tokensCoding and multi-step tool use
qwen3.5:cloud256K tokensCoding, document analysis, and image understanding
gemma4:cloud256K tokensGeneral reasoning, coding, and multimodal tasks

Cloud models are a practical starting point for most VPS users because Ollama runs the model remotely instead of using your server’s RAM and CPU.

Some recommended Ollama local models include:

ModelDownload sizeMaximum contextBest for
gemma49.6 GB128K tokensGeneral reasoning, coding, and agent workflows
qwen3.56.6 GB256K tokensCoding, vision, and document processing
qwen3-coder:30b19 GB256K tokens (natively), 1M tokens (extrapolation)Coding-focused agent tasks

Local models run entirely on your VPS. Since most VPS plans don’t include a dedicated GPU, they may respond more slowly than cloud models, especially during multi-step tasks. However, your prompts and responses stay on your server.

The maximum context column shows the highest value each model supports. The context window you can use in practice depends on your available RAM, model version, quantization, and other running services.

Best practices for running OpenClaw with Ollama

Some of the best practices for running OpenClaw with Ollama include preloading local models, using specific model tags, backing up OpenClaw regularly, and testing other models as your workflows become more complex.

  • Preload local models before important tasks. Ollama unloads models after five minutes of inactivity by default. The next request may take longer while the model reloads. Run ollama run gemma4 “” on your Ollama server before starting a time-sensitive task. You can also use Ollama’s keep_alive setting to keep the model loaded longer.
  • Use a specific model tag. When you configure OpenClaw or run ollama pull, specify the exact model tag you tested instead of relying on the floating latest tag. This keeps your agent on the same model version until you intentionally update it.
  • Back up OpenClaw regularly. Run openclaw backup create on a schedule to back up your configuration, credentials, agent state, and workspace data. Store the backup in a secure location because it may contain sensitive information. You can also verify a backup with openclaw backup verify.
  • Switch models when tasks become more complex. A model that handles simple prompts may struggle with long conversations or workflows that require several tool calls. Consider switching to a stronger model when your current one loses context or produces unreliable tool calls. Test the candidates with your actual OpenClaw tasks instead of relying only on model size or benchmark scores.

How to troubleshoot common OpenClaw and Ollama errors

To troubleshoot common OpenClaw and Ollama errors, verify that OpenClaw can reach the Ollama server, confirm that both tools use the same model name and provider URL, check the context window, and review the Ollama logs for memory or timeout issues.

  • OpenClaw can’t reach Ollama. Run the curl connection test inside the OpenClaw container. If it returns “Connection refused,” switch to the Ollama VPS and run systemctl status ollama to confirm that the service is running. If Ollama runs on a separate VPS, make sure OLLAMA_HOST is set to 0.0.0.0:11434 and the firewall allows connections from the OpenClaw VPS IP address to port 11434. After changing OLLAMA_HOST, restart Ollama with sudo systemctl restart ollama.
  • OpenClaw can’t find the model. On the Ollama VPS, run ollama list to confirm that you downloaded the model. Then, run openclaw models list –provider ollama inside the OpenClaw container to check which Ollama models OpenClaw recognizes. Make sure the model name and tag match exactly. For example, gemma4 uses the default latest tag, while gemma4:12b selects a specific variant. After correcting the name, set the model again with openclaw models set ollama/model-name.
  • The agent outputs raw JSON instead of calling tools. Inside the OpenClaw container, check whether the Ollama baseUrl ends with /v1. OpenClaw’s native Ollama provider requires the base URL without this suffix, such as http://host.docker.internal:11434 or http://your-ollama-ip:11434. Remove /v1, save the configuration, and restart the Gateway with openclaw gateway restart.
  • The agent runs out of context during multi-step tasks. On the Ollama VPS, run ollama ps and check the CONTEXT column. If the value is too low for your workflow, run openclaw config file inside the OpenClaw container to locate the active configuration file. Increase params.num_ctx, save the file, and restart the Gateway with openclaw gateway restart. Note that larger context windows use more memory, so choose a value your server can handle.
  • Ollama returns incomplete responses or stops unexpectedly. On the Ollama VPS, run journalctl -u ollama –no-pager –follow –pager-end to view the service logs. If the logs indicate memory pressure, reduce the context window or switch to a smaller model. If slow inference causes requests to time out, increase the Ollama provider’s timeoutSeconds value in the OpenClaw configuration file. Then, restart the Gateway from the OpenClaw container.

How does running Ollama compare to using external AI APIs?

Running Ollama locally means hosting open-source AI models on your own infrastructure, while Ollama Cloud and external AI APIs run models on infrastructure managed by third-party providers.

The main tradeoff is greater control and data privacy versus easier scaling, faster setup, and less infrastructure maintenance.

FactorSelf-hosted OllamaOllama CloudExternal API, such as OpenAI or Anthropic
Model usage costNo per-token model feesFree and paid plans with usage limitsUsually charged by input and output token usage
Infrastructure costVPS hosting and computing resourcesVPS hosting for OpenClawVPS hosting for OpenClaw
Data handlingPrompts and responses stay on your serverOllama processes prompts and responses temporarily in the cloudThe API provider processes prompts and responses according to its data policies
Model maintenanceYou manage Ollama, model files, updates, and server resourcesOllama manages the model infrastructureThe API provider manages the model infrastructure
PerformanceDepends on your VPS hardware and Ollama’s model sizeOptimized by Ollama’s cloud infrastructureDepends on the provider’s cloud infrastructure
ScalingUpgrade your VPS or add more serversManaged by Ollama within your plan limitsManaged by the provider within your account limits

Self-hosted Ollama removes per-token model fees, but you’re responsible for installing and updating Ollama, managing model files, and providing enough RAM, storage, and processing power on your VPS.

Ollama doesn’t receive your prompts or responses when you run models locally.

With Ollama Cloud, the models run on remote infrastructure, so they don’t use your VPS RAM or GPU. Ollama offers free and paid plans with different cloud usage limits.

According to Ollama’s privacy policy, it processes cloud prompts and responses temporarily to provide the service. Ollama says it doesn’t log this content, use it for training, or retain it after processing.

External APIs such as OpenAI and Anthropic also manage the model infrastructure. They generally charge different rates for input and output tokens, although pricing varies by model and may include separate charges for tools or other features.

Ultimately, your choice affects the total cost of running your existing OpenClaw setup. Self-hosted Ollama shifts more of the cost to VPS resources and maintenance, while cloud models and external APIs add subscription or usage-based costs.

How to expand the OpenClaw and Ollama setup

You can expand your OpenClaw and Ollama setup by adding models, connecting messaging channels, enabling web search, installing skills, and documenting your configuration as a safety net.

  • Add or switch models. Run ollama pull model-name on your Ollama server to download another local model. Then, run openclaw models set ollama/model-name inside the OpenClaw container to make it the default model. To use an Ollama Cloud model, sign in to Ollama and set the model with openclaw models set ollama/cloud-model-name.
  • Connect a messaging channel. Run openclaw channels add inside the OpenClaw container. Then, select a channel and enter the required credentials. Add one channel at a time, and test incoming and outgoing messages before connecting another. Hostinger customers can follow our guide on connecting OpenClaw to Telegram and WhatsApp.
  • Enable web search. Run ollama signin on your Ollama server, then run openclaw config –section web inside the OpenClaw container. Follow the prompts to select and configure a search provider.
  • Add skills for specific workflows. Run openclaw skills search “keyword” inside the OpenClaw container to find a skill on ClawHub. Install it with openclaw skills install @owner/skill-name, then test it with a low-risk task before giving it access to sensitive files, accounts, or commands.
  • Document your setup. Record the model name and tag, Ollama host address, connected channels, enabled skills, firewall rules, and backup location. Store this information outside the VPS so you can access it if you migrate the server or a faulty update makes the current installation unusable.
Author
The author

Ariffud Muhammad

Ariffud is a Technical Content Writer with an educational background in Informatics. He has extensive expertise in Linux and VPS, authoring over 200 articles on server management and web development. Follow him on LinkedIn.

What our customers say