Setup guide - Documented by OpenCode
Use LM Studio in OpenCode
The OpenCode providers docs include an LM Studio section. It registers LM Studio as an @ai-sdk/openai-compatible provider in opencode.json, pointed at http://127.0.0.1:1234/v1.
Last verified 3 steps3 official sources
Steps
- Step 1.
Add the LM Studio provider to the opencode.json file in your project directory (verbatim from the OpenCode LM Studio section).
JSON{ "$schema": "https://opencode.ai/config.json", "provider": { "lmstudio": { "npm": "@ai-sdk/openai-compatible", "name": "LM Studio (local)", "options": { "baseURL": "http://127.0.0.1:1234/v1" }, "models": { "google/gemma-3n-e4b": { "name": "Gemma 3n-e4b (local)" } } } } } - Step 2.
Make sure the LM Studio server is running (LM Studio docs).
Terminallms server start --port 1234 - Step 3.
Optional: list the model identifiers LM Studio is serving, so you can use them as keys under models (LM Studio docs).
Terminalcurl http://localhost:1234/v1/models
Caveats
- Steps 2 and 3 come from LM Studio's docs (server start and the /v1/models endpoint), combined with OpenCode's documented config.
- Each model key must match an identifier LM Studio serves. google/gemma-3n-e4b is OpenCode's example.
- Indentation in the JSON was normalized. The keys and values are verbatim.
More setup guides
Same tool, other providers
Related reading
- LM Studio Bionic: A Local-First AI Agent for Open ModelsLM Studio launches Bionic, a standalone agent harness for open models with local inference, voice input, and zero data retention cloud options.
- Ollama vs LM Studio vs vLLM vs llama.cpp: Picking a Local Runtime for Coding AgentsOllama vs LM Studio vs vLLM vs llama.cpp for coding agents: what each local runtime is for, where they overlap, and which to pick for your setup.
- OpenCode Hacked: What the Console Breach Means for Your API KeysOpenCode disclosed a breach of its Console that may have exposed provider keys. Who is affected, what to rotate today, and why hosted key gateways are the real risk.
- OpenCode 2: How to Upgrade From v1 Without Breaking Your SetupOpenCode 2 upgrade from v1: what the migration guide says breaks (plugins, server API, TUI config), what carries over, and a safe checklist before you switch.
- Run Your Coding Agent as an API: OpenCode Server on RailwayOpenCode server on Railway: run opencode serve in a container as a password-protected HTTP API with a persistent volume, reachable from any machine or webhook.
- Give Every Agent PR a Live Preview: Railway Environments for AI Pull RequestsRailway preview environments for agent pull requests: an isolated copy of your whole stack for every PR, so you verify agent changes by running them.
FAQ
How do I use LM Studio in OpenCode?
The OpenCode providers docs include an LM Studio section. It registers LM Studio as an @ai-sdk/openai-compatible provider in opencode.json, pointed at http://127.0.0.1:1234/v1.
Which LM Studio model ids work in OpenCode?
The official docs read for this guide list google/gemma-3n-e4b. Requests go to http://127.0.0.1:1234/v1.
Is this an official LM Studio and OpenCode setup?
OpenCode documents this setup in its own docs. It was last checked against 3 official pages on October 17, 2026.
Sources
Last verified against 3 official pages.
Newsletter
New models, set up the day they ship
One email per week. New model releases, the coding tools that support them and how to wire them up.