Skip to content

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

🛰️ fix: Honor Anthropic Vertex Configuration (#12972)

Danny Avila69395d066726
diff --git a/api/server/services/Config/EndpointService.js b/api/server/services/Config/EndpointService.js
index b10c0d2890..058341ca2c 100644
--- a/api/server/services/Config/EndpointService.js
+++ b/api/server/services/Config/EndpointService.js
@@ -16,6 +16,7 @@ const {
} = process.env ?? {};
const userProvidedOpenAI = isUserProvided(openAIApiKey);
+const anthropicUsesVertex = isEnabled(process.env.ANTHROPIC_USE_VERTEX);
module.exports = {
config: {
@@ -23,9 +24,7 @@ module.exports = {
openAIApiKey,
azureOpenAIApiKey,
userProvidedOpenAI,
- [EModelEndpoint.anthropic]: generateConfig(
- anthropicApiKey || isEnabled(process.env.ANTHROPIC_USE_VERTEX),
- ),
+ [EModelEndpoint.anthropic]: generateConfig(anthropicUsesVertex ? 'true' : anthropicApiKey),
[EModelEndpoint.openAI]: generateConfig(openAIApiKey, OPENAI_REVERSE_PROXY),
[EModelEndpoint.azureOpenAI]: generateConfig(azureOpenAIApiKey, AZURE_OPENAI_BASEURL),
[EModelEndpoint.assistants]: generateConfig(
diff --git a/api/server/services/Config/__tests__/EndpointService.spec.js b/api/server/services/Config/__tests__/EndpointService.spec.js
new file mode 100644
index 0000000000..82f7175d23
--- /dev/null
+++ b/api/server/services/Config/__tests__/EndpointService.spec.js
@@ -0,0 +1,83 @@
+const mockDataProvider = {
+ Capabilities: {
+ actions: 'actions',
+ code_interpreter: 'code_interpreter',
+ image_vision: 'image_vision',
+ retrieval: 'retrieval',
+ tools: 'tools',
+ },
+ EModelEndpoint: {
+ agents: 'agents',
+ anthropic: 'anthropic',
+ assistants: 'assistants',
+ azureAssistants: 'azureAssistants',
+ azureOpenAI: 'azureOpenAI',
+ bedrock: 'bedrock',
+ google: 'google',
+ openAI: 'openAI',
+ },
+ defaultAgentCapabilities: [],
+ defaultRetrievalModels: [],
+ defaultAssistantsVersion: {
+ assistants: 1,
+ azureAssistants: 2,
+ },
+ isAgentsEndpoint: (endpoint) => endpoint === 'agents',
+ isAssistantsEndpoint: (endpoint) => endpoint === 'assistants' || endpoint === 'azureAssistants',
+};
+
+jest.mock(
+ '@librechat/api',
+ () => ({
+ sendEvent: jest.fn(),
+ isEnabled: (value) => value === true || value === 'true' || value === '1',
+ isUserProvided: (value) => value === 'user_provided',
+ }),
+ { virtual: true },
+);
+
+jest.mock('librechat-data-provider', () => mockDataProvider, { virtual: true });
+
+jest.mock('~/server/utils/handleText', () => ({
+ generateConfig: (key) => (key ? { userProvide: key === 'user_provided' } : false),
+}));
+
+describe('EndpointService', () => {
+ let originalEnv;
+ const { EModelEndpoint } = mockDataProvider;
+
+ beforeEach(() => {
+ originalEnv = { ...process.env };
+ jest.resetModules();
+ });
+
+ afterEach(() => {
+ process.env = originalEnv;
+ jest.resetModules();
+ });
+
+ function loadConfig(env) {
+ process.env = { ...originalEnv };
+ delete process.env.ANTHROPIC_API_KEY;
+ delete process.env.ANTHROPIC_USE_VERTEX;
+ Object.assign(process.env, env);
+ return require('../EndpointService').config;
+ }
+
+ it('does not require a user Anthropic API key when Vertex AI is enabled by env', () => {
+ const config = loadConfig({
+ ANTHROPIC_API_KEY: 'user_provided',
+ ANTHROPIC_USE_VERTEX: 'true',
+ });
+
+ expect(config[EModelEndpoint.anthropic]).toEqual({ userProvide: false });
+ });
+
+ it('requires a user Anthropic API key when user_provided is set without Vertex AI', () => {
+ const config = loadConfig({
+ ANTHROPIC_API_KEY: 'user_provided',
+ });
+
+ expect(config[EModelEndpoint.anthropic]).toEqual({ userProvide: true });
+ });
+});