How to Connect a Local AI Desktop Client to LLM APIs Through a Local Proxy
This guide explains how to connect a local AI desktop client to a cloud large language model API through a proxy listening on 127.0.0.1. It covers storing your API key outside client configuration files, verifying downloaded installers, configuring the proxy, testing the connection with curl and the desktop client, troubleshooting common HTTP errors, and reviewing a security checklist before use.
1. Understanding the Connection Flow
The target setup works like this:
Desktop client → Local proxy (listening on a port on 127.0.0.1) → Cloud LLM API → Proxy returns the result → Desktop client
This design has two advantages. First, the API key is stored only in the proxy or in an environment variable, so it never has to be written into the client’s configuration file. Second, when you switch models or providers, you usually only need to change the proxy’s upstream address and model ID. The client settings stay the same.
This guide assumes your LLM service provides an API compatible with the OpenAI interface format, with request paths such as /v1/chat/completions. If your service uses a different format, check the correct endpoint path in the service’s documentation before following the steps below.
The port 11435 in this guide is only an example. Use the port shown in your proxy tool’s settings screen.
2. Get and Store Your API Key
- Log in to your LLM service platform and open the API management console.
- Create a new API key on the key management page. If the platform supports permission scopes, select only the models or API permissions you actually need.
- Copy the key immediately after creating it. Most platforms show the full key only once, and you cannot view it again after closing the page.
- Store the key in a password manager or as an environment variable. Do not put it in a code repository, chat log, screenshot, or support ticket.
On Windows, you can save the key as a user-level environment variable. Run this in PowerShell:
[Environment]::SetEnvironmentVariable("LLM_API_KEY", "your-api-key", "User")
Open a new terminal after setting the variable, because the new value only applies to newly started sessions. To use the key only in the current session, run $env:LLM_API_KEY = "your-api-key" instead.
Rotate the key every 90 days. If you suspect the key has leaked, delete it in the console immediately, create a new key, and update the proxy configuration.
3. Download and Verify the Installers
1. Install the AI desktop client
Download the installer only from the client’s official website or an official mirror that the vendor designates. The download page usually lists a SHA256 checksum for the installer. After the download finishes, calculate the hash in PowerShell:
Get-FileHash "C:\Downloads\installer-file-name.exe" -Algorithm SHA256
Compare the output with the value published on the official page, character by character. If the two values do not match, do not run the installer. Download it again. If the vendor does not publish a checksum, assess the trustworthiness of the source carefully.
Once the checksum matches, double-click the installer and follow the setup wizard. After installation, launch the client once to confirm it opens correctly. At this point the client cannot connect to a cloud model yet. This is expected.
2. Install the local proxy tool
Install the proxy tool the same way. Verify its checksum first, then run the installer.
The first time you start the proxy tool, Windows Firewall may show a prompt. Allow the program to communicate on Private networks only, and block Public networks. This way, the proxy port stays closed to other devices on the same network, even if the firewall allows the program.
4. Configure the Proxy Tool
Open the proxy tool’s Settings or Configuration page, and check each field below.
| Field | Value | Notes |
|---|---|---|
| Upstream Base URL | The API address from the platform documentation | Must start with https://. Use the exact path given in the platform documentation. |
| API Key | The key you saved in Step 2 | After pasting, check for leading or trailing spaces. |
| Model ID | The full model ID from the platform’s model list | Capitalization and version suffixes must match the platform exactly. |
| Listen address | 127.0.0.1 |
Do not enter 0.0.0.0. That would make the proxy reachable by other devices on the local network. |
| Listen port | For example, 11435 |
Before starting, confirm the port is free with the command below. |
| Request timeout | 30 to 60 seconds | Increase it for long text generation. |
| Retry count | 1 to 2 | Do not retry 401, 403, or 404 errors. Retrying these will not succeed. |
| Request logging | Off, or status codes only | Full logs may contain prompts and sensitive data. |
Check whether the port is in use:
netstat -ano | findstr :11435
No output means the port is free. If there is output, note the process ID in the last column, or choose a different unused port.
After you finish the configuration, click “Start Proxy.” Wait until the status changes to “Running,” then move on to verification.
If the proxy tool does not support injecting authentication headers, try a different approach. If the client lets you set a custom API address, set it to http://127.0.0.1:11435/v1, then provide the API key through an environment variable or setting that the client supports. If the client supports neither a custom address nor environment variables, this method will not work with that client.
5. Verify the Connection
1. Confirm the proxy forwards requests with curl
Windows 10 and later include curl.exe. In PowerShell, curl points to a different command, so always type the full name curl.exe.
First, query the model list. This requires the proxy to support this path:
curl.exe http://127.0.0.1:11435/v1/models
Normally, the response is JSON that includes the model ID you set in the proxy. If the model is not in the list, correct the model ID before moving on to the next step.
Then send a test message. Create a file named request.json in any folder with the following content:
{"model":"your-model-id","messages":[{"role":"user","content":"Hello, please confirm the connection status."}]}
Then run:
curl.exe -X POST http://127.0.0.1:11435/v1/chat/completions -H "Content-Type: application/json" -d "@request.json"
The expected result is JSON in which the choices[0].message.content field contains the model’s reply. Response time depends on the model’s size and network conditions. It usually ranges from a few seconds to more than ten seconds.
2. Test in the desktop client
Open the AI desktop client, set the API address in its settings to http://127.0.0.1:11435/v1, and choose the model ID that matches the proxy. Enter “Hello, please confirm the connection status.” and check the reply.
If the curl test passes but the client still gets no reply, the problem is usually the client’s address or model settings. Check each item against the table in Step 4.
6. Troubleshooting
| Symptom | Likely cause | How to check | Fix | |
|---|---|---|---|---|
| Connection refused or no response | The proxy is not running, or the port is wrong | Check the proxy status. Run `netstat -ano \ | findstr :11435`. | Start the proxy and verify the port. |
| 401 returned | Wrong key, extra spaces, or a revoked key | Check the key in the proxy for leading or trailing spaces. | Copy the key again. If it still fails, generate a new key in the console. | |
| 403 returned | Insufficient account permissions, insufficient balance, or a regional restriction | Log in to the console and check the account status and model permissions. | Add funds, or request access to the model. | |
| 404 or model not found | A typo, wrong capitalization, or incorrect version number in the model ID | Call /v1/models to see the available IDs. |
Change the model ID to the full form shown in the list. | |
| 429 returned | Request rate exceeds the platform limit | Read the hint in the error message. | Reduce concurrency, or add a delay between requests. | |
| Occasional timeouts | Unstable network or slow model response | Run the same curl command several times and compare response times. | Increase the timeout, or change the network environment. |
Troubleshoot in order. First confirm the proxy is running, then confirm curl works, and finally check the client settings.
