Close Menu
  • AI Tools
    • Claude AI
    • ChatGPT
    • Cursor AI
    • GitHub Copilot
  • Programming
    • Python
    • JavaScript
  • About
  • Contact Us
Facebook X (Twitter) Instagram
Skill Trek
Facebook X (Twitter) Instagram Pinterest
  • AI Tools
    • Claude AI
    • ChatGPT
    • Cursor AI
    • GitHub Copilot
  • Programming
    • Python
    • JavaScript
  • About
  • Contact Us
Subscribe
Skill Trek
Home»AI Tools»How to Add a Custom Provider in OpenCode
AI Tools

How to Add a Custom Provider in OpenCode

Md Al MamunBy Md Al MamunNovember 22, 2026No Comments10 Mins Read
Share Facebook Bluesky Threads Pinterest Twitter LinkedIn Tumblr Email
Follow Us
Facebook X (Twitter) Pinterest LinkedIn
Share
Facebook Bluesky Pinterest Threads Email Copy Link

Want to use local AI models inside OpenCode without relying on paid cloud-based AI APIs?

In this tutorial, I’ll show you how to add a custom provider in OpenCode using LM Studio. By connecting LM Studio to OpenCode, you can run large language models (LLMs) locally on your computer and use them for coding, generating code, debugging, and building projects.

OpenCode provides several built-in AI providers, including OpenAI, Anthropic, Google, and GitHub Copilot. However, it doesn’t provide a dedicated option in its settings interface to add a completely custom provider. Fortunately, you can solve this by manually editing the OpenCode configuration file.

We’ll use LM Studio to download and run local AI models, start a local API server, and connect that server to OpenCode through a custom provider configuration.

Let’s get started!

What You Need Before Getting Started

Before connecting LM Studio to OpenCode, make sure you have the following:

  • OpenCode: Installed and running on your Windows computer.
  • LM Studio: Installed on your computer.
  • Local AI Model: At least one model downloaded through LM Studio.
  • Visual Studio Code: Recommended for editing the OpenCode configuration file.

Step 1: Understand OpenCode Providers

First, open OpenCode and navigate to the home menu.

Click on Settings to see the available AI providers.

You’ll find several popular providers. Click See more providers to explore additional built-in options, including:

  • OpenCode
  • OpenAI
  • GitHub Copilot
  • Anthropic
  • Google

However, if you search for “custom,” you’ll notice that there isn’t a dedicated option in the interface to add a custom provider.

Don’t worry! We can manually configure a custom provider using the OpenCode JSON configuration file.

For this tutorial, we’ll connect LM Studio to OpenCode so we can use locally running AI models.

Step 2: Download and Install LM Studio

First, open your browser and visit the official LM Studio website:

Website: https://lmstudio.ai/

On the homepage, you’ll find the LM Studio download options.

You can download LM Studio Bionic or scroll down to find the standalone version.

LM Studio provides a local chat interface and a programmable API, allowing you to download, manage, and run large language models directly on your computer.

Download the appropriate version for your operating system and complete the installation.

Once the installation is finished, launch LM Studio.

Step 3: Download a Local AI Model

Now that LM Studio is installed, it’s time to download a model.

Inside LM Studio, navigate to the model search section.

Here, you can explore different open-source and locally runnable AI models.

For example, you can search for models such as:

  • Gemma 4 E2B
  • Gemma 4 E4B
  • Qwen 3.5
  • LFM 2.5

Choose a model that is compatible with your computer’s available RAM and hardware.

Once you’ve selected a model, click the Download button.

Wait for the download to finish. Depending on the model size and your internet speed, this may take a few minutes.

After downloading the model, go to the chat section and start a new conversation.

Click the model selection menu at the top and select your downloaded model to load it.

For example, I already have LFM 2.5 and Qwen 3 4B installed.

Once the model loads successfully, you can test it directly inside LM Studio by entering a simple prompt in the chat box.

If it generates a response, your local model is working correctly.

Step 4: Start the LM Studio Local API Server

Now we need to start the local model server so OpenCode can communicate with LM Studio.

Inside LM Studio, navigate to the Developer or Model Server tab from the left sidebar.

You’ll see the server status, which should initially be stopped.

Toggle the server switch to start the LM Studio server.

Once the server starts successfully, LM Studio will display your local API address and the currently loaded model.

The API address typically looks similar to:

http://localhost:1234/v1

Your actual address and port may be different, so always use the address displayed in your LM Studio interface.

Keep this server running while using the model inside OpenCode.

Important: If you want to switch to another model later, simply click Load Model in the Model Server section and select a different downloaded model.

Step 5: Open the OpenCode Configuration File

Now comes the most important part: configuring LM Studio as a custom provider in OpenCode.

First, open Windows File Explorer.

Navigate to:

C:\Users\YOUR_USERNAME\.config\opencode

Replace YOUR_USERNAME with your actual Windows user folder name.

Inside the opencode directory, look for a file named:

opencode.json

This is the configuration file where we’ll define our custom LM Studio provider.

What if the file doesn’t exist?

You can create it manually.

Open a terminal inside the opencode directory and execute:

code opencode.json

This command will create the configuration file and open it in Visual Studio Code, assuming the code command is available on your system.

Step 6: Add LM Studio as a Custom Provider

Now open the opencode.json file in Visual Studio Code.

Copy the following configuration and paste it into the file.

{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "lmstudio": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "LM Studio",
      "options": {
        "baseURL": "http://localhost:1234/v1",
        "apiKey": "lm-studio"
      },
      "models": {
        "YOUR_MODEL_ID": {
          "name": "LFM 2.5 1B"
        }
      }
    }
  }
}

Let’s understand the important parts of this configuration.

1. Provider Name

"lmstudio": {
  "npm": "@ai-sdk/openai-compatible",
  "name": "LM Studio"
}

Here, we’re defining a custom provider with the ID lmstudio and display name LM Studio.

The OpenAI-compatible provider package allows OpenCode to communicate with LM Studio through its compatible API.

2. API Configuration

"options": {
  "baseURL": "http://localhost:1234/v1",
  "apiKey": "lm-studio"
}

The baseURL points to the local LM Studio API server.

The API key is a placeholder used for this local connection. If you’ve configured authentication in LM Studio, use the appropriate credentials instead.

3. Configure Your Model

"models": {
  "YOUR_MODEL_ID": {
    "name": "LFM 2.5 1B"
  }
}

This is where you need to make a small customization.

Replace YOUR_MODEL_ID with the exact model ID displayed in LM Studio.

For example, if your model ID is lmstudio-community/LFM2.5-1.2B-Instruct-GGUF, your configuration could look like this:

"models": {
  "lmstudio-community/LFM2.5-1.2B-Instruct-GGUF": {
    "name": "LFM 2.5 Model"
  }
}

Make sure you use the actual model ID reported by your LM Studio server rather than copying the example blindly.

Step 7: Add Multiple Local AI Models

One of the best things about this configuration is that you can add multiple local models under the same provider.

For example, if you have both LFM 2.5 and Qwen 3 4B installed, you can configure them like this:

{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "lmstudio": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "LM Studio",
      "options": {
        "baseURL": "http://localhost:1234/v1",
        "apiKey": "lm-studio"
      },
      "models": {
        "YOUR_LFM_MODEL_ID": {
          "name": "LFM 2.5"
        },
        "YOUR_QWEN_MODEL_ID": {
          "name": "Qwen 3 4B Model"
        }
      }
    }
  }
}

Replace both model IDs with the exact IDs available in your LM Studio installation.

You can add more models by following the same structure.

Important: Adding multiple models to the configuration doesn’t mean they will all run simultaneously. You still need to load a model in LM Studio before OpenCode can use it.

Once you’ve finished editing the configuration, press Ctrl + S to save the file.

Step 8: Connect LM Studio to OpenCode

Now it’s time to test our custom provider.

Go back to OpenCode.

Open the model selection menu and search for:

LM Studio

You should now see your newly configured provider.

Click on it to view the models you’ve added, such as:

  • LFM 2.5
  • Qwen 3 4B Model

Select the model you want to use.

Now enter a simple prompt, such as:

Hi

Press Enter to send the prompt.

If everything is configured correctly, OpenCode will send the request to your local LM Studio server and display the model’s response.

You can also switch back to LM Studio and check the server activity. You’ll see the request being processed, and the generation progress will update as the model produces its response.

Congratulations! You’ve successfully connected LM Studio to OpenCode.

Step 9: Start Building Projects with Local AI Models

Now you can use your local AI models inside OpenCode to perform various coding tasks.

For example, you can ask your local model to:

  • Generate Python, JavaScript, or other programming code.
  • Explain existing code.
  • Find and fix programming errors.
  • Create project structures.
  • Write functions and classes.
  • Help you understand unfamiliar codebases.
  • Build small applications and automation scripts.

The biggest advantage is that your prompts and model inference can stay on your local machine rather than being sent to a cloud AI provider.

However, remember that local model performance depends on your computer’s hardware and the capabilities of the model you’re running.

Troubleshooting Common Problems

If LM Studio doesn’t appear in OpenCode or your model isn’t responding, check the following:

1. LM Studio Server Is Not Running

Make sure the local API server is enabled in LM Studio’s Developer or Model Server section.

2. Incorrect API Address

Check the baseURL in your opencode.json file. It should match the API address displayed in LM Studio and normally end with /v1.

3. Incorrect Model ID

Make sure the model ID in your JSON configuration exactly matches the ID provided by LM Studio.

4. Invalid JSON Configuration

Check your JSON syntax carefully. Make sure you have the correct commas, quotation marks, brackets, and curly braces.

5. Model Is Not Loaded

Make sure the model you want to use is loaded in LM Studio before sending requests from OpenCode.

6. Insufficient System Resources

Some AI models require significant RAM or GPU memory. If a model fails to load or responds very slowly, try a smaller model that better matches your hardware.

Frequently Asked Questions (FAQ)

Can I use LM Studio with OpenCode for free?

Yes. You can use locally downloaded models through LM Studio with OpenCode without paying for a cloud model API. However, you still need compatible hardware to run the models.

Do I need an OpenAI API key?

No. When connecting to LM Studio’s local OpenAI-compatible API server, you generally don’t need a real OpenAI API key. The example uses lm-studio as a placeholder.

Can I add multiple models to OpenCode?

Yes. You can define multiple models inside the models section of your LM Studio provider configuration.

Does LM Studio need to stay open?

Yes. LM Studio must be running, and its local API server must be active while OpenCode communicates with it.

Can I use local AI models for coding?

Yes. You can use compatible local coding and general-purpose language models for code generation, debugging, explanations, and other programming tasks.

Conclusion

In this tutorial, we learned how to add a custom provider in OpenCode using LM Studio.

We downloaded and installed LM Studio, downloaded local AI models, started the local API server, and manually configured OpenCode using the opencode.json file.

Now you can run local large language models inside OpenCode and use them for coding and development without depending entirely on paid cloud-based AI services.

If you found this tutorial helpful, please leave a comment below and subscribe to my YouTube channel for more tutorials about AI tools, local LLMs, programming, and developer productivity.

Thanks for reading!

Share. Facebook Pinterest Telegram Bluesky Threads Email Copy Link
Previous ArticleHow to Install OpenCode in WSL on Windows 11 (Step-by-Step Guide)
Next Article OpenCode Skills Tutorial: From Setup to Efficient AI Agents
Md Al Mamun
  • Website
  • Facebook
  • X (Twitter)
  • Instagram
  • LinkedIn

a full-stack developer and educator with a community of over 144,000 learners across YouTube, Udemy, and Facebook. With years of hands-on experience in building modern web applications, I specialize in making complex topics easy to understand through clear, structured explanations and real-world examples.

Related Posts

How to Use Hermes AI Agent with Ollama (Step-by-Step Guide)

November 22, 2026

OpenCode Skills Tutorial: From Setup to Efficient AI Agents

November 22, 2026

How to Get an ElevenLabs API Key (Step-by-Step Guide)

November 20, 2026

How to Install and Use YouTube Agent Skills in Claude (Step-by-Step Guide)

November 18, 2026

How to Connect OpenCode to Roblox Studio Using MCP

September 14, 2026

How to Use Claude Code for Free using Ollama in VS Code

September 3, 2026
Add A Comment
Leave A Reply Cancel Reply

Recent Posts

  • How to Install ECC Repository in Claude Code (Step-by-Step Guide)
  • How to Use Hermes AI Agent with Ollama (Step-by-Step Guide)
  • How to Call an API in Python (Step-by-Step Guide for Beginners)
  • OpenCode Skills Tutorial: From Setup to Efficient AI Agents
  • How to Add a Custom Provider in OpenCode

Recent Comments

No comments to show.

Archives

  • November 2026
  • September 2026
  • August 2026

Categories

  • AI Tools
  • Claude AI
  • Google Antigravity
  • JavaScript
  • Programming
  • Python
  • Uncategorized
Quick Access
  • Home
  • About
  • Contact Us
  • Privacy Policy
  • Disclaimer
Facebook X (Twitter) Instagram Pinterest
  • Home
  • About
  • Contact Us
  • Privacy Policy
  • Disclaimer
© 2026 SkillTrek. All Rights Preserved by Md Al Mamun.

Type above and press Enter to search. Press Esc to cancel.