Skip to content

Allow OpenAI-compatible services without API key when base URL is set - #768

Draft
icereed with Copilot wants to merge 6 commits into
mainfrom
copilot/fix-lm-studio-api-issue
Draft

Allow OpenAI-compatible services without API key when base URL is set#768
icereed with Copilot wants to merge 6 commits into
mainfrom
copilot/fix-lm-studio-api-issue

Conversation

Copilot AI commented Nov 7, 2025

Copy link
Copy Markdown
Contributor

Application fails to start with OpenAI-compatible services (LM Studio, local inference servers) because it enforces OPENAI_API_KEY requirement even when OPENAI_BASE_URL is configured. These services typically don't require authentication.

Changes

Validation Logic

  • Modified startup validation to allow empty OPENAI_API_KEY when OPENAI_BASE_URL is set
  • Updated error message to indicate both authentication paths
  • Azure OpenAI still requires both key and URL (unchanged)

Client Creation

  • createLLM(), createVisionLLM(), and ocr.createOpenAIClient() now inject dummy token when base URL is set but key is empty
  • Dummy token defined in internal/constants package to avoid duplication

Testing

  • Added test coverage for OpenAI-compatible configurations (with/without API key)
  • Verified Azure and standard OpenAI flows remain unchanged

Usage

# LM Studio / OpenAI-compatible services (no key needed)
export OPENAI_BASE_URL="http://localhost:1234/v1"
export LLM_PROVIDER="openai"
export LLM_MODEL="model-name"
# OPENAI_API_KEY not required

# Standard OpenAI (key required)
export OPENAI_API_KEY="sk-..."
export LLM_PROVIDER="openai"

# Azure OpenAI (both required)
export OPENAI_API_KEY="..."
export OPENAI_BASE_URL="https://resource.openai.azure.com"
export OPENAI_API_TYPE="azure"

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • openaipublic.blob.core.windows.net
    • Triggering command: /tmp/go-build1520700788/b001/paperless-gpt.test -test.testlogfile=/tmp/go-build1520700788/b001/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true (dns block)
    • Triggering command: /tmp/go-build1391058986/b001/paperless-gpt.test -test.testlogfile=/tmp/go-build1391058986/b001/testlog.txt -test.paniconexit0 -test.timeout=10m0s (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Cannot use LM Studio despite OpenAI API compatibility – requires OPENAI_API_KEY</issue_title>
<issue_description>I'm trying to use LM Studio as an OpenAI-compatible backend, but the application still requires an API key for OpenAI, even though I'm setting the OPENAI_BASE_URL to the LM Studio URL.

Steps to reproduce:

  1. Set environment variables as follows:
    OPENAI_BASE_URL=http://localhost:1234/v1

  2. Run the application without setting OPENAI_API_KEY (since LM Studio doesn’t require one).

Expected behavior:
The app should connect to LM Studio successfully without needing an OpenAI API key.

Actual behavior:
The application immediately fails with the following error message in the log:
level=fatal msg="Please set the OPENAI_API_KEY environment variable for OpenAI provider."

Additional context:
Even when providing a dummy API key, the same error occurs.
It seems the application enforces OPENAI_API_KEY presence regardless of the base URL or provider.</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@coderabbitai

coderabbitai Bot commented Nov 7, 2025

Copy link
Copy Markdown
Contributor

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Comment @coderabbitai help to get the list of available commands and usage tips.

Copilot AI and others added 5 commits November 7, 2025 12:19
… key requirement

Co-authored-by: icereed <444269+icereed@users.noreply.github.com>
Co-authored-by: icereed <444269+icereed@users.noreply.github.com>
Co-authored-by: icereed <444269+icereed@users.noreply.github.com>
Co-authored-by: icereed <444269+icereed@users.noreply.github.com>
Co-authored-by: icereed <444269+icereed@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix LM Studio API key requirement issue Allow OpenAI-compatible services without API key when base URL is set Nov 7, 2025
Copilot AI requested a review from icereed November 7, 2025 12:33
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.

Cannot use LM Studio despite OpenAI API compatibility – requires OPENAI_API_KEY

2 participants