Models & Providers Local Models

OpenClaw + LM Studio: Build Local Agents Without Cloud Costs

Zero API costs. Zero data leaving your machine. Zero rate limits. LM Studio turns any laptop into a private inference server — and OpenClaw connects to it in under five minutes with one config block.

RN
R. Nakamura
Developer Advocate
Feb 12, 2025 13 min read 7.6k views
Updated Feb 12, 2025
Key Takeaways
  • LM Studio exposes an OpenAI-compatible API at http://localhost:1234/v1 — OpenClaw connects to it with zero custom code
  • Set provider type to openai-compatible and point base_url at your LM Studio server to get agents running locally
  • Mistral 7B Instruct and LLaMA 3 8B Instruct are strong defaults — both under 5GB and fast on modern hardware
  • GPU acceleration (Metal on Mac, CUDA on Windows/Linux) gets you 30–80 tok/s — adequate for real-time agent use
  • All inference stays on your machine — zero data exposure, no rate limits, no monthly bill from an API provider

Cloud API costs compound fast when you're running agents at scale. One busy research agent can burn through $50–200/month in GPT-4 tokens without breaking a sweat. LM Studio eliminates that entirely. Download a model once, run it forever, keep every byte of data on your hardware. Here's exactly how to wire it into OpenClaw.

Why LM Studio Is the Right Local Backend

LM Studio does one thing better than any other local model runner: it makes the setup painless. Download the app, pick a model from its built-in catalog, click a toggle to start the server. That's it. No Python environment, no CUDA configuration, no compiling llama.cpp from source.

The critical feature for OpenClaw compatibility is LM Studio's OpenAI-compatible API server. It mirrors the same REST interface as OpenAI's API — same endpoint paths, same request format, same response structure. OpenClaw already knows how to talk to OpenAI's API. So it talks to LM Studio's server the exact same way.

As of early 2025, LM Studio supports macOS (Apple Silicon and Intel), Windows, and Linux. Apple Silicon users get the best experience — Metal GPU acceleration is built in and models run fast even on base M1 chips.

💡
Hardware Reality Check

A 7B parameter model needs about 5GB RAM to run comfortably. A 13B model needs ~9GB. A 70B model needs ~45GB or multi-GPU. For OpenClaw agents running in real time, stick to 7B–13B models unless you have serious hardware. They're fast enough for most tasks and the quality gap has closed significantly in 2025.

Starting the LM Studio Local Server

Open LM Studio. Navigate to the "Local Server" tab on the left sidebar — it looks like a server rack icon. This panel controls everything about the OpenAI-compatible endpoint.

Before starting the server, load a model. Click "Select a model to load" at the top of the panel and choose from your downloaded models. LM Studio shows VRAM usage estimates next to each model — pick one that fits your hardware.

  1. Select your model in the Local Server tab
  2. Note the server address — default is http://localhost:1234
  3. Click the green "Start Server" button
  4. Confirm the status shows "Server Running" in green

The server is now running. You can verify it responds by hitting the models endpoint directly.

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

You should get a JSON response listing the loaded model. That's the confirmation that everything is ready for OpenClaw.

We'll get to the exact OpenClaw config block in a moment — but first, understand why the model name matters more than most guides mention.

Configuring OpenClaw to Use LM Studio

Open your OpenClaw agent configuration file. Under the model provider section, add the following block:

model:
  provider: openai-compatible
  base_url: http://localhost:1234/v1
  api_key: lm-studio
  model: mistral-7b-instruct-v0.3

The api_key value is required by the config schema but LM Studio ignores it completely — any non-empty string works. Using lm-studio makes it obvious in config diffs what this connection is for.

The model field must match the identifier LM Studio uses internally. The safest way to find it: hit the /v1/models endpoint and copy the id field from the response exactly as it appears.

curl http://localhost:1234/v1/models | python3 -m json.tool

Save your config and restart the agent. If the agent starts without errors and responds to a test message, you're connected.

⚠️
LM Studio Must Be Running Before OpenClaw Starts

OpenClaw checks the model provider connection at startup. If LM Studio isn't running when you start the agent, you'll get a connection refused error. Start LM Studio first, confirm the server is up, then launch OpenClaw. For production setups, use a process manager to enforce the startup order.

Choosing the Right Model for Your Agent

Model selection is the decision that most impacts agent quality. The right choice depends on your task type, hardware, and latency requirements.

Model Size Best For Speed (M2 Pro)
Mistral 7B Instruct4.1GBGeneral tasks, fast responses~55 tok/s
LLaMA 3 8B Instruct4.9GBInstruction following, chat~48 tok/s
Qwen2.5-Coder 7B4.4GBCode generation, debugging~52 tok/s
Mixtral 8x7B26GBComplex reasoning, analysis~18 tok/s

Sound familiar? Most builders start with Mistral 7B, get comfortable, then upgrade to Mixtral once they've validated their agent logic works. That's the right sequence — don't optimize hardware before you've confirmed your agent design is solid.

Performance Tuning for Local Agents

Raw model speed matters for agent loops. An agent that waits 8 seconds per LLM call feels broken even if the output is correct. Three settings inside LM Studio dramatically affect throughput.

GPU layers (n_gpu_layers): This controls how many transformer layers run on GPU versus CPU. Set this to the maximum your VRAM allows. LM Studio shows a suggested value automatically — use it. Moving layers to GPU is the single biggest speed improvement available.

Context length: Smaller context = faster inference. Most OpenClaw agent tasks don't need 128k context. Set context to 8192 or 16384 unless your task genuinely requires long documents. Cutting context from 32k to 8k often gives 30–40% speed improvement.

Threads: Set CPU threads to the number of performance cores on your machine, not total logical threads. Hyperthreading doesn't help LLM inference and can actually slow it down.

💡
Quantization Makes a Big Difference

LM Studio offers models in Q4, Q5, and Q8 quantization. Q4_K_M is the sweet spot — roughly 20% quality drop versus full precision, but 2x faster and half the VRAM. For most OpenClaw agent tasks, Q4_K_M quality is indistinguishable from Q8 in practice. Download the Q4 variant first.

Common Mistakes When Connecting LM Studio to OpenClaw

  • Using the wrong port: LM Studio defaults to port 1234, but if you changed it, your OpenClaw config must match. Check LM Studio's server panel for the actual address before copying it.
  • Model not loaded when server starts: Clicking "Start Server" without loading a model first means the server runs but completions fail with a model not found error. Always load the model before starting the server.
  • Wrong model identifier in config: The model name in your OpenClaw config must match LM Studio's internal identifier exactly, including version numbers and quantization suffixes. Use the /v1/models endpoint to get the exact string.
  • Firewall blocking localhost connections: On some Windows setups, firewall rules block localhost traffic on non-standard ports. If OpenClaw can't connect, check Windows Defender Firewall settings for inbound rules on port 1234.
  • Running out of VRAM mid-session: If you load a model that barely fits in VRAM, other applications can cause eviction. Close browsers and other GPU-intensive apps before running agent sessions with large models.

Frequently Asked Questions

Does LM Studio work with OpenClaw out of the box?

Yes, once LM Studio's local server is running it exposes an OpenAI-compatible endpoint. OpenClaw supports any OpenAI-compatible provider, so you point it at http://localhost:1234/v1 and it works immediately without plugins or custom code.

What is the LM Studio server URL to use in OpenClaw?

The default LM Studio server URL is http://localhost:1234/v1. Use this as the base_url in your OpenClaw provider config. If you changed the port in LM Studio settings, update the port number — the /v1 path stays the same.

Which models in LM Studio work best for OpenClaw agents?

Mistral 7B Instruct and LLaMA 3 8B Instruct are strong starting points — fast, instruction-following, and under 5GB. For coding tasks, Qwen2.5-Coder outperforms both. For complex reasoning, Mixtral 8x7B if your RAM allows.

Can I run LM Studio on a machine without a GPU?

Yes, LM Studio supports CPU-only inference via llama.cpp. Expect 3–8 tokens per second on a modern CPU versus 30–80 on a mid-range GPU. For development and testing, CPU inference is fine. For production agent workloads, GPU acceleration is worth the investment.

What model name should I put in the OpenClaw config?

Use the exact model identifier from LM Studio's /v1/models endpoint — usually something like mistral-7b-instruct-v0.3. Copy it directly from the API response to avoid mismatches that cause model not found errors.

Will my conversations be private when using LM Studio with OpenClaw?

Yes. With LM Studio, inference runs 100% on your local machine — no data leaves your network. This makes it suitable for sensitive data, air-gapped environments, and any context where data residency requirements prohibit cloud APIs.

RN
R. Nakamura
Developer Advocate

R. Nakamura has spent two years benchmarking local model setups for OpenClaw deployments across enterprise and hobbyist environments. Has tested every major local runner — LM Studio, Ollama, llama.cpp direct — and documented exactly what breaks at scale and what doesn't.

Local AI Agent Guides

Weekly guides on running OpenClaw with local models, free.