Run Powerful AI Models Locally for Free with LM Studio and N8N
Are you tired of paying monthly fees just to use AI LLM models like OpenAI's chat model in your automations? What if you could run powerful AI models like DeepSeek or Llama right on your own computer—no API keys, no subscriptions, and completely free? In this article, I'll walk you through how to set it all up. We'll install a local LLM, connect it to N8N, and replace the OpenAI chat node, saving you money and giving you full control over your AI.
Introducing LM Studio: Your Local AI Launchpad
To run LLMs locally, we'll use a powerful desktop app called LM Studio. Think of LM Studio as a launchpad; it lets you download, run, and chat with large language models on your own machine, entirely without the cloud. Whether you're on Windows, macOS, or Linux, just head over to the LM Studio website and download the version for your operating system.
Downloading Your First Local Model
Once installed, open LM Studio, and you'll see a clean, chat-style interface. This is where you can interact directly with any local model you download. But before we can chat, we need to load a model, and that's where the "Discover" tab comes in. In the discover section, you'll find a library of open-source LLMs like DeepSeek, Llama, Mistral, and more. Each model has its own strengths, but for this article, we're going to use DeepSeek, which is optimized for code and reasoning tasks—perfect for workflow automation. Click on the DeepSeek model for good performance on most machines and start the download.
Once the model finishes downloading, it will appear in the "My Models" tab. This is your personal library; any model you've downloaded will live here, ready to launch at any time.
Chatting with Your Local AI
Now, let's go back to the chat tab, select DeepSeek, and try it out. With DeepSeek selected, go ahead and type your first prompt, just like you would with ChatGPT. The response time depends on your system; if you have a decent GPU, it can be surprisingly fast. And just like that, you're chatting with an AI model that's running entirely on your computer. More importantly, it's completely free.
Activating the Local API Server
Now, here's where the magic happens. LM Studio doesn't just let you chat with a local model; it also starts a local API server in the background. This means you can connect this model to other tools like N8N or any other cloud provider. But before we can connect it, let's make sure the server is actually running. Head over to the developer tab in LM Studio and check the server status. You should see a message like:
HTTP server listening on port 1234
Now, let's take it a step further. Copy this URL (http://localhost:1234
) and paste it into your browser. Here, you'll see all the models currently loaded and available to serve requests. If your model, like DeepSeek, shows up here, it means the backend is live and ready to connect with N8N. So far, so good.
Integrating the Local LLM with N8N
Now, let's jump into N8N and wire this up. With our local server running and the DeepSeek model active, it's time to replace the paid OpenAI chat node inside N8N. Wherever you're currently using the OpenAI chat node, open it up. Normally, this node sends your prompts to OpenAI's cloud using an API key, and that's what costs you tokens or monthly fees. But we're going to re-route this, so instead of OpenAI, it will send the request to your own local server running right on your computer.
First, we need to create a new API credential. But don't worry; since we're using a local server, we don't actually need a real API key. Just enter anything, even a random string like ABC123
—it won't be used. Give this credential a clear name, like DeepSeek Local Model
, so you can easily find it later.
Next, scroll down to the Base URL field. This is where we tell N8N where to send the request. Instead of OpenAI's official API URL, paste in the address from LM Studio, which is http://localhost:1234
. This tells N8N, 'Hey, send this prompt to the local server instead and let DeepSeek handle the response.'
All right, now that everything is configured—the credentials are set, the Base URL points to your local server, and the model name matches—it's time to test the connection. Open the chat message field and write a simple prompt like, 'Hey,' then click send. And here we go... we get an error that says something like:
Request to localhost was refused.
Don't panic! This is expected, especially if you're running N8N inside Docker.
Solving the Docker Networking Challenge
So, why does localhost
work in your browser but not in Docker? Here's the key: when you open a web browser on your machine and go to localhost:1234
, you're telling your host operating system to look for something running on your own computer. LM Studio is running there, so it works.
But when Docker sees localhost
, it's doing something completely different. When you're running N8N in a Docker container, the term localhost
refers to inside the container itself, not your actual computer. So, when the chat model in an N8N workflow tries to call localhost:1234
, it's essentially saying, 'Hey Docker container, do you have a server running on port 1234?' Of course, there isn't one. The LM Studio server is running on your host machine, outside of Docker. That's why you're seeing this connection error: it's Docker trying to talk to itself and failing.
That's where host.docker.internal
comes in. It's a special hostname that tells Docker to reach outside the container and connect to the host machine. So, when you change your Base URL from http://localhost:1234
to http://host.docker.internal:1234
, it correctly routes the request to LM Studio running on your actual computer. Nice!
The connection test was successful! That means N8N is now able to detect all the models currently available in LM Studio, including the ones you downloaded to your machine. In the drop-down list, you should now see DeepSeek along with any other models you've added. Go ahead and select the DeepSeek model from the list. Also, change this node's name to DeepSeek Chat Model
.
Final Test and Success
Before we run the final test, let's clean up the workflow canvas a bit. If you have extra or unused nodes from testing earlier, feel free to delete them to keep things tidy. A clean workspace makes it easier to debug and extend your automation later.
Now for the moment of truth. Open the chat box, send a simple prompt, and give it a moment to respond... and boom, it works! You've just sent a message to a powerful LLM running locally inside a node-based automation platform.
What We Accomplished
So, what did we just accomplish? Here's a quick recap:
- We installed LM Studio and set up a local API server.
- We downloaded and ran the DeepSeek LLM on our own machine.
- We connected that local model directly to N8N, replacing the OpenAI chat node.
- We successfully sent a test prompt and got a live response—without using the cloud and without paying a cent.
This setup gives you full control over your AI workflows: they are local, private, and cost-free. And this is just the beginning.
Join the 10xdev Community
Subscribe and get 8+ free PDFs that contain detailed roadmaps with recommended learning periods for each programming language or field, along with links to free resources such as books, YouTube tutorials, and courses with certificates.