Skip to content

fix: allow CUSTOM_MODEL to work without OPENAI_KEY for local endpoints#163

Open
octo-patch wants to merge 1 commit into
dzhng:mainfrom
octo-patch:fix/custom-model-no-openai-key
Open

fix: allow CUSTOM_MODEL to work without OPENAI_KEY for local endpoints#163
octo-patch wants to merge 1 commit into
dzhng:mainfrom
octo-patch:fix/custom-model-no-openai-key

Conversation

@octo-patch

Copy link
Copy Markdown

Fixes #133
Fixes #98

Problem

When users try to use a local or OpenAI-compatible LLM (Ollama, LM Studio, etc.) by setting CUSTOM_MODEL and OPENAI_ENDPOINT without OPENAI_KEY, the app throws "No model found". This happens because:

  1. The openai client is only created when OPENAI_KEY is set
  2. customModel depends on the openai client: openai?.(process.env.CUSTOM_MODEL, ...)
  3. Without OPENAI_KEY, openai is undefined, so customModel is also undefined
  4. getModel() then throws "No model found" even though CUSTOM_MODEL is set

Additionally, the README incorrectly references a non-existent OPENAI_MODEL environment variable (should be CUSTOM_MODEL), which has confused many users (#107, #98, #133).

Solution

  • providers.ts: Create the openai client when either OPENAI_KEY or CUSTOM_MODEL is set. Local/compatible endpoints don't require a real API key, so we use 'placeholder' as a fallback to satisfy the SDK's requirement.
  • README.md: Correct OPENAI_MODELCUSTOM_MODEL and clarify that OPENAI_KEY is not needed for local endpoints.

Testing

Verified by tracing through the code: with CUSTOM_MODEL=llama3.1 and OPENAI_ENDPOINT=http://localhost:11434/v1 (no OPENAI_KEY), the openai client is now created and customModel is properly initialized.

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 dzhng#133, dzhng#98

Co-Authored-By: Octopus <liyuan851277048@icloud.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

No model found Completely impossible to bypass the OpenAI API key verification

1 participant