Skip to content

feat(config): add OpenAI-compatible custom provider support#67

Open
gcaguilar wants to merge 3 commits into
coollabsio:mainfrom
gcaguilar:main
Open

feat(config): add OpenAI-compatible custom provider support#67
gcaguilar wants to merge 3 commits into
coollabsio:mainfrom
gcaguilar:main

Conversation

@gcaguilar

@gcaguilar gcaguilar commented May 3, 2026

Copy link
Copy Markdown

Summary

  • Add CUSTOM_API_KEY, CUSTOM_BASE_URL, and CUSTOM_MODEL env vars for any OpenAI-compatible endpoint (LiteLLM, LocalAI, LM Studio, vLLM, etc.)
  • Update hasProvider validation in both configure.js and entrypoint.sh so the container starts with only CUSTOM_API_KEY set
  • Add 34 tests in scripts/configure.test.js covering provider config, base URL handling, model defaults, priority selection, and hasProvider
  • Fix Custom Provider Api Key #24

Details

The existing provider system supports built-in providers (Anthropic, OpenAI, Gemini, etc.) and custom/proxy providers that require a full models.providers config block. This PR adds a dedicated env-var path for OpenAI-compatible providers, following the same pattern as Venice AI, Moonshot, and Ollama.

Files changed (5 files, +442/-5)

File Change
scripts/configure.js Provider config block, primaryCandidates entry, hasProvider validation, error message
scripts/entrypoint.sh Provider check loop + error message
.env.example 3 new env vars with comments
README.md Provider table rows + updated priority list
scripts/configure.test.js New test file — 34 tests

Provider config

{
  "models": {
    "providers": {
      "openai-compatible": {
        "api": "openai-completions",
        "apiKey": "<CUSTOM_API_KEY>",
        "baseUrl": "<CUSTOM_BASE_URL or https://api.openai.com/v1>",
        "models": [{ "id": "<CUSTOM_MODEL or gpt-4>", "name": "...", "contextWindow": 128000 }]
      }
    }
  }
}

Env vars

Variable Default Description
CUSTOM_API_KEY (required) API key for the OpenAI-compatible endpoint
CUSTOM_BASE_URL https://api.openai.com/v1 Base URL (trailing slashes stripped)
CUSTOM_MODEL gpt-4 Model ID and display name

Allow any OpenAI-compatible endpoint via CUSTOM_API_KEY, CUSTOM_BASE_URL,

and CUSTOM_MODEL env vars. Useful for LiteLLM, LocalAI, LM Studio, vLLM,

and other OpenAI API proxies.

Updates hasProvider validation in both configure.js and entrypoint.sh

so the container starts with only CUSTOM_API_KEY set.

Adds 34 tests in scripts/configure.test.js covering provider config,

base URL handling, model defaults, priority selection, and hasProvider.
@samiralavi

Copy link
Copy Markdown

I need this PR to be merged soon

@gcaguilar

Copy link
Copy Markdown
Author

@andrasbacsai Could you take a look at the PR, please?

@andrasbacsai

Copy link
Copy Markdown
Member

@coderabbitai review

@coderabbitai

coderabbitai Bot commented May 26, 2026

Copy link
Copy Markdown
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented May 26, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

This PR adds support for OpenAI-compatible custom providers, enabling users to configure self-hosted or alternative endpoints via three environment variables: CUSTOM_API_KEY (required), CUSTOM_BASE_URL (optional, defaults to /v1), and CUSTOM_MODEL (optional, defaults to gpt-4). The configuration logic in scripts/configure.js creates a models.providers["openai-compatible"] entry when the API key is present, extends model auto-selection to include the custom provider as a fallback, and removes the provider configuration when the key is absent. Validation logic treats CUSTOM_API_KEY as a satisfying provider credential. Documentation, configuration examples, and comprehensive tests validate the feature across provider creation, removal, coexistence, priority ordering, and validation scenarios.


Come with me if you want to live... behind your own self-hosted servers instead of paying VC-backed serverless tax. This PR is good. It is very good. Now where is my gluten-free taco? The test suite is 409 lines of beautiful, hardened logic—no framework bloat, no magic. The Terminator approves.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@scripts/configure.js`:
- Line 373: The primaryCandidates array is hardcoded to
"openai-compatible/gpt-4" and doesn't honor the CUSTOM_MODEL used when
constructing the provider's models (the block that creates a model with
CUSTOM_MODEL around where models are defined and referenced by
primaryCandidates); update the primaryCandidates entry to use the same
CUSTOM_MODEL variable (e.g., process.env.CUSTOM_MODEL or the local constant used
to build the provider model) instead of the literal "openai-compatible/gpt-4" so
the auto-selection matches the provider's actual model ID.

In `@scripts/configure.test.js`:
- Around line 304-361: The test suite misses a case verifying CUSTOM_MODEL is
used when building primaryCandidates: update the tests in configure.test.js to
add a test (similar to the proposed snippet) that sets
process.env.CUSTOM_API_KEY and process.env.CUSTOM_MODEL and asserts the selected
model equals `openai-compatible/${process.env.CUSTOM_MODEL}`; ensure the
primaryCandidates entry for the custom provider uses `process.env.CUSTOM_MODEL
|| 'gpt-4'` so it mirrors the behavior expected by configure.js (see
configure.js line referenced around the primaryCandidates construction).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 0a69d2e6-a1a1-4ff5-a166-896ae1690ff9

📥 Commits

Reviewing files that changed from the base of the PR and between 577e3e8 and 76dbd5d.

📒 Files selected for processing (5)
  • .env.example
  • README.md
  • scripts/configure.js
  • scripts/configure.test.js
  • scripts/entrypoint.sh

Comment thread scripts/configure.js Outdated
Comment thread scripts/configure.test.js
@gcaguilar

Copy link
Copy Markdown
Author

@andrasbacsai Comments applied

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.

Custom Provider Api Key

3 participants