From 121f6edbb06100cf3f9aa8e6b5148ff6a01fc771 Mon Sep 17 00:00:00 2001 From: octo-patch Date: Fri, 24 Apr 2026 10:11:30 +0800 Subject: [PATCH] fix: allow CUSTOM_MODEL to work without OPENAI_KEY for local endpoints Local and OpenAI-compatible LLM endpoints (Ollama, LM Studio, etc.) do not require a real API key. Previously, setting CUSTOM_MODEL without OPENAI_KEY would leave the openai client as undefined, causing CUSTOM_MODEL to silently resolve to undefined and the app to throw "No model found". Fix providers.ts to create the openai client when CUSTOM_MODEL is set, using a placeholder API key so local endpoints are not blocked by key validation. Also correct the README which incorrectly referenced the non-existent OPENAI_MODEL variable instead of the actual CUSTOM_MODEL. Fixes #133, #98 Co-Authored-By: Octopus --- README.md | 6 +++--- src/ai/providers.ts | 15 +++++++++------ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 78d7dcaa..4dc4eb5c 100644 --- a/README.md +++ b/README.md @@ -102,10 +102,10 @@ FIRECRAWL_KEY="your_firecrawl_key" OPENAI_KEY="your_openai_key" ``` -To use local LLM, comment out `OPENAI_KEY` and instead uncomment `OPENAI_ENDPOINT` and `OPENAI_MODEL`: +To use a local LLM, uncomment `OPENAI_ENDPOINT` and `CUSTOM_MODEL` (you do not need to set `OPENAI_KEY` when using a local endpoint): -- Set `OPENAI_ENDPOINT` to the address of your local server (eg."http://localhost:1234/v1") -- Set `OPENAI_MODEL` to the name of the model loaded in your local server. +- Set `OPENAI_ENDPOINT` to the address of your local server (eg."http://localhost:11434/v1") +- Set `CUSTOM_MODEL` to the name of the model loaded in your local server. ### Docker diff --git a/src/ai/providers.ts b/src/ai/providers.ts index ce305aa3..f4290aa3 100644 --- a/src/ai/providers.ts +++ b/src/ai/providers.ts @@ -10,12 +10,15 @@ import { getEncoding } from 'js-tiktoken'; import { RecursiveCharacterTextSplitter } from './text-splitter'; // Providers -const openai = process.env.OPENAI_KEY - ? createOpenAI({ - apiKey: process.env.OPENAI_KEY, - baseURL: process.env.OPENAI_ENDPOINT || 'https://api.openai.com/v1', - }) - : undefined; +// Create openai client when OPENAI_KEY is set, or when CUSTOM_MODEL is configured +// (local/OpenAI-compatible endpoints don't require a real API key) +const openai = + process.env.OPENAI_KEY || process.env.CUSTOM_MODEL + ? createOpenAI({ + apiKey: process.env.OPENAI_KEY || 'placeholder', + baseURL: process.env.OPENAI_ENDPOINT || 'https://api.openai.com/v1', + }) + : undefined; const fireworks = process.env.FIREWORKS_KEY ? createFireworks({