You can run artificial intelligence on your own computer and use it in other applications without subscribing to a paid API that charges per message. In this tutorial, I explain how I did this using LM Studio, the Qwen3-4B model, and Python, from my first conversation with the model to a chat interface accessible through a web browser.
The test was performed on a Windows computer with 32 GB of RAM and an NVIDIA GeForce RTX 3050 graphics card with 6 GB of video memory. First, I interacted with the model directly in LM Studio. Then, I enabled its API, sent a question using Python, and connected a local web page to the AI.
You can follow these same steps to experiment with local AI and understand how to integrate it into your own projects.
What Is Local AI?
Local AI runs an artificial intelligence model directly on your own device. In this tutorial, the computer receives a question, processes the text, and generates a response.
The model used is an LLM, which stands for Large Language Model. This type of model can perform tasks such as answering questions, explaining concepts, assisting with writing, and generating code.
Once the model and the necessary components have been downloaded, LM Studio allows you to interact with it without an internet connection. Downloading additional models and searching for new ones still requires network access.
One possible application is developing an assistant to support studying, programming, or research activities. You can also integrate the model into your own software, as we will demonstrate using Python.
Is Running Local AI Free?
In this experiment, I did not need to subscribe to an API service or pay for each question sent to the model.
However, this does not mean that running the model has no costs. Processing uses your computer’s resources, consumes electricity, and requires storage space and memory.
It is also important to review the application’s terms of use and the license of the selected model, especially for commercial projects.
For experimentation, the main advantage is being able to test AI using your own computer’s resources, without being charged according to the number of messages or tokens sent to a remote service.
What Do You Need to Follow This Tutorial?
For this experiment, I used the following configuration:
| Component | Configuration used |
|---|---|
| Operating system | Windows 64-bit |
| RAM | 32 GB |
| Graphics card | NVIDIA GeForce RTX 3050 Laptop |
| Video memory | 6 GB |
| Application | LM Studio |
| Model | Qwen3-4B in GGUF format |
| Quantization | Q4_K_M |
| Integration language | Python |
This table describes the configuration used in the experiment, not universal minimum requirements. The memory required and response speed depend on the model, quantization, conversation length, and runtime settings.
Does AI Use RAM or Video Memory?
It can use both.
The downloaded model file is stored on the computer’s SSD or hard drive. During execution, the data required for processing is loaded into RAM and, when supported by the configuration, into the graphics card’s memory, known as VRAM.
The GPU can accelerate response generation because it performs many operations in parallel. Performance also depends on the graphics card’s processing capabilities, memory bandwidth, and how much of the model can run on the GPU.
Having 32 GB of RAM is not equivalent to having 32 GB of VRAM. These are different resources, although both may be involved in running the model.
1. Install LM Studio
LM Studio is an application that allows you to download language models, interact with them, and make them available through a local API.
Visit the official LM Studio website and download the version compatible with your operating system. For this experiment, I used the 64-bit Windows version.
After installation, open the application.
The application and the model are separate components. Installing LM Studio prepares the environment, but you still need to download the model that will generate the responses.
2. Download the Qwen3-4B Model
In LM Studio’s model search section, look for:
Qwen3-4B
For this experiment, I used the model from the following repository:
lmstudio-community/Qwen3-4B-GGUF
The selected variant was Q4_K_M, with a download size of approximately 2.50 GB.
The term 4B indicates that the model contains approximately four billion parameters. Q4_K_M identifies a quantization method that reduces the storage space occupied by the model’s weights and the memory required to load them, potentially affecting response quality.
The GGUF format is used by compatible local inference tools, including the environment employed in this experiment.
The downloaded file size does not represent the total memory consumption during execution. Processing also requires memory for the conversation context and other data.
3. Have Your First Conversation in LM Studio
After completing the download, select the model and click Use in New Chat, or the equivalent option in your version.
Send a simple question, for example:
What is local artificial intelligence?
In my experiment, Qwen3-4B responded in Portuguese. This confirmed that the model was loaded and capable of generating responses directly on the computer.
Some models include a reasoning stage before producing the final response. Response time may vary depending on the question, context, and hardware.
Even when running locally, the model may generate incorrect information. For academic, technical, or professional applications, facts, calculations, and references should be verified.
4. Enable the LM Studio Local Server
Interacting with the model inside the application is the first step. To allow another application to use it, we need to enable the LM Studio API server.
In the application’s server or developer section, enable the option to start the server. The names and locations of these controls may vary between versions.
In my experiment, I used the following address:
http://127.0.0.1:1234
This address has two important components:
127.0.0.1represents the computer itself.1234is the port used by the server in this example.
Keep the server running and confirm that the model is available.
The model identifier used in the following examples is:
qwen3-4b
If your model has a different identifier, update this value in the code examples.
5. Check Whether the API Is Working
With the server running, open the following address in your browser:
http://127.0.0.1:1234/v1/models
The response should be a JSON document containing the models visible to the server.
In my experiment, the list included the identifier qwen3-4b.
This confirms that the API is responding. The next test checks whether it can also generate a response to a question.
LM Studio provides endpoints compatible with the OpenAI API format. Here, we will use /v1/chat/completions to send messages to the local model.
This compatibility does not mean that the question is sent to OpenAI. The address configured in the code points to LM Studio running on the computer itself.
6. Send a Question to the AI Using Python
With Python installed, create a file named:
test_ai.py
Paste the following code:
import jsonimport urllib.requesturl = "http://127.0.0.1:1234/v1/chat/completions"data = { "model": "qwen3-4b", "messages": [ { "role": "user", "content": "Explain what Arduino is in English." } ], "max_tokens": 1000, "stream": False}request = urllib.request.Request( url, data=json.dumps(data).encode("utf-8"), headers={"Content-Type": "application/json"}, method="POST")with urllib.request.urlopen(request, timeout=180) as response: result = json.loads(response.read().decode("utf-8"))print(result["choices"][0]["message"]["content"])
This example uses only modules from Python’s standard library. No additional package installation is required to make the API request.
How to Run the Code
On Windows, open a terminal in the folder where you saved the file and run:
py test_ai.py
LM Studio must have its server running and the model available.
In my experiment, the terminal displayed an explanation of Arduino. This confirmed communication between a Python application and the local model.
What Happens During This Integration?
The Python program converts the question into an HTTP request and sends it to LM Studio. The server processes the message using Qwen3-4B and returns a JSON response.
The final line of code extracts the response text from the JSON and displays it in the terminal.
The max_tokens parameter limits the number of tokens generated. Tokens are units of text used by the model and do not correspond exactly to words.
7. Create a Local Chat Interface in Your Browser
After testing the model in the terminal, the next step was to create a web interface.
The application uses a Python server to deliver the page to the browser and forward messages to LM Studio.
The page opens at:
http://127.0.0.1:8000
The web page server and the AI server use different ports:
| Address | Function |
|---|---|
127.0.0.1:8000 | Chat web page |
127.0.0.1:1234 | LM Studio API |
To reproduce this experiment, save the following code in a file named local_chat.py:
import jsonimport urllib.requestfrom http.server import BaseHTTPRequestHandler, ThreadingHTTPServerPAGE = """<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>Local AI Chat</title><style>body { font-family: Arial, sans-serif; max-width: 850px; margin: 30px auto; padding: 0 16px; background: #f5f7fb; color: #182230;}#chat { min-height: 250px; background: white; border: 1px solid #ccd3df; border-radius: 12px; padding: 16px;}.message { white-space: pre-wrap; overflow-wrap: anywhere; margin: 12px 0; padding: 12px; border-radius: 8px;}.user { background: #e8efff; }.assistant { background: #eef6ee; }
How to Open the Chat
Keep the LM Studio server running. In another terminal, open the folder containing the Python file and run:
py local_chat.py
Then, open the following address in your browser:
http://127.0.0.1:8000
Type a question and click Send.
The web page forwards the message to the Python server, which communicates with LM Studio and returns the response. The browser also sends the previous message history so that the model can maintain the context of the conversation.
This history is stored in the web page’s memory. When you reload the page or click New conversation, the history is cleared. The example does not save conversations in a database.
Responses are displayed as plain text. If the model generates Markdown formatting, such as asterisks for bold text, these characters may appear literally.
Common Problems and How to Solve Them
The API Does Not Open in the Browser
Check whether the LM Studio server is running and whether the configured port is 1234.
If you selected a different port, update the addresses in the examples.
The Code Reports That the Model Is Unavailable
Open:
http://127.0.0.1:1234/v1/models
Check the model identifier and update the "model" field in the code.
Windows Cannot Find the Python File
Open the terminal in the folder where the file was saved.
If you are using Notepad, select All Files when saving and make sure the filename has not accidentally become local_chat.py.txt.
The Response Takes Too Long
Response time depends on the hardware, conversation length, and amount of generated text.
A long conversation increases the amount of context sent to the model. For a new test, click New conversation and submit a short question.
Port 8000 Is Already in Use
Close the other application using that port or change the port number at the end of the code:
server = ThreadingHTTPServer(("127.0.0.1", 8001), Server)
Then open the page at:
http://127.0.0.1:8001
Can I Connect This AI to My WordPress Website?
Yes, but this is a later step beyond the local integration demonstrated in this tutorial.
The address 127.0.0.1 represents the computer running the application. Therefore, an external hosting server cannot access the AI running on my computer simply by using this address.
To connect a WordPress website to the local AI, it would be necessary to establish secure communication between the hosting server and the computer.
The website would send a question, the local model would generate the response, and the result would be returned to the web page.
For a personal chat application, access would also need to be restricted to the authorized WordPress account, and communication with the computer would need to be authenticated.
The code presented in this tutorial is a local prototype and does not include authentication for public internet deployment. It is configured to listen only on 127.0.0.1.
If the AI continues running on a personal computer, that computer must remain powered on, with the necessary services running, to answer questions submitted through the website.
What Did I Accomplish in This Experiment?
By the end of the experiment, I was able to interact with Qwen3-4B inside LM Studio, enable its API, send a question through Python, and use a chat interface in a web browser.
This demonstrates an interesting possibility for application developers: a language model can be accessed programmatically and integrated into a custom interface.
Building on this foundation, it is possible to explore study assistants, writing tools, and applications that support programming.
In my case, the next step will be to investigate how to establish a secure connection with WordPress for personal use.
Frequently Asked Questions About Local AI
Do I Need an Internet Connection to Chat With the Model?
Once the model and its runtime components have been downloaded, local chat can operate without an internet connection.
However, integrations that access external services or remote websites still require connectivity.
Do I Need a Dedicated Graphics Card?
Not necessarily.
Depending on the model and runtime environment, it is possible to use the CPU and system RAM.
A compatible GPU can accelerate response generation.
Can I Run Any Model With 32 GB of RAM?
No.
Larger models may require more memory than the computer has available.
Quantization, context length, and GPU resources also influence memory consumption.
Do I Need to Pay for Each Question?
In this example, questions are processed locally without using a paid external API.
However, hardware and electricity costs still apply, along with any relevant software usage and licensing conditions.
Can I Use Another Model With the Same Code?
Yes, provided that the model is available on the server and compatible with the API request.
Update the "model" field to match the identifier returned by the API.
Does the AI Permanently Learn From My Conversations?
No.
This example sends the conversation history as context, but it does not train the model or modify its weights.
Maintaining conversational context is different from training an AI model.
Documentation and Further Reading
For more information, consult the official LM Studio documentation: