Nolan0722/TRAE-Ollama-Bridge
About
Encapsulate the local Ollama into an OpenAI-compatible API to bypass the fixed model limitations in IDEs like TRAE.
Systems & InfrastructureMeasured star growth
- in 24h
- 0
- in 7 days
- 0
- in 15 days
- 0
- in 1 month
- Collecting history
Net star changes over overlapping periods, not daily totals. Missing measurements are left blank. Stars measure attention, not software quality.
docs/README.en.md
OriginalTRAE-Ollama-Bridge
Updated: 2025-11-05 • Version: latest
Use local Ollama models in IDEs that hard-code OpenAI endpoints. This bridge wraps Ollama with an OpenAI-compatible API and offers a Web UI to manage model mappings, test chats, and optionally intercept
https://api.openai.comtransparently.
Overview
Wrap local Ollama into an OpenAI-compatible interface to bypass fixed model/vendor and Base URL restrictions in TRAE and similar IDEs. The Web UI manages model mappings and provides a chat tester. An optional system-level interception policy can transparently take over clients that always call https://api.openai.com.
Highlights
- OpenAI-compatible
/v1endpoints: plug-and-play with TRAE and similar IDEs. - Dual-mode chat test: switch between "Explicit Bridge" and "Transparent Interception" in one click.
- Optional API Key validation: respects
EXPECTED_API_KEYandACCEPT_ANY_API_KEYpolicies. - One-click system policy: install/reuse local CA & domain certs, write hosts, and configure 443→local port forwarding.
- Mapping management: map local Ollama models to OpenAI-style IDs for easy selection in IDEs.
- Streaming/non-streaming responses: simulate OpenAI Chat Completions behavior.
- Local-first privacy: traffic stays on your machine.
Notes
- Make sure Ollama is installed and your required models run correctly. Consider increasing the context length for your models.
- Copy
.env.exampleto.envand adjust values to your environment. - Start this project before configuring the Trae IDE custom model.
Environment Variables
See .env.example:
PORT(default3000)HTTPS_ENABLED=true|false(defaultfalse)SSL_CERT_FILE,SSL_KEY_FILE(required when HTTPS is enabled)OLLAMA_BASE_URL(defaulthttp://127.0.0.1:11434)EXPECTED_API_KEY(optional fixed key)ACCEPT_ANY_API_KEY=true|false(defaulttrue)STRIP_THINK_TAGS=true|false(strip<think>...</think>blocks)ELEVATOR_PORT(default55055)
Quick Start (Windows)
- Install Node.js (v18+ recommended) and npm.
- Double-click
Start-Bridge.batto launch (first run installs dependencies automatically). - Your browser opens
http://localhost:PORT/(defaultPORT=3000) to show the Web UI. - Privileged bridge service from Web UI:
- Click "Install & Start Service".
- Click "Apply Intercept Policy".
- To undo, click "Revoke Policy" or "Uninstall Service".
- Web UI Ollama models list:
- Click "Refresh" to list local Ollama models.
- Click "Copy" to copy the model name.
- Web UI model mappings:
- Click "Refresh" to show current mappings.
- Click "Add Mapping" to add a new mapping row.
- Enter local Ollama model name in "Local Model Name" (e.g.,
llama2-13b). - Enter a global alias in "Mapping ID" (e.g.,
OpenAI-llama2-13b) to use in IDEs like TRAE.
- Enter local Ollama model name in "Local Model Name" (e.g.,
- Click "Save" to persist mappings.
- Click "Delete" to remove a mapping row.
- Web UI chat tester:
- Choose "Mapping ID" and "Streaming" ("Streaming" or "Non-Streaming").
- Choose "Test Mode": "Explicit Bridge (/v1, local)" or "Transparent Interception (https://api.openai.com)".
- Click "System Status" to confirm it shows "HTTPS: Enabled · hosts: Written" when testing transparent interception.
- Optional: enter "API Key". If
EXPECTED_API_KEYis set andACCEPT_ANY_API_KEY=false, you must enter that exact value. - Enter your prompt and click "Send". Seeing a response in the chat box means the test succeeded.
- Click "Clear" to clear the chat.
Configure Trae IDE
- Complete the Quick Start steps and verify chat testing works.
- Open and log in to Trae IDE.
- In the AI dialog, click
Settings (gear icon) / Models / Add Model. - Vendor: select
OpenAI. - Model: choose
Custom Model. - Model ID: fill the alias defined in Web UI
映射ID(e.g.,OpenAI-llama2-13b). - API Key: any value works by default. If you set
EXPECTED_API_KEYin.env, you must enter that exact value. - Click
Add Model. - In the chat, select your custom model.
Modes
- Transparent Interception: for clients that hard-code
https://api.openai.com. A system-level 443→PORT mapping combined with local CA and domain certificate handles TLS verification to take over traffic. - Explicit Bridge: if the client supports a custom Base URL, use
http://localhost:PORT/v1or, with HTTPS enabled,https://localhost:PORT/v1.
FAQ
Chat fails in Transparent Interception mode?
- In the Web UI, click "System Status" and confirm it shows "HTTPS: Enabled · hosts: Written".
- In PowerShell, run
netsh interface portproxy show alland check for0.0.0.0:443 → 127.0.0.1:PORTor::0:443 → ::1:PORT. If empty, click "Apply Intercept Policy" in the Web UI. - Certificates & trust: ensure your local CA is installed under "Trusted Root Certification Authorities" and a domain cert for
api.openai.comis generated and trusted (certmgr.msc). - Hosts resolution: verify
C:\Windows\System32\drivers\etc\hostshasapi.openai.compointing locally (IPv4/IPv6) without conflicting entries. - Browser CORS: if the browser shows CORS/cert warnings, test with "Explicit Bridge" in Web UI or directly inside the IDE.
Service port in use (
EADDRINUSE)?- Change
PORTin.envto a free port or stop the process that occupies it.
- Change
How does API Key validation work?
- With
ACCEPT_ANY_API_KEY=true(default) any key is accepted. - With
ACCEPT_ANY_API_KEY=falseandEXPECTED_API_KEYset, requests must include the exact key. - Filling "API Key" in the Web UI automatically sends
Authorization: Bearer <key>.
- With
Responses include
<think>...</think>blocks?- Set
STRIP_THINK_TAGS=trueto remove<think>sections for cleaner IDE output.
- Set
Management APIs
GET/POST/DELETE /bridge/models: manage the mapping tableGET /bridge/ollama/models: list local modelsPOST /bridge/setup/https-hosts: generate/reuse local CA and domain certs, write hosts, and configure 443→PORTPOST /bridge/setup/install-elevated-service: install/start a zero-interaction helper servicePOST /bridge/setup/uninstall-elevated-service: uninstall the helper serviceGET /bridge/setup/elevated-service-status: query helper service statusGET /bridge/setup/status: check HTTPS and hosts statusPOST /bridge/setup/revoke: revoke interception (stop forwarding/proxy and clean hosts)
License
MIT (see root LICENSE).
Acknowledgements
Article by wkgcass inspired this project.
Stay Updated
Star and Watch the repo to get the latest updates.
If this project helps you, a star is appreciated!
Go to GitHub: TRAE-Ollama-Bridge
Explore related projects
Loading…