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

🔑 feat: Set Google Service Key File Path (#8130)

Danny Avila20100e120bfd
diff --git a/api/server/services/Config/loadAsyncEndpoints.js b/api/server/services/Config/loadAsyncEndpoints.js
index 0282146cd1..edded906d8 100644
--- a/api/server/services/Config/loadAsyncEndpoints.js
+++ b/api/server/services/Config/loadAsyncEndpoints.js
@@ -1,3 +1,5 @@
+const fs = require('fs');
+const path = require('path');
const { EModelEndpoint } = require('librechat-data-provider');
const { isUserProvided } = require('~/server/utils');
const { config } = require('./EndpointService');
@@ -11,9 +13,21 @@ const { openAIApiKey, azureOpenAIApiKey, useAzurePlugins, userProvidedOpenAI, go
async function loadAsyncEndpoints(req) {
let i = 0;
let serviceKey, googleUserProvides;
+ const serviceKeyPath =
+ process.env.GOOGLE_SERVICE_KEY_FILE_PATH ||
+ path.join(__dirname, '../../..', 'data', 'auth.json');
+
try {
- serviceKey = require('~/data/auth.json');
- } catch (e) {
+ if (process.env.GOOGLE_SERVICE_KEY_FILE_PATH) {
+ const absolutePath = path.isAbsolute(serviceKeyPath)
+ ? serviceKeyPath
+ : path.resolve(serviceKeyPath);
+ const fileContent = fs.readFileSync(absolutePath, 'utf8');
+ serviceKey = JSON.parse(fileContent);
+ } else {
+ serviceKey = require('~/data/auth.json');
+ }
+ } catch {
if (i === 0) {
i++;
}
@@ -32,14 +46,14 @@ async function loadAsyncEndpoints(req) {
const gptPlugins =
useAzure || openAIApiKey || azureOpenAIApiKey
? {
- availableAgents: ['classic', 'functions'],
- userProvide: useAzure ? false : userProvidedOpenAI,
- userProvideURL: useAzure
- ? false
- : config[EModelEndpoint.openAI]?.userProvideURL ||
+ availableAgents: ['classic', 'functions'],
+ userProvide: useAzure ? false : userProvidedOpenAI,
+ userProvideURL: useAzure
+ ? false
+ : config[EModelEndpoint.openAI]?.userProvideURL ||
config[EModelEndpoint.azureOpenAI]?.userProvideURL,
- azure: useAzurePlugins || useAzure,
- }
+ azure: useAzurePlugins || useAzure,
+ }
: false;
return { google, gptPlugins };
diff --git a/api/server/services/Endpoints/google/initialize.js b/api/server/services/Endpoints/google/initialize.js
index 60e874d5b8..169d625e3f 100644
--- a/api/server/services/Endpoints/google/initialize.js
+++ b/api/server/services/Endpoints/google/initialize.js
@@ -1,3 +1,5 @@
+const fs = require('fs');
+const path = require('path');
const { getGoogleConfig, isEnabled } = require('@librechat/api');
const { EModelEndpoint, AuthKeys } = require('librechat-data-provider');
const { getUserKey, checkUserKeyExpiry } = require('~/server/services/UserService');
@@ -15,8 +17,20 @@ const initializeClient = async ({ req, res, endpointOption, overrideModel, optio
}
let serviceKey = {};
+
try {
- serviceKey = require('~/data/auth.json');
+ if (process.env.GOOGLE_SERVICE_KEY_FILE_PATH) {
+ const serviceKeyPath =
+ process.env.GOOGLE_SERVICE_KEY_FILE_PATH ||
+ path.join(__dirname, '../../../../..', 'data', 'auth.json');
+ const absolutePath = path.isAbsolute(serviceKeyPath)
+ ? serviceKeyPath
+ : path.resolve(serviceKeyPath);
+ const fileContent = fs.readFileSync(absolutePath, 'utf8');
+ serviceKey = JSON.parse(fileContent);
+ } else {
+ serviceKey = require('~/data/auth.json');
+ }
} catch (_e) {
// Do nothing
}
diff --git a/packages/api/src/files/mistral/crud.ts b/packages/api/src/files/mistral/crud.ts
index f3ad74b731..5b0d10659a 100644
--- a/packages/api/src/files/mistral/crud.ts
+++ b/packages/api/src/files/mistral/crud.ts
@@ -439,15 +439,20 @@ async function loadGoogleAuthConfig(): Promise<{
serviceAccount: GoogleServiceAccount;
accessToken: string;
}> {
- /** Path from current file to project root auth.json */
- const authJsonPath = path.join(__dirname, '..', '..', '..', 'api', 'data', 'auth.json');
+ /** Path from environment variable or default location */
+ const serviceKeyPath =
+ process.env.GOOGLE_SERVICE_KEY_FILE_PATH ||
+ path.join(__dirname, '..', '..', '..', 'api', 'data', 'auth.json');
+ const absolutePath = path.isAbsolute(serviceKeyPath)
+ ? serviceKeyPath
+ : path.resolve(serviceKeyPath);
let serviceKey: GoogleServiceAccount;
try {
- const authJsonContent = fs.readFileSync(authJsonPath, 'utf8');
+ const authJsonContent = fs.readFileSync(absolutePath, 'utf8');
serviceKey = JSON.parse(authJsonContent) as GoogleServiceAccount;
} catch {
- throw new Error(`Google service account not found at ${authJsonPath}`);
+ throw new Error(`Google service account not found at ${absolutePath}`);
}
if (!serviceKey.client_email || !serviceKey.private_key || !serviceKey.project_id) {