Skip to content

cronos3k/LM-Studio-API-Proxy

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LM Studio API Proxy

Expose your local LM Studio as a public OpenAI-compatible API endpoint using Cloudflare Tunnel. No signup required!

Share your local LLM with coworkers, use it in VS Code, or connect from anywhere.

Features

  • No signup required - Uses free Cloudflare quick tunnels
  • OpenAI-compatible API - Works with any OpenAI SDK client
  • Streaming support - Real-time token streaming
  • Built-in tester - Automatically test all endpoints
  • Logging - See all requests in real-time

Quick Start

1. Install

git clone https://github.com/cronos3k/LM-Studio-API-Proxy.git
cd LM-Studio-API-Proxy
pip install -r requirements.txt

2. Download Cloudflared (one-time)

Windows:

curl -L -o cloudflared.exe https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-windows-amd64.exe

Mac:

brew install cloudflared

Linux:

curl -L -o cloudflared https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64
chmod +x cloudflared

3. Start LM Studio

  1. Open LM Studio
  2. Load a model
  3. Start local server (default: localhost:1234)

4. Run the Proxy

python lmstudio_proxy.py

You'll see:

============================================================
  LM Studio API Proxy (Cloudflare Tunnel)
============================================================
  LM Studio: http://localhost:1234
  Status: [OK] Model: mistralai/codestral-22b-v0.1
============================================================

  Local API: http://localhost:8000/v1

  Starting Cloudflare tunnel...

============================================================
  PUBLIC URL: https://random-words.trycloudflare.com/v1
============================================================

5. Test It

python test_endpoint.py https://your-url.trycloudflare.com/v1

Usage Examples

Python (OpenAI SDK)

from openai import OpenAI

client = OpenAI(
    base_url="https://your-url.trycloudflare.com/v1",
    api_key="not-needed"
)

response = client.chat.completions.create(
    model="mistralai/codestral-22b-v0.1",
    messages=[{"role": "user", "content": "Hello!"}]
)
print(response.choices[0].message.content)

curl

curl https://your-url.trycloudflare.com/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d "{\"model\": \"mistralai/codestral-22b-v0.1\", \"messages\": [{\"role\": \"user\", \"content\": \"Hello!\"}]}"

VS Code / Continue Extension

Edit ~/.continue/config.json:

{
  "models": [{
    "title": "LM Studio Remote",
    "provider": "openai",
    "model": "mistralai/codestral-22b-v0.1",
    "apiBase": "https://your-url.trycloudflare.com/v1",
    "apiKey": "not-needed"
  }]
}

Command Line Options

python lmstudio_proxy.py [OPTIONS]
Option Description Default
--host LM Studio host localhost
--port LM Studio port 1234
--proxy-port Local proxy port 8000

Examples

# Default (localhost:1234)
python lmstudio_proxy.py

# Custom LM Studio address
python lmstudio_proxy.py --host 192.168.1.100

# Custom ports
python lmstudio_proxy.py --port 8080 --proxy-port 9000

API Endpoints

Endpoint Method Description
/ GET Health check
/v1/models GET List available models
/v1/chat/completions POST Chat completions (streaming supported)
/v1/completions POST Text completions (streaming supported)
/v1/embeddings POST Generate embeddings

Testing

Run the built-in endpoint tester:

# Test remote URL
python test_endpoint.py https://your-url.trycloudflare.com/v1

# Test local
python test_endpoint.py http://localhost:8000/v1

Output:

============================================================
  LM Studio API Proxy - Endpoint Tester
============================================================
  Target: https://your-url.trycloudflare.com/v1

[1/6] Testing health endpoint...
  [OK] Health check passed

[2/6] Testing models endpoint...
  [OK] Models endpoint works - Found 19 models

[3/6] Testing chat completions...
  [OK] Chat completions works (3.6s, 25 tokens)

[4/6] Testing streaming...
  [OK] Streaming works (4.1s, 31 chunks)

[5/6] Testing OpenAI SDK...
  [OK] OpenAI SDK works (3.4s)

[6/6] Testing completions endpoint...
  [OK] Completions endpoint works

============================================================
  All tests passed! (6/6)
============================================================

Files

File Description
lmstudio_proxy.py Main proxy server (Cloudflare tunnel)
test_endpoint.py Endpoint tester
requirements.txt Python dependencies
cloudflared.exe Cloudflare tunnel binary (download separately)

How It Works

[Your Coworker / VS Code / Any Client]
                |
                | (internet)
                v
[Cloudflare Tunnel] -----> [This Proxy] -----> [LM Studio]
  (trycloudflare.com)        port 8000          port 1234
  1. LM Studio runs locally with your model
  2. This proxy creates an OpenAI-compatible API
  3. Cloudflare tunnel exposes it publicly (no port forwarding needed)
  4. Anyone with the URL can use your model

Troubleshooting

"Cannot connect to LM Studio"

  • Make sure LM Studio is running
  • Check that local server is started
  • Verify port (default: 1234)

"cloudflared not found"

  • Download cloudflared binary (see Quick Start)
  • Place it in the same folder as the script

Tunnel URL changed

  • Cloudflare generates a new random URL each time
  • Share the new URL with your users

Security

  • URLs are random and hard to guess
  • Anyone with the URL can use your model
  • Only share with trusted people
  • Stop the script when not in use

License

MIT

Links

About

Expose LM Studio as a public OpenAI-compatible API endpoint. Share your local LLM with VS Code, Continue, Cursor, CLI tools & Python scripts. No port forwarding needed.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages