AI & Agents

How to Connect OpenClaw to LM Studio for Local LLM Agents

OpenClaw's default preload behavior conflicts with LM Studio's JIT model loading, causing models to stay permanently resident on memory-constrained machines. This guide walks through the full connection setup, from installing LM Studio through the OpenClaw onboarding flow, and covers the preload configuration fix that most integration tutorials leave out.

Fastio Editorial Team 9 min read
Running OpenClaw against a local LM Studio server keeps all data on your machine.

Why Local Models Matter for OpenClaw Agents

LM Studio serves large language models through an OpenAI-compatible API at localhost:1234. Since OpenClaw connects to any provider that speaks the OpenAI protocol, the two fit together without custom adapters. Your prompts, agent memory, and tool outputs stay on your machine, and inference costs nothing per token.

The privacy benefit goes beyond principle. According to a 2026 Index.dev survey, 44% of enterprises cite security as their greatest barrier to LLM adoption, ahead of regulatory risk and cost. Running inference locally removes the data residency question entirely. For individual developers, it also means experimenting freely without watching an API bill climb.

LM Studio supports GGUF models (via llama.cpp) and MLX models optimized for Apple Silicon. A Mac with 16GB or more of unified memory runs capable 8B-parameter models comfortably. Dedicated GPU rigs with 24GB VRAM handle larger models and longer context windows. The OpenClaw local models guide recommends running the largest model variant your hardware supports, since heavily quantized models increase vulnerability to prompt injection in agent workflows.

One configuration detail catches most newcomers: OpenClaw's default preload behavior can conflict with LM Studio's just-in-time model loading. If you run multiple models and notice that LM Studio stops swapping between them automatically, the fix is a single config change covered in the troubleshooting section below. The official LM Studio integration page documents the preload parameter and the full onboarding flow.

How to Install LM Studio and Start the Server

Download LM Studio from lmstudio.ai or install the headless daemon from the command line:

curl -fsSL https://lmstudio.ai/install.sh | bash

Once installed, browse the model library and download one that fits your hardware. The LM Studio integration docs recommend choosing a model with at least 50,000 tokens of context, since OpenClaw agent tool calls consume substantial context per turn. Larger, less-quantized variants also resist prompt injection better in agentic workflows, so pick the biggest model your RAM or VRAM can hold.

After downloading, start the local inference server. LM Studio offers both a GUI toggle and a CLI command:

lms server start --port 1234

Verify the server is running by listing available models:

curl http://localhost:1234/api/v1/models

You should see a JSON response listing your downloaded models. The model identifier follows an author/name pattern, like qwen/qwen3.5-9b. Copy this string exactly because you'll need it during OpenClaw's onboarding step.

If you plan to authenticate requests (useful when exposing LM Studio over a LAN), generate an API key in LM Studio's server settings and export it:

export LM_API_TOKEN="your-lm-studio-api-token"

For localhost-only usage, authentication is optional. LM Studio accepts unauthenticated requests by default when the server binds to 127.0.0.1.

Running the OpenClaw Onboarding Flow

OpenClaw's onboarding wizard handles provider configuration, model selection, and API key storage in one pass. If you haven't installed OpenClaw yet, follow the official install instructions for your platform before continuing.

Start the interactive onboarding:

openclaw onboard

When prompted for a provider, select LM Studio. The wizard asks for:

  1. Base URL: enter http://localhost:1234/v1
  2. API key: paste your LM_API_TOKEN value, or leave blank for unauthenticated local servers
  3. Default model: pick from the list of models LM Studio reports, or type the model key directly (e.g., qwen/qwen3.5-9b)

For CI pipelines or headless environments, skip the interactive prompts entirely:

openclaw onboard \
  --non-interactive \
  --accept-risk \
  --auth-choice lmstudio \
  --custom-base-url http://localhost:1234/v1 \
  --lmstudio-api-key "$LM_API_TOKEN" \
  --custom-model-id qwen/qwen3.5-9b

After onboarding, OpenClaw references the model with a provider prefix. Where LM Studio calls the model qwen/qwen3.5-9b, OpenClaw calls it lmstudio/qwen/qwen3.5-9b. You can switch models later without re-running onboarding:

openclaw models set lmstudio/qwen/qwen3.5-9b

To verify the connection, run a quick test prompt. If you get a coherent response, the wiring is complete. If you see an HTTP 401 error, double-check that LM_API_TOKEN matches LM Studio's configured key.

Terminal output showing OpenClaw connected to a local model provider
Fastio features

Give your local agents persistent cloud storage

generous storage workspace with built-in RAG, MCP server access, and no credit card required. Your OpenClaw agent writes files locally and stores them where they last.

Model Configuration and Context Windows

The onboarding wizard writes a configuration file that you can edit directly for fine-tuning. The provider block looks like this:

{
  "models": {
    "providers": {
      "lmstudio": {
        "baseUrl": "http://localhost:1234/v1",
        "apiKey": "${LM_API_TOKEN}",
        "api": "openai-completions"
      }
    }
  }
}

If your LM Studio version supports the Responses API, switch the api field to openai-responses for richer tool-use handling. The OpenClaw docs recommend this when available, with openai-completions as the fallback.

Context window sizing matters more than model size. OpenClaw tracks token usage and issues warnings when remaining capacity drops below 20% of the declared window (with an 8,000-token floor). At 10% remaining (4,000-token floor), it blocks new tool calls entirely. Declare accurate context values in your model config to avoid unexpected stops mid-task.

You can also lower the effective window if your hardware struggles with long contexts:

{
  "agents": {
    "defaults": {
      "contextTokens": 32000
    }
  }
}

For a hybrid setup, configure a hosted model as a fallback. Setting models.mode to merge lets OpenClaw try your local LM Studio model first and fall back to a cloud provider like Claude or GPT-4 if the local model is unavailable. This is useful for long-running agent tasks where you want the cost savings of local inference but can't afford downtime if LM Studio crashes or the model runs out of VRAM.

Embedding support is another piece worth configuring. If you want OpenClaw's memory search to run locally too, point the embedding provider at LM Studio:

openclaw config set agents.defaults.memorySearch.provider lmstudio
openclaw gateway restart

This keeps your agent's entire memory pipeline on-device.

For teams with a powerful GPU machine on the network, LM Studio's LM Link feature lets you run OpenClaw on a laptop while offloading inference to a remote server. Set the base URL to the remote host's address (e.g., http://gpu-box.local:1234/v1) and make sure LM Studio binds beyond loopback on that machine.

How to Fix the JIT Model Loading Conflict

LM Studio's JIT (just-in-time) model loading is designed for memory efficiency. When enabled, LM Studio loads a model into memory only when a request arrives and unloads it after an idle timeout. This lets you keep several large models downloaded without reserving VRAM for all of them simultaneously.

OpenClaw's default configuration preloads the configured model at startup, which overrides LM Studio's JIT lifecycle management. The model stays resident in memory regardless of your idle timeout settings, and LM Studio won't automatically swap it for a different model when you need one.

On a machine with enough memory for one large model at a time, this creates a problem. You load Model A for a coding task, finish, and expect LM Studio to unload it so you can run Model B for a writing task. Instead, Model A stays pinned and Model B either fails to load or forces an out-of-memory crash.

The fix is a single configuration change. Disable OpenClaw's preload step so LM Studio's native lifecycle management stays in control:

{
  "models": {
    "providers": {
      "lmstudio": {
        "baseUrl": "http://localhost:1234/v1",
        "apiKey": "${LM_API_TOKEN}",
        "api": "openai-completions",
        "params": {
          "preload": false
        }
      }
    }
  }
}

With preload: false, OpenClaw skips the load API call entirely. LM Studio's JIT system handles loading when the first inference request arrives and unloads based on your configured idle TTL. The tradeoff is a brief cold-start delay on the first prompt after a model swap, typically a few seconds depending on model size and disk speed.

Keep preload: true (or omit the param, since true is the default) if you run a single model exclusively and want it warm at all times. The JIT conflict only matters when you cycle between models or share the GPU with other processes.

Configuration panel showing model loading and memory management settings

Persistent Storage for Agent Output

Local models solve the inference privacy problem, but your agent still needs somewhere to put its work. Files written to the local disk are fine during development. In production, you want persistence that survives machine reboots, container resets, and team handoffs.

Local storage works until it doesn't. A Docker container restart wipes everything inside it. A laptop disk crash takes your agent's accumulated knowledge with it. S3 or Google Drive can store files, but neither indexes them for semantic search or provides audit trails for agent actions.

Fastio fills this gap with workspaces designed for agent teams. The Business Trial includes 50GB of storage, included credits per month, and 5 workspaces, with no credit card required and no expiration. Your OpenClaw agent writes files to a Fastio workspace via the MCP server, which exposes 19 tools for storage, search, sharing, and workflow operations over Streamable HTTP at /mcp.

What makes this useful for local-model setups specifically is Intelligence Mode. Enable it on a workspace and every uploaded file gets automatically indexed for semantic search. Your OpenClaw agent can then query those files through the MCP server's search tools, with citations pointing back to exact source passages. This gives you RAG capabilities without running a separate vector database or embedding pipeline.

The ownership transfer feature is worth noting for contractor or freelancer workflows. An agent builds a workspace full of deliverables, then transfers ownership to the client. The agent retains admin access for ongoing maintenance, but the client owns the data. That clean handoff is harder to orchestrate with raw S3 buckets or shared Drive folders.

If you're already running an OpenClaw agent with local LM Studio inference, adding Fastio as the storage layer takes about five minutes. Install the ClawHub skill, authenticate once, and your agent has persistent cloud storage that it can search by meaning.

Frequently Asked Questions

How do I use LM Studio with OpenClaw?

Install LM Studio, download a model with at least 50,000 tokens of context, and start the local server on port 1234. Then run `openclaw onboard`, select LM Studio as your provider, and enter `http://localhost:1234/v1` as the base URL. OpenClaw connects through LM Studio's OpenAI-compatible API with no additional adapters needed.

Does OpenClaw work with local LLMs?

Yes. OpenClaw supports any backend that exposes an OpenAI-compatible `/v1/chat/completions` endpoint. LM Studio is the recommended local option, but vLLM, Ollama, MLX, SGLang, and LiteLLM also work. The OpenClaw docs recommend running larger, less-quantized models for better resistance to prompt injection in agent workflows.

How do I fix LM Studio JIT loading issues with OpenClaw?

Set `preload` to `false` in your OpenClaw provider configuration under `models.providers.lmstudio.params`. This stops OpenClaw from preloading the model at startup, which otherwise overrides JIT settings and prevents automatic model unloading. With preload disabled, LM Studio loads models on first request and unloads them based on your idle TTL settings.

What models work best with OpenClaw and LM Studio?

Choose a model with a context window above 50,000 tokens, since agent tool calls consume substantial context. Qwen 3.5 9B and Llama 3.1 8B Q4 are good starting points for 16GB machines. The OpenClaw gateway docs recommend full-size model variants over heavily quantized ones, because smaller quants increase vulnerability to prompt injection attacks.

Can I use LM Studio on one machine and OpenClaw on another?

Yes. LM Studio's LM Link feature supports remote inference. Set LM Studio to bind beyond loopback on the GPU machine, then configure OpenClaw's base URL to point to the remote host (e.g., `http://gpu-box.local:1234/v1`). This lets you run OpenClaw on a laptop while a more powerful machine handles inference.

Related Resources

Fastio features

Give your local agents persistent cloud storage

generous storage workspace with built-in RAG, MCP server access, and no credit card required. Your OpenClaw agent writes files locally and stores them where they last.