Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active
TypeScript aianthropicartifactsawsazurechatgptchatgpt-cloneclaudeclonedeepseekgeminigooglegpt-5librechatmcpo1openairesponses-apivisionwebui
🧾 feat: Serve Built-In Endpoint Model Lists From Config So Overrides Can Narrow Them (#16639)
Danny Avilaaab44c5e3585
diff --git a/api/server/services/Config/loadDefaultModels.js b/api/server/services/Config/loadDefaultModels.jsindex 794cabc406..8c569e7bd8 100644--- a/api/server/services/Config/loadDefaultModels.js+++ b/api/server/services/Config/loadDefaultModels.js@@ -7,6 +7,7 @@ const {getAppConfigOptionsFromUser,getOpenAIModels,getGoogleModels,+ configuredModelList,} = require('@librechat/api');const { getAppConfig } = require('./app');@@ -35,17 +36,21 @@ async function loadDefaultModels(req) {const [openAI, anthropic, azureOpenAI, assistants, azureAssistants, google, bedrock] =await Promise.all([- getOpenAIModels({ user: req.user.id, headers: openAIHeaders, userObject: req.user }).catch(- (error) => {- logger.error('Error fetching OpenAI models:', error);- return [];- },- ),+ getOpenAIModels({+ user: req.user.id,+ headers: openAIHeaders,+ userObject: req.user,+ configuredModels: configuredModelList(appConfig, EModelEndpoint.openAI),+ }).catch((error) => {+ logger.error('Error fetching OpenAI models:', error);+ return [];+ }),getAnthropicModels({user: req.user.id,vertexModels: vertexConfig?.modelNames,headers: anthropicHeaders,userObject: req.user,+ configuredModels: configuredModelList(appConfig, EModelEndpoint.anthropic),}).catch((error) => {logger.error('Error fetching Anthropic models:', error);return [];diff --git a/packages/api/src/endpoints/config/index.ts b/packages/api/src/endpoints/config/index.tsindex 4f5afaf927..a4fb7abff3 100644--- a/packages/api/src/endpoints/config/index.ts+++ b/packages/api/src/endpoints/config/index.ts@@ -1,5 +1,5 @@export { createEndpointsConfigService } from './endpoints';-export { createLoadConfigModels } from './models';+export { createLoadConfigModels, configuredModelList } from './models';export * from './providers';export type { EndpointsConfigDeps } from './endpoints';export type { LoadConfigModelsDeps } from './models';diff --git a/packages/api/src/endpoints/config/models.spec.ts b/packages/api/src/endpoints/config/models.spec.tsindex 1f748bfcbe..eea055ec9e 100644--- a/packages/api/src/endpoints/config/models.spec.ts+++ b/packages/api/src/endpoints/config/models.spec.ts@@ -16,7 +16,7 @@ jest.mock('~/utils', () => {});import { SCOPED_TOKEN_CONFIG_KEY_PREFIX } from '../keys';-import { createLoadConfigModels } from './models';+import { createLoadConfigModels, configuredModelList } from './models';describe('createLoadConfigModels – user-provided baseURL header guard', () => {const fetchModels = jest.fn().mockResolvedValue([]);@@ -297,3 +297,59 @@ describe('createLoadConfigModels – in-request fetch coalescing', () => {expect(fetchModels).toHaveBeenCalledTimes(1);});});++describe('createLoadConfigModels � configured model lists for built-in endpoints', () => {+ const load = (endpoints: Record<string, unknown>, config?: Record<string, unknown>) =>+ createLoadConfigModels({+ getAppConfig: jest.fn().mockResolvedValue({ endpoints }),+ getUserKeyValues: jest.fn(),+ fetchModels: jest.fn(),+ })({ user: { id: 'user-1' }, config } as unknown as ServerRequest);++ it.each([+ EModelEndpoint.openAI,+ EModelEndpoint.google,+ EModelEndpoint.anthropic,+ EModelEndpoint.bedrock,+ ])('serves the %s list from config in place of its environment list', async (endpoint) => {+ const models = await load({ [endpoint]: { models: ['model-a', 'model-b'] } });+ expect(models[endpoint]).toEqual(['model-a', 'model-b']);+ });++ it('reads the per-request config, so principal overrides narrow the list', async () => {+ const models = await load(+ { [EModelEndpoint.anthropic]: { models: ['base-a', 'base-b'] } },+ { endpoints: { [EModelEndpoint.anthropic]: { models: ['narrowed'] } } },+ );+ expect(models[EModelEndpoint.anthropic]).toEqual(['narrowed']);+ });++ it('leaves endpoints without a configured list to their environment defaults', async () => {+ const models = await load({ [EModelEndpoint.openAI]: { streamRate: 25 } });+ expect(models).not.toHaveProperty(EModelEndpoint.openAI);+ expect(models).not.toHaveProperty(EModelEndpoint.anthropic);+ });++ it('keeps an explicitly empty list and drops non-string entries', async () => {+ const models = await load({+ [EModelEndpoint.google]: { models: [] },+ [EModelEndpoint.bedrock]: { models: ['ok', 42, null] },+ });+ expect(models[EModelEndpoint.google]).toEqual([]);+ expect(models[EModelEndpoint.bedrock]).toEqual(['ok']);+ });+});++describe('configuredModelList', () => {+ it('returns string entries of a configured list and undefined otherwise', () => {+ const appConfig = {+ endpoints: {+ [EModelEndpoint.openAI]: { models: ['a', 7, 'b'] },+ [EModelEndpoint.google]: { streamRate: 25 },+ },+ } as unknown as Parameters<typeof configuredModelList>[0];+ expect(configuredModelList(appConfig, EModelEndpoint.openAI)).toEqual(['a', 'b']);+ expect(configuredModelList(appConfig, EModelEndpoint.google)).toBeUndefined();+ expect(configuredModelList(undefined, EModelEndpoint.anthropic)).toBeUndefined();+ });+});diff --git a/packages/api/src/endpoints/config/models.ts b/packages/api/src/endpoints/config/models.tsindex 9525064e4d..c524e31f4a 100644--- a/packages/api/src/endpoints/config/models.ts+++ b/packages/api/src/endpoints/config/models.ts@@ -14,6 +14,39 @@ import type { GetAppConfigOptions } from '~/app/service';import { fetchModels as defaultFetchModels } from '~/endpoints/models';import { getTokenConfigKey } from '~/endpoints/custom/initialize';import { getAppConfigOptionsFromUser } from '~/app/service';++/**+ * Built-in endpoints whose configured `models` list replaces their `*_MODELS`+ * environment list. Read per request, so principal overrides can narrow them.+ */+type ConfiguredModelListEndpoint =+ | EModelEndpoint.openAI+ | EModelEndpoint.google+ | EModelEndpoint.anthropic+ | EModelEndpoint.bedrock;++const CONFIGURED_MODEL_LIST_ENDPOINTS: readonly ConfiguredModelListEndpoint[] = [+ EModelEndpoint.openAI,+ EModelEndpoint.google,+ EModelEndpoint.anthropic,+ EModelEndpoint.bedrock,+];++/**+ * The model list configured for a built-in endpoint in the resolved config, or+ * `undefined` when none is set. A configured list replaces the environment list+ * and makes provider discovery unnecessary.+ */+export function configuredModelList(+ appConfig: AppConfig | null | undefined,+ endpoint: ConfiguredModelListEndpoint,+): string[] | undefined {+ const models = appConfig?.endpoints?.[endpoint]?.models;+ if (!Array.isArray(models)) {+ return undefined;+ }+ return models.filter((model): model is string => typeof model === 'string');+}import { resolveConfigSecret } from '~/admin/secrets';import { validateEndpointURL } from '~/auth';import { tokenConfigCache } from '~/cache';@@ -72,9 +105,11 @@ export function createLoadConfigModels(deps: LoadConfigModelsDeps) {modelsConfig[EModelEndpoint.azureAssistants] = azureConfig.assistantModels;}- const bedrockConfig = appConfig.endpoints?.[EModelEndpoint.bedrock];- if (bedrockConfig?.models && Array.isArray(bedrockConfig.models)) {- modelsConfig[EModelEndpoint.bedrock] = bedrockConfig.models;+ for (const endpoint of CONFIGURED_MODEL_LIST_ENDPOINTS) {+ const models = configuredModelList(appConfig, endpoint);+ if (models) {+ modelsConfig[endpoint] = models;+ }}if (!Array.isArray(appConfig.endpoints?.[EModelEndpoint.custom])) {diff --git a/packages/api/src/endpoints/models.spec.ts b/packages/api/src/endpoints/models.spec.tsindex a354303974..8bc1e7c45f 100644--- a/packages/api/src/endpoints/models.spec.ts+++ b/packages/api/src/endpoints/models.spec.ts@@ -1104,3 +1104,38 @@ describe('fetchModels caching behavior', () => {expect(mockCacheSet).toHaveBeenCalled();});});++describe('configured model lists skip provider discovery', () => {+ let originalEnv: NodeJS.ProcessEnv;++ beforeEach(() => {+ originalEnv = { ...process.env };+ delete process.env.OPENAI_MODELS;+ delete process.env.ANTHROPIC_MODELS;+ process.env.OPENAI_API_KEY = 'sk-test';+ process.env.ANTHROPIC_API_KEY = 'sk-ant-test';+ mockedAxios.get.mockReset();+ });++ afterEach(() => {+ process.env = originalEnv;+ });++ it('returns the configured OpenAI list without requesting /models', async () => {+ const models = await getOpenAIModels({ user: 'user-1', configuredModels: ['gpt-a', 'gpt-b'] });+ expect(models).toEqual(['gpt-a', 'gpt-b']);+ expect(mockedAxios.get).not.toHaveBeenCalled();+ });++ it('returns the configured Anthropic list without requesting /models', async () => {+ const models = await getAnthropicModels({ user: 'user-1', configuredModels: ['claude-a'] });+ expect(models).toEqual(['claude-a']);+ expect(mockedAxios.get).not.toHaveBeenCalled();+ });++ it('still discovers models when no list is configured', async () => {+ mockedAxios.get.mockResolvedValue({ data: { data: [{ id: 'gpt-discovered' }] } });+ await getOpenAIModels({ user: 'user-1' });+ expect(mockedAxios.get).toHaveBeenCalled();+ });+});diff --git a/packages/api/src/endpoints/models.ts b/packages/api/src/endpoints/models.tsindex b0beb1787a..74cba44869 100644--- a/packages/api/src/endpoints/models.ts+++ b/packages/api/src/endpoints/models.ts@@ -331,6 +331,8 @@ export interface GetOpenAIModelsOptions {headers?: Record<string, string> | null;/** User object for resolving header placeholders */userObject?: Partial<IUser>;+ /** A model list configured for the endpoint; when set, it is returned without discovery. */+ configuredModels?: string[];}function resolveOpenAIApiKey(opts: GetOpenAIModelsOptions): string | undefined {@@ -398,6 +400,9 @@ export async function fetchOpenAIModels(* @returns Promise resolving to array of model IDs*/export async function getOpenAIModels(opts: GetOpenAIModelsOptions = {}): Promise<string[]> {+ if (opts.configuredModels) {+ return opts.configuredModels;+ }let models = defaultModels[EModelEndpoint.openAI];if (opts.assistants) {@@ -486,8 +491,13 @@ export async function getAnthropicModels(vertexModels?: string[];headers?: Record<string, string> | null;userObject?: Partial<IUser>;+ /** A model list configured for the endpoint; when set, it is returned without discovery. */+ configuredModels?: string[];} = {},): Promise<string[]> {+ if (opts.configuredModels) {+ return opts.configuredModels;+ }const models = defaultModels[EModelEndpoint.anthropic];// Vertex AI models from YAML config take prioritydiff --git a/packages/data-provider/src/config.spec.ts b/packages/data-provider/src/config.spec.tsindex 72e479c429..d18d2b4f1e 100644--- a/packages/data-provider/src/config.spec.ts+++ b/packages/data-provider/src/config.spec.ts@@ -2399,3 +2399,28 @@ describe('interface theme config', () => {expect(chatProjectsConfigSchema.safeParse({ maxDescriptionLength: 10001 }).success).toBe(false);});});++describe('built-in endpoint model lists', () => {+ const parse = (endpoints: Record<string, unknown>) =>+ configSchema.safeParse({ version: '1.0', endpoints });++ it.each([+ EModelEndpoint.openAI,+ EModelEndpoint.google,+ EModelEndpoint.anthropic,+ EModelEndpoint.bedrock,+ ])('accepts a models list for %s', (endpoint) => {+ const result = parse({ [endpoint]: { models: ['model-a'] } });+ expect(result.success).toBe(true);+ expect(result.success && result.data.endpoints?.[endpoint]).toMatchObject({+ models: ['model-a'],+ });+ });++ it.each([EModelEndpoint.openAI, EModelEndpoint.google])(+ 'rejects a non-array models value for %s',+ (endpoint) => {+ expect(parse({ [endpoint]: { models: 'model-a' } }).success).toBe(false);+ },+ );+});diff --git a/packages/data-provider/src/config.ts b/packages/data-provider/src/config.tsindex cda40946ac..b38b0e98b7 100644--- a/packages/data-provider/src/config.ts+++ b/packages/data-provider/src/config.ts@@ -1963,6 +1963,17 @@ export type TVertexAIConfig = TVertexAISchema & {* Anthropic endpoint schema with optional Vertex AI configuration.* Extends baseEndpointSchema with Vertex AI support.*/+/**+ * A built-in endpoint whose configured `models` list replaces its `*_MODELS`+ * environment list. Read from the per-request config, so principal overrides+ * can narrow it.+ */+export const modelListEndpointSchema = baseEndpointSchema.merge(+ z.object({+ models: z.array(z.string()).optional(),+ }),+);+export const anthropicEndpointSchema = baseEndpointSchema.merge(z.object({/** Vertex AI configuration for running Anthropic models on Google Cloud */@@ -3741,8 +3752,8 @@ export const configSchema = z.object({* endpoint > a custom endpoint's own config.*/all: baseEndpointSchema.omit({ baseURL: true }).optional(),- [EModelEndpoint.openAI]: baseEndpointSchema.optional(),- [EModelEndpoint.google]: baseEndpointSchema.optional(),+ [EModelEndpoint.openAI]: modelListEndpointSchema.optional(),+ [EModelEndpoint.google]: modelListEndpointSchema.optional(),[EModelEndpoint.anthropic]: anthropicEndpointSchema.optional(),[EModelEndpoint.azureOpenAI]: azureEndpointSchema.optional(),[EModelEndpoint.azureAssistants]: assistantEndpointSchema.optional(),