How to Connect LM Studio Models to VS Code

LM Studio makes it easy to run large language models (LLMs) locally on your Windows 11 PC, allowing you to use AI without relying on cloud-based services. By hosting models such as Llama, Mistral, Gemma, DeepSeek, or Qwen locally, LM Studio provides an OpenAI-compatible API that can be accessed by compatible applications, including Visual Studio Code. Connecting LM Studio to VS Code enables you to use local AI models for code generation, debugging, documentation, and other development tasks directly within your editor.

Whether you’re a developer looking for offline AI assistance or want greater privacy by keeping your prompts and code on your local machine, integrating LM Studio with VS Code is a great option. The setup is relatively straightforward, but it requires configuring LM Studio’s local server and pointing your VS Code AI extension to the correct API endpoint.

In this guide, we’ll show you how to connect LM Studio models to Visual Studio Code on Windows 11.

How to Connect LM Studio Models to VS Code

Before you begin, make sure you have the latest versions of LM Studio and Visual Studio Code installed on your PC. You’ll also need to download at least one compatible language model in LM Studio and install a VS Code extension that supports OpenAI-compatible APIs, such as Continue, Cline, Roo Code, or GitHub Copilot alternatives that allow custom endpoints. Follow the steps below to complete the setup.

1. Install LM Studio

If you haven’t already installed LM Studio, download and install it first.

  1. Open your preferred web browser.
  2. Visit the official LM Studio website.
  3. Download the Windows installer.
  4. Run the installer.
  5. Follow the on-screen instructions to complete the installation.
  6. Launch LM Studio.

Once installed, you’re ready to download your first AI model.

2. Download a Language Model

LM Studio requires at least one downloaded model before it can serve AI requests.

  1. Open LM Studio.
  2. Click the Discover or Search section.
  3. Search for a model you want to use, such as:
    • Llama
    • Mistral
    • Gemma
    • DeepSeek
    • Qwen
  4. Click Download.
  5. Wait for the model to finish downloading.

Choose a model that matches your PC’s RAM and GPU capabilities for the best performance.

3. Load the Model

Downloaded models must be loaded into memory before they can process requests.

  1. Open the My Models section.
  2. Select your downloaded model.
  3. Click Load.
  4. Wait until the model finishes loading.
  5. Verify that the model is ready.

A loaded model is required before starting the local API server.

4. Start the Local Server

LM Studio includes an OpenAI-compatible API server that allows external applications to communicate with the loaded model.

  1. Open the Developer or Local Server section in LM Studio.
  2. Enable the Local Server option.
  3. Start the server.
  4. Note the API endpoint, which is typically:
http://localhost:1234/v1
  1. Keep LM Studio running while using VS Code.

The local server acts as the bridge between LM Studio and Visual Studio Code.

5. Install an AI Extension in VS Code

Visual Studio Code requires an extension that supports OpenAI-compatible APIs.

  1. Open Visual Studio Code.
  2. Click the Extensions icon.
  3. Search for an extension such as:
    • Continue
    • Cline
    • Roo Code
  4. Click Install.
  5. Restart VS Code if prompted.

These extensions can connect to locally hosted AI models through LM Studio.

6. Configure the API Endpoint

The extension must be configured to communicate with LM Studio instead of an online AI provider.

  1. Open the extension’s settings.
  2. Locate the API configuration section.
  3. Enter the local endpoint:
http://localhost:1234/v1
  1. If prompted for an API key, enter:
lm-studio

or leave the field blank if the extension allows it.

  1. Save the configuration.

Most OpenAI-compatible extensions work with LM Studio using this endpoint.

7. Select Your Local Model

Many VS Code AI extensions allow you to choose which model to use.

  1. Open the extension settings.
  2. Refresh the available models.
  3. Select the model currently loaded in LM Studio.
  4. Save your changes.

VS Code should now communicate with the local model instead of a cloud service.

8. Test the Connection

Before using the model for development tasks, verify that the integration is working correctly.

  1. Open a source code file in VS Code.
  2. Launch the AI assistant.
  3. Ask a simple question, such as:
Explain this function.

or

Optimize this code.
  1. Wait for the response.

If the model replies successfully, the connection has been established.

9. Allow LM Studio Through Windows Firewall

If VS Code cannot connect to the local server, Windows Firewall may be blocking access.

  1. Open Windows Security.
  2. Go to Firewall & network protection.
  3. Select Allow an app through firewall.
  4. Ensure LM Studio is allowed on your current network.
  5. Restart LM Studio if necessary.

This allows local API requests to reach the server.

10. Update LM Studio and VS Code

Older versions may contain compatibility issues with newer AI models or extensions.

  1. Update LM Studio to the latest version.
  2. Update Visual Studio Code.
  3. Update your AI extension.
  4. Restart both applications.
  5. Test the connection again.

Using the latest versions improves compatibility and performance.

Conclusion

Connecting LM Studio models to Visual Studio Code is an excellent way to bring powerful local AI capabilities directly into your development environment. Once the integration is complete, you can generate code, explain functions, debug errors, and write documentation without sending your data to external cloud services.

If the connection doesn’t work immediately, verify that the model is loaded, the LM Studio local server is running, and your VS Code extension is configured with the correct API endpoint. Keeping LM Studio, Visual Studio Code, and your extensions up to date will help ensure a smooth and reliable local AI development experience.

Posted by Raj Bepari

I’m a digital content creator passionate about everything tech.