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: Anthropic Vertex AI Support (#10780)
Joseph Licata90c63a56f305
diff --git a/.env.example b/.env.exampleindex 0f9c58dab9..c9bb6ac820 100644--- a/.env.example+++ b/.env.example@@ -124,6 +124,10 @@ ANTHROPIC_API_KEY=user_provided# ANTHROPIC_MODELS=claude-opus-4-20250514,claude-sonnet-4-20250514,claude-3-7-sonnet-20250219,claude-3-5-sonnet-20241022,claude-3-5-haiku-20241022,claude-3-opus-20240229,claude-3-sonnet-20240229,claude-3-haiku-20240307# ANTHROPIC_REVERSE_PROXY=+# Set to true to use Anthropic models through Google Vertex AI instead of direct API+# ANTHROPIC_USE_VERTEX=+# ANTHROPIC_VERTEX_REGION=us-east5+#============## Azure ##============#diff --git a/api/package.json b/api/package.jsonindex bab5e8f053..a82fb145b4 100644--- a/api/package.json+++ b/api/package.json@@ -34,6 +34,8 @@},"homepage": "https://librechat.ai","dependencies": {+ "@anthropic-ai/sdk": "^0.71.0",+ "@anthropic-ai/vertex-sdk": "^0.14.0","@aws-sdk/client-bedrock-runtime": "^3.941.0","@aws-sdk/client-s3": "^3.758.0","@aws-sdk/s3-request-presigner": "^3.758.0",diff --git a/api/server/controllers/agents/client.js b/api/server/controllers/agents/client.jsindex dced3acb02..2f40dbe083 100644--- a/api/server/controllers/agents/client.js+++ b/api/server/controllers/agents/client.js@@ -250,9 +250,7 @@ class AgentClient extends BaseClient {return this.contentParts;}- setOptions(options) {- logger.info('[api/server/controllers/agents/client.js] setOptions', options);- }+ setOptions(_options) {}/*** `AgentClient` is not opinionated about vision requests, so we don't do anything here@@ -747,10 +745,16 @@ class AgentClient extends BaseClient {if (!collectedUsage || !collectedUsage.length) {return;}+ // Support both OpenAI format (input_token_details) and Anthropic format (cache_*_input_tokens)+ const firstUsage = collectedUsage[0];const input_tokens =- (collectedUsage[0]?.input_tokens || 0) +- (Number(collectedUsage[0]?.input_token_details?.cache_creation) || 0) +- (Number(collectedUsage[0]?.input_token_details?.cache_read) || 0);+ (firstUsage?.input_tokens || 0) ++ (Number(firstUsage?.input_token_details?.cache_creation) ||+ Number(firstUsage?.cache_creation_input_tokens) ||+ 0) ++ (Number(firstUsage?.input_token_details?.cache_read) ||+ Number(firstUsage?.cache_read_input_tokens) ||+ 0);let output_tokens = 0;let previousTokens = input_tokens; // Start with original input@@ -760,8 +764,13 @@ class AgentClient extends BaseClient {continue;}- const cache_creation = Number(usage.input_token_details?.cache_creation) || 0;- const cache_read = Number(usage.input_token_details?.cache_read) || 0;+ // Support both OpenAI format (input_token_details) and Anthropic format (cache_*_input_tokens)+ const cache_creation =+ Number(usage.input_token_details?.cache_creation) ||+ Number(usage.cache_creation_input_tokens) ||+ 0;+ const cache_read =+ Number(usage.input_token_details?.cache_read) || Number(usage.cache_read_input_tokens) || 0;const txMetadata = {context,diff --git a/api/server/services/Config/EndpointService.js b/api/server/services/Config/EndpointService.jsindex 1cd4c9b6b8..b10c0d2890 100644--- a/api/server/services/Config/EndpointService.js+++ b/api/server/services/Config/EndpointService.js@@ -1,4 +1,4 @@-const { isUserProvided } = require('@librechat/api');+const { isUserProvided, isEnabled } = require('@librechat/api');const { EModelEndpoint } = require('librechat-data-provider');const { generateConfig } = require('~/server/utils/handleText');@@ -23,7 +23,9 @@ module.exports = {openAIApiKey,azureOpenAIApiKey,userProvidedOpenAI,- [EModelEndpoint.anthropic]: generateConfig(anthropicApiKey),+ [EModelEndpoint.anthropic]: generateConfig(+ anthropicApiKey || isEnabled(process.env.ANTHROPIC_USE_VERTEX),+ ),[EModelEndpoint.openAI]: generateConfig(openAIApiKey, OPENAI_REVERSE_PROXY),[EModelEndpoint.azureOpenAI]: generateConfig(azureOpenAIApiKey, AZURE_OPENAI_BASEURL),[EModelEndpoint.assistants]: generateConfig(diff --git a/api/server/services/Config/getEndpointsConfig.js b/api/server/services/Config/getEndpointsConfig.jsindex 8804fb7d3d..bb22584851 100644--- a/api/server/services/Config/getEndpointsConfig.js+++ b/api/server/services/Config/getEndpointsConfig.js@@ -43,6 +43,14 @@ async function getEndpointsConfig(req) {};}+ // Enable Anthropic endpoint when Vertex AI is configured in YAML+ if (appConfig.endpoints?.[EModelEndpoint.anthropic]?.vertexConfig?.enabled) {+ /** @type {Omit<TConfig, 'order'>} */+ mergedConfig[EModelEndpoint.anthropic] = {+ userProvide: false,+ };+ }+if (appConfig.endpoints?.[EModelEndpoint.azureOpenAI]?.assistants) {/** @type {Omit<TConfig, 'order'>} */mergedConfig[EModelEndpoint.azureAssistants] = {diff --git a/api/server/services/Config/loadDefaultModels.js b/api/server/services/Config/loadDefaultModels.jsindex 0a4b4a7fa7..31aa831a70 100644--- a/api/server/services/Config/loadDefaultModels.js+++ b/api/server/services/Config/loadDefaultModels.js@@ -6,6 +6,7 @@ const {getOpenAIModels,getGoogleModels,} = require('@librechat/api');+const { getAppConfig } = require('./app');/*** Loads the default models for the application.@@ -15,16 +16,21 @@ const {*/async function loadDefaultModels(req) {try {+ const appConfig = req.config ?? (await getAppConfig({ role: req.user?.role }));+ const vertexConfig = appConfig?.endpoints?.[EModelEndpoint.anthropic]?.vertexConfig;+const [openAI, anthropic, azureOpenAI, assistants, azureAssistants, google, bedrock] =await Promise.all([getOpenAIModels({ user: req.user.id }).catch((error) => {logger.error('Error fetching OpenAI models:', error);return [];}),- getAnthropicModels({ user: req.user.id }).catch((error) => {- logger.error('Error fetching Anthropic models:', error);- return [];- }),+ getAnthropicModels({ user: req.user.id, vertexModels: vertexConfig?.modelNames }).catch(+ (error) => {+ logger.error('Error fetching Anthropic models:', error);+ return [];+ },+ ),getOpenAIModels({ user: req.user.id, azure: true }).catch((error) => {logger.error('Error fetching Azure OpenAI models:', error);return [];diff --git a/librechat.example.yaml b/librechat.example.yamlindex 174613396d..983a5b611d 100644--- a/librechat.example.yaml+++ b/librechat.example.yaml@@ -253,6 +253,67 @@ endpoints:# minRelevanceScore: 0.45# # (optional) Agent Capabilities available to all users. Omit the ones you wish to exclude. Defaults to list below.# capabilities: ["execute_code", "file_search", "actions", "tools"]++ # Anthropic endpoint configuration with Vertex AI support+ # Use this to run Anthropic Claude models through Google Cloud Vertex AI+ # anthropic:+ # # (optional) Stream rate limiting in milliseconds+ # streamRate: 20+ # # (optional) Title model for conversation titles+ # titleModel: claude-3.5-haiku # Use the visible model name (key from models config)+ #+ # # Vertex AI Configuration - enables running Claude models via Google Cloud+ # # This is similar to Azure OpenAI but for Anthropic models on Google Cloud+ # # Vertex AI is automatically enabled when this config section is present+ # vertex:+ # # Vertex AI region (optional, defaults to 'us-east5')+ # # Available regions: us-east5, us-central1, europe-west1, europe-west4, asia-southeast1+ # region: "us-east5"+ # # Path to Google service account key file (optional)+ # # If not specified, uses GOOGLE_SERVICE_KEY_FILE env var or default path (api/data/auth.json)+ # # The project_id is automatically extracted from the service key file+ # # serviceKeyFile: "/path/to/service-account.json"+ # # Google Cloud Project ID (optional) - auto-detected from service key file+ # # Only specify if you need to override the project_id in your service key+ # # projectId: "${VERTEX_PROJECT_ID}"+ #+ # # ============================================================================+ # # Model Configuration - Set Visible Model Names and Deployment Mappings+ # # Similar to Azure OpenAI model naming pattern+ # # ============================================================================+ #+ # # Option 1: Simple array (legacy format - model name = deployment name)+ # # Use this if you want the technical model IDs to show in the UI+ # # models:+ # # - "claude-sonnet-4-20250514"+ # # - "claude-3-7-sonnet-20250219"+ # # - "claude-3-5-sonnet-v2@20241022"+ # # - "claude-3-5-haiku@20241022"+ #+ # # Option 2: Object format with custom visible names (RECOMMENDED)+ # # The key is the visible model name shown in the UI (can be any name you want)+ # # The deploymentName is the actual Vertex AI model ID used for API calls+ # # You can use friendly names (avoid spaces for cleaner YAML) or technical IDs as keys+ # models:+ # claude-opus-4.5:+ # deploymentName: claude-opus-4-5@20251101+ # claude-sonnet-4:+ # deploymentName: claude-sonnet-4-20250514+ # claude-3.7-sonnet:+ # deploymentName: claude-3-7-sonnet-20250219+ # claude-3.5-sonnet:+ # deploymentName: claude-3-5-sonnet-v2@20241022+ # claude-3.5-haiku:+ # deploymentName: claude-3-5-haiku@20241022+ #+ # # Option 3: Mixed format with default deploymentName+ # # Set a default deploymentName and use boolean values for models+ # # deploymentName: claude-sonnet-4-20250514+ # # models:+ # # claude-sonnet-4: true # Will use the default deploymentName+ # # claude-3.5-haiku:+ # # deploymentName: claude-3-5-haiku@20241022 # Override for this model+custom:# Groq Example- name: 'groq'diff --git a/package-lock.json b/package-lock.jsonindex c5c1e88a2e..95e79e6f82 100644--- a/package-lock.json+++ b/package-lock.json@@ -48,6 +48,8 @@"version": "v0.8.2-rc1","license": "ISC","dependencies": {+ "@anthropic-ai/sdk": "^0.71.0",+ "@anthropic-ai/vertex-sdk": "^0.14.0","@aws-sdk/client-bedrock-runtime": "^3.941.0","@aws-sdk/client-s3": "^3.758.0","@aws-sdk/s3-request-presigner": "^3.758.0",@@ -133,6 +135,596 @@"supertest": "^7.1.0"}},+ "api/node_modules/@anthropic-ai/sdk": {+ "version": "0.71.2",+ "resolved": "https://registry.npmjs.org/@anthropic-ai/sdk/-/sdk-0.71.2.tgz",+ "integrity": "sha512-TGNDEUuEstk/DKu0/TflXAEt+p+p/WhTlFzEnoosvbaDU2LTjm42igSdlL0VijrKpWejtOKxX0b8A7uc+XiSAQ==",+ "license": "MIT",+ "dependencies": {+ "json-schema-to-ts": "^3.1.1"+ },+ "bin": {+ "anthropic-ai-sdk": "bin/cli"+ },+ "peerDependencies": {+ "zod": "^3.25.0 || ^4.0.0"+ },+ "peerDependenciesMeta": {+ "zod": {+ "optional": true+ }+ }+ },+ "api/node_modules/@aws-sdk/client-bedrock-runtime": {+ "version": "3.941.0",+ "resolved": "https://registry.npmjs.org/@aws-sdk/client-bedrock-runtime/-/client-bedrock-runtime-3.941.0.tgz",+ "integrity": "sha512-hvOhVSe1OHTh8EvK/rIbURc0KmBSEceVKfF9TrLkwLbvLFZEGsy2y6lHi4CFuH5WYMPU0C1wLWfd2bgkLvsMcA==",+ "license": "Apache-2.0",+ "dependencies": {+ "@aws-crypto/sha256-browser": "5.2.0",+ "@aws-crypto/sha256-js": "5.2.0",+ "@aws-sdk/core": "3.940.0",+ "@aws-sdk/credential-provider-node": "3.940.0",+ "@aws-sdk/eventstream-handler-node": "3.936.0",+ "@aws-sdk/middleware-eventstream": "3.936.0",+ "@aws-sdk/middleware-host-header": "3.936.0",+ "@aws-sdk/middleware-logger": "3.936.0",+ "@aws-sdk/middleware-recursion-detection": "3.936.0",+ "@aws-sdk/middleware-user-agent": "3.940.0",+ "@aws-sdk/middleware-websocket": "3.936.0",+ "@aws-sdk/region-config-resolver": "3.936.0",+ "@aws-sdk/token-providers": "3.940.0",+ "@aws-sdk/types": "3.936.0",+ "@aws-sdk/util-endpoints": "3.936.0",+ "@aws-sdk/util-user-agent-browser": "3.936.0",+ "@aws-sdk/util-user-agent-node": "3.940.0",+ "@smithy/config-resolver": "^4.4.3",+ "@smithy/core": "^3.18.5",+ "@smithy/eventstream-serde-browser": "^4.2.5",+ "@smithy/eventstream-serde-config-resolver": "^4.3.5",+ "@smithy/eventstream-serde-node": "^4.2.5",+ "@smithy/fetch-http-handler": "^5.3.6",+ "@smithy/hash-node": "^4.2.5",+ "@smithy/invalid-dependency": "^4.2.5",+ "@smithy/middleware-content-length": "^4.2.5",+ "@smithy/middleware-endpoint": "^4.3.12",+ "@smithy/middleware-retry": "^4.4.12",+ "@smithy/middleware-serde": "^4.2.6",+ "@smithy/middleware-stack": "^4.2.5",+ "@smithy/node-config-provider": "^4.3.5",+ "@smithy/node-http-handler": "^4.4.5",+ "@smithy/protocol-http": "^5.3.5",+ "@smithy/smithy-client": "^4.9.8",+ "@smithy/types": "^4.9.0",+ "@smithy/url-parser": "^4.2.5",+ "@smithy/util-base64": "^4.3.0",+ "@smithy/util-body-length-browser": "^4.2.0",+ "@smithy/util-body-length-node": "^4.2.1",+ "@smithy/util-defaults-mode-browser": "^4.3.11",+ "@smithy/util-defaults-mode-node": "^4.2.14",+ "@smithy/util-endpoints": "^3.2.5",+ "@smithy/util-middleware": "^4.2.5",+ "@smithy/util-retry": "^4.2.5",+ "@smithy/util-stream": "^4.5.6",+ "@smithy/util-utf8": "^4.2.0",+ "tslib": "^2.6.2"+ },+ "engines": {+ "node": ">=18.0.0"+ }+ },+ "api/node_modules/@aws-sdk/client-sso": {+ "version": "3.940.0",+ "resolved": "https://registry.npmjs.org/@aws-sdk/client-sso/-/client-sso-3.940.0.tgz",+ "integrity": "sha512-SdqJGWVhmIURvCSgkDditHRO+ozubwZk9aCX9MK8qxyOndhobCndW1ozl3hX9psvMAo9Q4bppjuqy/GHWpjB+A==",+ "license": "Apache-2.0",+ "dependencies": {+ "@aws-crypto/sha256-browser": "5.2.0",+ "@aws-crypto/sha256-js": "5.2.0",+ "@aws-sdk/core": "3.940.0",+ "@aws-sdk/middleware-host-header": "3.936.0",+ "@aws-sdk/middleware-logger": "3.936.0",+ "@aws-sdk/middleware-recursion-detection": "3.936.0",+ "@aws-sdk/middleware-user-agent": "3.940.0",+ "@aws-sdk/region-config-resolver": "3.936.0",+ "@aws-sdk/types": "3.936.0",+ "@aws-sdk/util-endpoints": "3.936.0",+ "@aws-sdk/util-user-agent-browser": "3.936.0",+ "@aws-sdk/util-user-agent-node": "3.940.0",+ "@smithy/config-resolver": "^4.4.3",+ "@smithy/core": "^3.18.5",+ "@smithy/fetch-http-handler": "^5.3.6",+ "@smithy/hash-node": "^4.2.5",+ "@smithy/invalid-dependency": "^4.2.5",+ "@smithy/middleware-content-length": "^4.2.5",+ "@smithy/middleware-endpoint": "^4.3.12",+ "@smithy/middleware-retry": "^4.4.12",+ "@smithy/middleware-serde": "^4.2.6",+ "@smithy/middleware-stack": "^4.2.5",+ "@smithy/node-config-provider": "^4.3.5",+ "@smithy/node-http-handler": "^4.4.5",+ "@smithy/protocol-http": "^5.3.5",+ "@smithy/smithy-client": "^4.9.8",+ "@smithy/types": "^4.9.0",+ "@smithy/url-parser": "^4.2.5",+ "@smithy/util-base64": "^4.3.0",+ "@smithy/util-body-length-browser": "^4.2.0",+ "@smithy/util-body-length-node": "^4.2.1",+ "@smithy/util-defaults-mode-browser": "^4.3.11",+ "@smithy/util-defaults-mode-node": "^4.2.14",+ "@smithy/util-endpoints": "^3.2.5",+ "@smithy/util-middleware": "^4.2.5",+ "@smithy/util-retry": "^4.2.5",+ "@smithy/util-utf8": "^4.2.0",+ "tslib": "^2.6.2"+ },+ "engines": {+ "node": ">=18.0.0"+ }+ },+ "api/node_modules/@aws-sdk/core": {+ "version": "3.940.0",+ "resolved": "https://registry.npmjs.org/@aws-sdk/core/-/core-3.940.0.tgz",+ "integrity": "sha512-KsGD2FLaX5ngJao1mHxodIVU9VYd1E8810fcYiGwO1PFHDzf5BEkp6D9IdMeQwT8Q6JLYtiiT1Y/o3UCScnGoA==",+ "license": "Apache-2.0",+ "dependencies": {+ "@aws-sdk/types": "3.936.0",+ "@aws-sdk/xml-builder": "3.930.0",+ "@smithy/core": "^3.18.5",+ "@smithy/node-config-provider": "^4.3.5",+ "@smithy/property-provider": "^4.2.5",+ "@smithy/protocol-http": "^5.3.5",+ "@smithy/signature-v4": "^5.3.5",+ "@smithy/smithy-client": "^4.9.8",+ "@smithy/types": "^4.9.0",+ "@smithy/util-base64": "^4.3.0",+ "@smithy/util-middleware": "^4.2.5",+ "@smithy/util-utf8": "^4.2.0",+ "tslib": "^2.6.2"+ },+ "engines": {+ "node": ">=18.0.0"+ }+ },+ "api/node_modules/@aws-sdk/credential-provider-env": {+ "version": "3.940.0",+ "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-env/-/credential-provider-env-3.940.0.tgz",+ "integrity": "sha512-/G3l5/wbZYP2XEQiOoIkRJmlv15f1P3MSd1a0gz27lHEMrOJOGq66rF1Ca4OJLzapWt3Fy9BPrZAepoAX11kMw==",+ "license": "Apache-2.0",+ "dependencies": {+ "@aws-sdk/core": "3.940.0",+ "@aws-sdk/types": "3.936.0",+ "@smithy/property-provider": "^4.2.5",+ "@smithy/types": "^4.9.0",+ "tslib": "^2.6.2"+ },+ "engines": {+ "node": ">=18.0.0"+ }+ },+ "api/node_modules/@aws-sdk/credential-provider-http": {+ "version": "3.940.0",+ "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-http/-/credential-provider-http-3.940.0.tgz",+ "integrity": "sha512-dOrc03DHElNBD6N9Okt4U0zhrG4Wix5QUBSZPr5VN8SvmjD9dkrrxOkkJaMCl/bzrW7kbQEp7LuBdbxArMmOZQ==",+ "license": "Apache-2.0",+ "dependencies": {+ "@aws-sdk/core": "3.940.0",+ "@aws-sdk/types": "3.936.0",+ "@smithy/fetch-http-handler": "^5.3.6",+ "@smithy/node-http-handler": "^4.4.5",+ "@smithy/property-provider": "^4.2.5",+ "@smithy/protocol-http": "^5.3.5",+ "@smithy/smithy-client": "^4.9.8",+ "@smithy/types": "^4.9.0",+ "@smithy/util-stream": "^4.5.6",+ "tslib": "^2.6.2"+ },+ "engines": {+ "node": ">=18.0.0"+ }+ },+ "api/node_modules/@aws-sdk/credential-provider-ini": {+ "version": "3.940.0",+ "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-ini/-/credential-provider-ini-3.940.0.tgz",+ "integrity": "sha512-gn7PJQEzb/cnInNFTOaDoCN/hOKqMejNmLof1W5VW95Qk0TPO52lH8R4RmJPnRrwFMswOWswTOpR1roKNLIrcw==",+ "license": "Apache-2.0",+ "dependencies": {+ "@aws-sdk/core": "3.940.0",+ "@aws-sdk/credential-provider-env": "3.940.0",+ "@aws-sdk/credential-provider-http": "3.940.0",+ "@aws-sdk/credential-provider-login": "3.940.0",+ "@aws-sdk/credential-provider-process": "3.940.0",+ "@aws-sdk/credential-provider-sso": "3.940.0",+ "@aws-sdk/credential-provider-web-identity": "3.940.0",+ "@aws-sdk/nested-clients": "3.940.0",+ "@aws-sdk/types": "3.936.0",+ "@smithy/credential-provider-imds": "^4.2.5",+ "@smithy/property-provider": "^4.2.5",+ "@smithy/shared-ini-file-loader": "^4.4.0",+ "@smithy/types": "^4.9.0",+ "tslib": "^2.6.2"+ },+ "engines": {+ "node": ">=18.0.0"+ }+ },+ "api/node_modules/@aws-sdk/credential-provider-node": {+ "version": "3.940.0",+ "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-node/-/credential-provider-node-3.940.0.tgz",+ "integrity": "sha512-M8NFAvgvO6xZjiti5kztFiAYmSmSlG3eUfr4ZHSfXYZUA/KUdZU/D6xJyaLnU8cYRWBludb6K9XPKKVwKfqm4g==",+ "license": "Apache-2.0",+ "dependencies": {+ "@aws-sdk/credential-provider-env": "3.940.0",+ "@aws-sdk/credential-provider-http": "3.940.0",+ "@aws-sdk/credential-provider-ini": "3.940.0",+ "@aws-sdk/credential-provider-process": "3.940.0",+ "@aws-sdk/credential-provider-sso": "3.940.0",+ "@aws-sdk/credential-provider-web-identity": "3.940.0",+ "@aws-sdk/types": "3.936.0",+ "@smithy/credential-provider-imds": "^4.2.5",+ "@smithy/property-provider": "^4.2.5",+ "@smithy/shared-ini-file-loader": "^4.4.0",+ "@smithy/types": "^4.9.0",+ "tslib": "^2.6.2"+ },+ "engines": {+ "node": ">=18.0.0"+ }+ },+ "api/node_modules/@aws-sdk/credential-provider-process": {+ "version": "3.940.0",+ "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-process/-/credential-provider-process-3.940.0.tgz",+ "integrity": "sha512-pILBzt5/TYCqRsJb7vZlxmRIe0/T+FZPeml417EK75060ajDGnVJjHcuVdLVIeKoTKm9gmJc9l45gon6PbHyUQ==",+ "license": "Apache-2.0",+ "dependencies": {+ "@aws-sdk/core": "3.940.0",+ "@aws-sdk/types": "3.936.0",+ "@smithy/property-provider": "^4.2.5",+ "@smithy/shared-ini-file-loader": "^4.4.0",+ "@smithy/types": "^4.9.0",+ "tslib": "^2.6.2"+ },+ "engines": {+ "node": ">=18.0.0"+ }+ },+ "api/node_modules/@aws-sdk/credential-provider-sso": {+ "version": "3.940.0",+ "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-sso/-/credential-provider-sso-3.940.0.tgz",+ "integrity": "sha512-q6JMHIkBlDCOMnA3RAzf8cGfup+8ukhhb50fNpghMs1SNBGhanmaMbZSgLigBRsPQW7fOk2l8jnzdVLS+BB9Uw==",+ "license": "Apache-2.0",+ "dependencies": {+ "@aws-sdk/client-sso": "3.940.0",+ "@aws-sdk/core": "3.940.0",+ "@aws-sdk/token-providers": "3.940.0",+ "@aws-sdk/types": "3.936.0",+ "@smithy/property-provider": "^4.2.5",+ "@smithy/shared-ini-file-loader": "^4.4.0",+ "@smithy/types": "^4.9.0",+ "tslib": "^2.6.2"+ },+ "engines": {+ "node": ">=18.0.0"+ }+ },+ "api/node_modules/@aws-sdk/credential-provider-web-identity": {+ "version": "3.940.0",+ "resolved": "https://registry.npmjs.org/@aws-sdk/credential-provider-web-identity/-/credential-provider-web-identity-3.940.0.tgz",+ "integrity": "sha512-9QLTIkDJHHaYL0nyymO41H8g3ui1yz6Y3GmAN1gYQa6plXisuFBnGAbmKVj7zNvjWaOKdF0dV3dd3AFKEDoJ/w==",+ "license": "Apache-2.0",+ "dependencies": {+ "@aws-sdk/core": "3.940.0",+ "@aws-sdk/nested-clients": "3.940.0",+ "@aws-sdk/types": "3.936.0",+ "@smithy/property-provider": "^4.2.5",+ "@smithy/shared-ini-file-loader": "^4.4.0",+ "@smithy/types": "^4.9.0",+ "tslib": "^2.6.2"+ },+ "engines": {+ "node": ">=18.0.0"+ }+ },+ "api/node_modules/@aws-sdk/eventstream-handler-node": {+ "version": "3.936.0",+ "resolved": "https://registry.npmjs.org/@aws-sdk/eventstream-handler-node/-/eventstream-handler-node-3.936.0.tgz",+ "integrity": "sha512-4zIbhdRmol2KosIHmU31ATvNP0tkJhDlRj9GuawVJoEnMvJA1pd2U3SRdiOImJU3j8pT46VeS4YMmYxfjGHByg==",+ "license": "Apache-2.0",+ "dependencies": {+ "@aws-sdk/types": "3.936.0",+ "@smithy/eventstream-codec": "^4.2.5",+ "@smithy/types": "^4.9.0",+ "tslib": "^2.6.2"+ },+ "engines": {+ "node": ">=18.0.0"+ }+ },+ "api/node_modules/@aws-sdk/middleware-eventstream": {+ "version": "3.936.0",+ "resolved": "https://registry.npmjs.org/@aws-sdk/middleware-eventstream/-/middleware-eventstream-3.936.0.tgz",+ "integrity": "sha512-XQSH8gzLkk8CDUDxyt4Rdm9owTpRIPdtg2yw9Y2Wl5iSI55YQSiC3x8nM3c4Y4WqReJprunFPK225ZUDoYCfZA==",+ "license": "Apache-2.0",+ "dependencies": {+ "@aws-sdk/types": "3.936.0",+ "@smithy/protocol-http": "^5.3.5",+ "@smithy/types": "^4.9.0",+ "tslib": "^2.6.2"+ },+ "engines": {+ "node": ">=18.0.0"+ }+ },+ "api/node_modules/@aws-sdk/middleware-host-header": {+ "version": "3.936.0",+ "resolved": "https://registry.npmjs.org/@aws-sdk/middleware-host-header/-/middleware-host-header-3.936.0.tgz",+ "integrity": "sha512-tAaObaAnsP1XnLGndfkGWFuzrJYuk9W0b/nLvol66t8FZExIAf/WdkT2NNAWOYxljVs++oHnyHBCxIlaHrzSiw==",+ "license": "Apache-2.0",+ "dependencies": {+ "@aws-sdk/types": "3.936.0",+ "@smithy/protocol-http": "^5.3.5",+ "@smithy/types": "^4.9.0",+ "tslib": "^2.6.2"+ },+ "engines": {+ "node": ">=18.0.0"+ }+ },+ "api/node_modules/@aws-sdk/middleware-logger": {+ "version": "3.936.0",+ "resolved": "https://registry.npmjs.org/@aws-sdk/middleware-logger/-/middleware-logger-3.936.0.tgz",+ "integrity": "sha512-aPSJ12d3a3Ea5nyEnLbijCaaYJT2QjQ9iW+zGh5QcZYXmOGWbKVyPSxmVOboZQG+c1M8t6d2O7tqrwzIq8L8qw==",+ "license": "Apache-2.0",+ "dependencies": {+ "@aws-sdk/types": "3.936.0",+ "@smithy/types": "^4.9.0",+ "tslib": "^2.6.2"+ },+ "engines": {+ "node": ">=18.0.0"+ }+ },+ "api/node_modules/@aws-sdk/middleware-recursion-detection": {+ "version": "3.936.0",+ "resolved": "https://registry.npmjs.org/@aws-sdk/middleware-recursion-detection/-/middleware-recursion-detection-3.936.0.tgz",+ "integrity": "sha512-l4aGbHpXM45YNgXggIux1HgsCVAvvBoqHPkqLnqMl9QVapfuSTjJHfDYDsx1Xxct6/m7qSMUzanBALhiaGO2fA==",+ "license": "Apache-2.0",+ "dependencies": {+ "@aws-sdk/types": "3.936.0",+ "@aws/lambda-invoke-store": "^0.2.0",+ "@smithy/protocol-http": "^5.3.5",+ "@smithy/types": "^4.9.0",+ "tslib": "^2.6.2"+ },+ "engines": {+ "node": ">=18.0.0"+ }+ },+ "api/node_modules/@aws-sdk/middleware-user-agent": {+ "version": "3.940.0",+ "resolved": "https://registry.npmjs.org/@aws-sdk/middleware-user-agent/-/middleware-user-agent-3.940.0.tgz",+ "integrity": "sha512-nJbLrUj6fY+l2W2rIB9P4Qvpiy0tnTdg/dmixRxrU1z3e8wBdspJlyE+AZN4fuVbeL6rrRrO/zxQC1bB3cw5IA==",+ "license": "Apache-2.0",+ "dependencies": {+ "@aws-sdk/core": "3.940.0",+ "@aws-sdk/types": "3.936.0",+ "@aws-sdk/util-endpoints": "3.936.0",+ "@smithy/core": "^3.18.5",+ "@smithy/protocol-http": "^5.3.5",+ "@smithy/types": "^4.9.0",+ "tslib": "^2.6.2"+ },+ "engines": {+ "node": ">=18.0.0"+ }+ },+ "api/node_modules/@aws-sdk/middleware-websocket": {+ "version": "3.936.0",+ "resolved": "https://registry.npmjs.org/@aws-sdk/middleware-websocket/-/middleware-websocket-3.936.0.tgz",+ "integrity": "sha512-bPe3rqeugyj/MmjP0yBSZox2v1Wa8Dv39KN+RxVbQroLO8VUitBo6xyZ0oZebhZ5sASwSg58aDcMlX0uFLQnTA==",+ "license": "Apache-2.0",+ "dependencies": {+ "@aws-sdk/types": "3.936.0",+ "@aws-sdk/util-format-url": "3.936.0",+ "@smithy/eventstream-codec": "^4.2.5",+ "@smithy/eventstream-serde-browser": "^4.2.5",+ "@smithy/fetch-http-handler": "^5.3.6",+ "@smithy/protocol-http": "^5.3.5",+ "@smithy/signature-v4": "^5.3.5",+ "@smithy/types": "^4.9.0",+ "@smithy/util-hex-encoding": "^4.2.0",+ "tslib": "^2.6.2"+ },+ "engines": {+ "node": ">= 14.0.0"+ }+ },+ "api/node_modules/@aws-sdk/nested-clients": {+ "version": "3.940.0",+ "resolved": "https://registry.npmjs.org/@aws-sdk/nested-clients/-/nested-clients-3.940.0.tgz",+ "integrity": "sha512-x0mdv6DkjXqXEcQj3URbCltEzW6hoy/1uIL+i8gExP6YKrnhiZ7SzuB4gPls2UOpK5UqLiqXjhRLfBb1C9i4Dw==",+ "license": "Apache-2.0",+ "dependencies": {+ "@aws-crypto/sha256-browser": "5.2.0",+ "@aws-crypto/sha256-js": "5.2.0",+ "@aws-sdk/core": "3.940.0",+ "@aws-sdk/middleware-host-header": "3.936.0",+ "@aws-sdk/middleware-logger": "3.936.0",+ "@aws-sdk/middleware-recursion-detection": "3.936.0",+ "@aws-sdk/middleware-user-agent": "3.940.0",+ "@aws-sdk/region-config-resolver": "3.936.0",+ "@aws-sdk/types": "3.936.0",+ "@aws-sdk/util-endpoints": "3.936.0",+ "@aws-sdk/util-user-agent-browser": "3.936.0",+ "@aws-sdk/util-user-agent-node": "3.940.0",+ "@smithy/config-resolver": "^4.4.3",+ "@smithy/core": "^3.18.5",+ "@smithy/fetch-http-handler": "^5.3.6",+ "@smithy/hash-node": "^4.2.5",+ "@smithy/invalid-dependency": "^4.2.5",+ "@smithy/middleware-content-length": "^4.2.5",+ "@smithy/middleware-endpoint": "^4.3.12",+ "@smithy/middleware-retry": "^4.4.12",+ "@smithy/middleware-serde": "^4.2.6",+ "@smithy/middleware-stack": "^4.2.5",+ "@smithy/node-config-provider": "^4.3.5",+ "@smithy/node-http-handler": "^4.4.5",+ "@smithy/protocol-http": "^5.3.5",+ "@smithy/smithy-client": "^4.9.8",+ "@smithy/types": "^4.9.0",+ "@smithy/url-parser": "^4.2.5",+ "@smithy/util-base64": "^4.3.0",+ "@smithy/util-body-length-browser": "^4.2.0",+ "@smithy/util-body-length-node": "^4.2.1",+ "@smithy/util-defaults-mode-browser": "^4.3.11",+ "@smithy/util-defaults-mode-node": "^4.2.14",+ "@smithy/util-endpoints": "^3.2.5",+ "@smithy/util-middleware": "^4.2.5",+ "@smithy/util-retry": "^4.2.5",+ "@smithy/util-utf8": "^4.2.0",+ "tslib": "^2.6.2"+ },+ "engines": {+ "node": ">=18.0.0"+ }+ },+ "api/node_modules/@aws-sdk/region-config-resolver": {+ "version": "3.936.0",+ "resolved": "https://registry.npmjs.org/@aws-sdk/region-config-resolver/-/region-config-resolver-3.936.0.tgz",+ "integrity": "sha512-wOKhzzWsshXGduxO4pqSiNyL9oUtk4BEvjWm9aaq6Hmfdoydq6v6t0rAGHWPjFwy9z2haovGRi3C8IxdMB4muw==",+ "license": "Apache-2.0",+ "dependencies": {+ "@aws-sdk/types": "3.936.0",+ "@smithy/config-resolver": "^4.4.3",+ "@smithy/node-config-provider": "^4.3.5",+ "@smithy/types": "^4.9.0",+ "tslib": "^2.6.2"+ },+ "engines": {+ "node": ">=18.0.0"+ }+ },+ "api/node_modules/@aws-sdk/token-providers": {+ "version": "3.940.0",+ "resolved": "https://registry.npmjs.org/@aws-sdk/token-providers/-/token-providers-3.940.0.tgz",+ "integrity": "sha512-k5qbRe/ZFjW9oWEdzLIa2twRVIEx7p/9rutofyrRysrtEnYh3HAWCngAnwbgKMoiwa806UzcTRx0TjyEpnKcCg==",+ "license": "Apache-2.0",+ "dependencies": {+ "@aws-sdk/core": "3.940.0",+ "@aws-sdk/nested-clients": "3.940.0",+ "@aws-sdk/types": "3.936.0",+ "@smithy/property-provider": "^4.2.5",+ "@smithy/shared-ini-file-loader": "^4.4.0",+ "@smithy/types": "^4.9.0",+ "tslib": "^2.6.2"+ },+ "engines": {+ "node": ">=18.0.0"+ }+ },+ "api/node_modules/@aws-sdk/types": {+ "version": "3.936.0",+ "resolved": "https://registry.npmjs.org/@aws-sdk/types/-/types-3.936.0.tgz",+ "integrity": "sha512-uz0/VlMd2pP5MepdrHizd+T+OKfyK4r3OA9JI+L/lPKg0YFQosdJNCKisr6o70E3dh8iMpFYxF1UN/4uZsyARg==",+ "license": "Apache-2.0",+ "dependencies": {+ "@smithy/types": "^4.9.0",+ "tslib": "^2.6.2"+ },+ "engines": {+ "node": ">=18.0.0"+ }+ },+ "api/node_modules/@aws-sdk/util-endpoints": {+ "version": "3.936.0",+ "resolved": "https://registry.npmjs.org/@aws-sdk/util-endpoints/-/util-endpoints-3.936.0.tgz",+ "integrity": "sha512-0Zx3Ntdpu+z9Wlm7JKUBOzS9EunwKAb4KdGUQQxDqh5Lc3ta5uBoub+FgmVuzwnmBu9U1Os8UuwVTH0Lgu+P5w==",+ "license": "Apache-2.0",+ "dependencies": {+ "@aws-sdk/types": "3.936.0",+ "@smithy/types": "^4.9.0",+ "@smithy/url-parser": "^4.2.5",+ "@smithy/util-endpoints": "^3.2.5",+ "tslib": "^2.6.2"+ },+ "engines": {+ "node": ">=18.0.0"+ }+ },+ "api/node_modules/@aws-sdk/util-format-url": {+ "version": "3.936.0",+ "resolved": "https://registry.npmjs.org/@aws-sdk/util-format-url/-/util-format-url-3.936.0.tgz",+ "integrity": "sha512-MS5eSEtDUFIAMHrJaMERiHAvDPdfxc/T869ZjDNFAIiZhyc037REw0aoTNeimNXDNy2txRNZJaAUn/kE4RwN+g==",+ "license": "Apache-2.0",+ "dependencies": {+ "@aws-sdk/types": "3.936.0",+ "@smithy/querystring-builder": "^4.2.5",+ "@smithy/types": "^4.9.0",+ "tslib": "^2.6.2"+ },+ "engines": {+ "node": ">=18.0.0"+ }+ },+ "api/node_modules/@aws-sdk/util-user-agent-browser": {+ "version": "3.936.0",+ "resolved": "https://registry.npmjs.org/@aws-sdk/util-user-agent-browser/-/util-user-agent-browser-3.936.0.tgz",+ "integrity": "sha512-eZ/XF6NxMtu+iCma58GRNRxSq4lHo6zHQLOZRIeL/ghqYJirqHdenMOwrzPettj60KWlv827RVebP9oNVrwZbw==",+ "license": "Apache-2.0",+ "dependencies": {+ "@aws-sdk/types": "3.936.0",+ "@smithy/types": "^4.9.0",+ "bowser": "^2.11.0",+ "tslib": "^2.6.2"+ }+ },+ "api/node_modules/@aws-sdk/util-user-agent-node": {+ "version": "3.940.0",+ "resolved": "https://registry.npmjs.org/@aws-sdk/util-user-agent-node/-/util-user-agent-node-3.940.0.tgz",+ "integrity": "sha512-dlD/F+L/jN26I8Zg5x0oDGJiA+/WEQmnSE27fi5ydvYnpfQLwThtQo9SsNS47XSR/SOULaaoC9qx929rZuo74A==",+ "license": "Apache-2.0",+ "dependencies": {+ "@aws-sdk/middleware-user-agent": "3.940.0",+ "@aws-sdk/types": "3.936.0",+ "@smithy/node-config-provider": "^4.3.5",+ "@smithy/types": "^4.9.0",+ "tslib": "^2.6.2"+ },+ "engines": {+ "node": ">=18.0.0"+ },+ "peerDependencies": {+ "aws-crt": ">=1.0.0"+ },+ "peerDependenciesMeta": {+ "aws-crt": {+ "optional": true+ }+ }+ },+ "api/node_modules/@aws-sdk/xml-builder": {+ "version": "3.930.0",+ "resolved": "https://registry.npmjs.org/@aws-sdk/xml-builder/-/xml-builder-3.930.0.tgz",+ "integrity": "sha512-YIfkD17GocxdmlUVc3ia52QhcWuRIUJonbF8A2CYfcWNV3HzvAqpcPeC0bYUhkK+8e8YO1ARnLKZQE0TlwzorA==",+ "license": "Apache-2.0",+ "dependencies": {+ "@smithy/types": "^4.9.0",+ "fast-xml-parser": "5.2.5",+ "tslib": "^2.6.2"+ },+ "engines": {+ "node": ">=18.0.0"+ }+ },+ "api/node_modules/@aws/lambda-invoke-store": {+ "version": "0.2.1",+ "resolved": "https://registry.npmjs.org/@aws/lambda-invoke-store/-/lambda-invoke-store-0.2.1.tgz",+ "integrity": "sha512-sIyFcoPZkTtNu9xFeEoynMef3bPJIAbOfUh+ueYcfhVl6xm2VRtMcMclSxmZCMnHHd4hlYKJeq/aggmBEWynww==",+ "license": "Apache-2.0",+ "engines": {+ "node": ">=18.0.0"+ }+ },"api/node_modules/@node-saml/node-saml": {"version": "5.1.0","resolved": "https://registry.npmjs.org/@node-saml/node-saml/-/node-saml-5.1.0.tgz",@@ -2097,6 +2689,16 @@}}},+ "node_modules/@anthropic-ai/vertex-sdk": {+ "version": "0.14.0",+ "resolved": "https://registry.npmjs.org/@anthropic-ai/vertex-sdk/-/vertex-sdk-0.14.0.tgz",+ "integrity": "sha512-YIonqYEwQ9ILvpeOUBRBCv+91nzIs/MAZIAJ6yyJ3muwoTbZdEu54A2HcM4nRHH+Gy1vxz0FVau6aGSayXNeWQ==",+ "license": "MIT",+ "dependencies": {+ "@anthropic-ai/sdk": ">=0.50.3 <1",+ "google-auth-library": "^9.4.2"+ }+ },"node_modules/@ariakit/core": {"version": "0.4.15","resolved": "https://registry.npmjs.org/@ariakit/core/-/core-0.4.15.tgz",@@ -43015,6 +43617,7 @@"typescript": "^5.0.4"},"peerDependencies": {+ "@anthropic-ai/vertex-sdk": "^0.14.0","@aws-sdk/client-bedrock-runtime": "^3.941.0","@aws-sdk/client-s3": "^3.758.0","@azure/identity": "^4.7.0",diff --git a/package.json b/package.jsonindex d0506b7182..0f3831ee24 100644--- a/package.json+++ b/package.json@@ -134,6 +134,7 @@"axios": "1.12.1","elliptic": "^6.6.1","form-data": "^4.0.4",+ "tslib": "^2.8.1","mdast-util-gfm-autolink-literal": "2.0.0","remark-gfm": {"mdast-util-gfm-autolink-literal": "2.0.0"diff --git a/packages/api/package.json b/packages/api/package.jsonindex abcba89716..876239f9b3 100644--- a/packages/api/package.json+++ b/packages/api/package.json@@ -79,6 +79,7 @@"registry": "https://registry.npmjs.org/"},"peerDependencies": {+ "@anthropic-ai/vertex-sdk": "^0.14.0","@aws-sdk/client-bedrock-runtime": "^3.941.0","@aws-sdk/client-s3": "^3.758.0","@azure/identity": "^4.7.0",diff --git a/packages/api/src/endpoints/anthropic/index.ts b/packages/api/src/endpoints/anthropic/index.tsindex e90546e461..0ec84d0466 100644--- a/packages/api/src/endpoints/anthropic/index.ts+++ b/packages/api/src/endpoints/anthropic/index.ts@@ -1,3 +1,4 @@export * from './helpers';export * from './llm';+export * from './vertex';export * from './initialize';diff --git a/packages/api/src/endpoints/anthropic/initialize.ts b/packages/api/src/endpoints/anthropic/initialize.tsindex 9a8984b5c7..58237b9604 100644--- a/packages/api/src/endpoints/anthropic/initialize.ts+++ b/packages/api/src/endpoints/anthropic/initialize.ts@@ -1,14 +1,16 @@-import { EModelEndpoint } from 'librechat-data-provider';+import { EModelEndpoint, AuthKeys } from 'librechat-data-provider';import type { BaseInitializeParams, InitializeResultBase, AnthropicConfigOptions } from '~/types';-import { checkUserKeyExpiry } from '~/utils';+import { checkUserKeyExpiry, isEnabled } from '~/utils';+import { loadAnthropicVertexCredentials, getVertexCredentialOptions } from './vertex';import { getLLMConfig } from './llm';/*** Initializes Anthropic endpoint configuration.+ * Supports both direct API key authentication and Google Cloud Vertex AI.** @param params - Configuration parameters* @returns Promise resolving to Anthropic configuration options- * @throws Error if API key is not provided+ * @throws Error if API key is not provided (when not using Vertex AI)*/export async function initializeAnthropic({req,@@ -20,45 +22,66 @@ export async function initializeAnthropic({const appConfig = req.config;const { ANTHROPIC_API_KEY, ANTHROPIC_REVERSE_PROXY, PROXY } = process.env;const { key: expiresAt } = req.body;- const isUserProvided = ANTHROPIC_API_KEY === 'user_provided';- const anthropicApiKey = isUserProvided- ? await db.getUserKey({ userId: req.user?.id ?? '', name: EModelEndpoint.anthropic })- : ANTHROPIC_API_KEY;+ let credentials: Record<string, unknown> = {};+ let vertexOptions: { region?: string; projectId?: string } | undefined;- if (!anthropicApiKey) {- throw new Error('Anthropic API key not provided. Please provide it again.');- }+ /** @type {undefined | import('librechat-data-provider').TVertexAIConfig} */+ const vertexConfig = appConfig?.endpoints?.[EModelEndpoint.anthropic]?.vertexConfig;- if (expiresAt && isUserProvided) {- checkUserKeyExpiry(expiresAt, EModelEndpoint.anthropic);- }+ // Check for Vertex AI configuration: YAML config takes priority over env var+ // When vertexConfig exists and enabled is not explicitly false, Vertex AI is enabled+ const useVertexAI =+ (vertexConfig && vertexConfig.enabled !== false) || isEnabled(process.env.ANTHROPIC_USE_VERTEX);- let clientOptions: AnthropicConfigOptions = {};+ if (useVertexAI) {+ // Load credentials with optional YAML config overrides+ const credentialOptions = vertexConfig ? getVertexCredentialOptions(vertexConfig) : undefined;+ credentials = await loadAnthropicVertexCredentials(credentialOptions);- /** @type {undefined | TBaseEndpoint} */- const anthropicConfig = appConfig?.endpoints?.[EModelEndpoint.anthropic];+ // Store vertex options for client creation+ if (vertexConfig) {+ vertexOptions = {+ region: vertexConfig.region,+ projectId: vertexConfig.projectId,+ };+ }+ } else {+ const isUserProvided = ANTHROPIC_API_KEY === 'user_provided';- if (anthropicConfig) {- clientOptions = {- ...clientOptions,- // Note: _lc_stream_delay is set on modelOptions in the result- };- }+ const anthropicApiKey = isUserProvided+ ? await db.getUserKey({ userId: req.user?.id ?? '', name: EModelEndpoint.anthropic })+ : ANTHROPIC_API_KEY;- const allConfig = appConfig?.endpoints?.all;+ if (!anthropicApiKey) {+ throw new Error('Anthropic API key not provided. Please provide it again.');+ }++ if (expiresAt && isUserProvided) {+ checkUserKeyExpiry(expiresAt, EModelEndpoint.anthropic);+ }- clientOptions = {+ credentials[AuthKeys.ANTHROPIC_API_KEY] = anthropicApiKey;+ }++ const clientOptions: AnthropicConfigOptions = {proxy: PROXY ?? undefined,reverseProxyUrl: ANTHROPIC_REVERSE_PROXY ?? undefined,modelOptions: {...(model_parameters ?? {}),user: req.user?.id,},- ...clientOptions,+ // Pass Vertex AI options if configured+ ...(vertexOptions && { vertexOptions }),+ // Pass full Vertex AI config including model mappings+ ...(vertexConfig && { vertexConfig }),};- const result = getLLMConfig(anthropicApiKey, clientOptions);+ /** @type {undefined | TBaseEndpoint} */+ const anthropicConfig = appConfig?.endpoints?.[EModelEndpoint.anthropic];+ const allConfig = appConfig?.endpoints?.all;++ const result = getLLMConfig(credentials, clientOptions);// Apply stream rate delayif (anthropicConfig?.streamRate) {diff --git a/packages/api/src/endpoints/anthropic/llm.spec.ts b/packages/api/src/endpoints/anthropic/llm.spec.tsindex 24fbef344b..5c220d2dc7 100644--- a/packages/api/src/endpoints/anthropic/llm.spec.ts+++ b/packages/api/src/endpoints/anthropic/llm.spec.ts@@ -238,9 +238,12 @@ describe('getLLMConfig', () => {});describe('Edge cases', () => {- it('should handle missing apiKey', () => {- const result = getLLMConfig(undefined, { modelOptions: {} });- expect(result.llmConfig).not.toHaveProperty('apiKey');+ it('should throw error when missing credentials', () => {+ expect(() => {+ getLLMConfig(undefined, { modelOptions: {} });+ }).toThrow(+ 'Invalid credentials provided. Please provide either a valid Anthropic API key or service account credentials for Vertex AI.',+ );});it('should handle empty modelOptions', () => {diff --git a/packages/api/src/endpoints/anthropic/llm.ts b/packages/api/src/endpoints/anthropic/llm.tsindex 725a608959..408ad2a77c 100644--- a/packages/api/src/endpoints/anthropic/llm.ts+++ b/packages/api/src/endpoints/anthropic/llm.ts@@ -1,8 +1,40 @@import { Dispatcher, ProxyAgent } from 'undici';+import { logger } from '@librechat/data-schemas';import { AnthropicClientOptions } from '@librechat/agents';-import { anthropicSettings, removeNullishValues } from 'librechat-data-provider';-import type { AnthropicLLMConfigResult, AnthropicConfigOptions } from '~/types/anthropic';+import { anthropicSettings, removeNullishValues, AuthKeys } from 'librechat-data-provider';+import type {+ AnthropicLLMConfigResult,+ AnthropicConfigOptions,+ AnthropicCredentials,+} from '~/types/anthropic';import { checkPromptCacheSupport, getClaudeHeaders, configureReasoning } from './helpers';+import {+ createAnthropicVertexClient,+ isAnthropicVertexCredentials,+ getVertexDeploymentName,+} from './vertex';++/**+ * Parses credentials from string or object format+ * - If a valid JSON string is passed, it parses and returns the object+ * - If a plain API key string is passed, it wraps it in an AnthropicCredentials object+ * - If an object is passed, it returns it directly+ * - If undefined, returns an empty object+ */+function parseCredentials(+ credentials: string | AnthropicCredentials | undefined,+): AnthropicCredentials {+ if (typeof credentials === 'string') {+ try {+ return JSON.parse(credentials);+ } catch {+ // If not valid JSON, treat as a plain API key+ logger.debug('[Anthropic] Credentials not JSON, treating as API key');+ return { [AuthKeys.ANTHROPIC_API_KEY]: credentials };+ }+ }+ return credentials && typeof credentials === 'object' ? credentials : {};+}/** Known Anthropic parameters that map directly to the client config */export const knownAnthropicParams = new Set([@@ -38,13 +70,13 @@ function applyDefaultParams(target: Record<string, unknown>, defaults: Record<st/*** Generates configuration options for creating an Anthropic language model (LLM) instance.- * @param apiKey - The API key for authentication with Anthropic.+ * @param credentials - The API key for authentication with Anthropic, or credentials object for Vertex AI.* @param options={} - Additional options for configuring the LLM.* @returns Configuration options for creating an Anthropic LLM instance, with null and undefined values removed.*/function getLLMConfig(- apiKey?: string,- options: AnthropicConfigOptions = {} as AnthropicConfigOptions,+ credentials: string | AnthropicCredentials | undefined,+ options: AnthropicConfigOptions = {},): AnthropicLLMConfigResult {const systemOptions = {thinking: options.modelOptions?.thinking ?? anthropicSettings.thinking.default,@@ -74,7 +106,6 @@ function getLLMConfig(let enableWebSearch = mergedOptions.web_search;let requestOptions: AnthropicClientOptions & { stream?: boolean } = {- apiKey,model: mergedOptions.model,stream: mergedOptions.stream,temperature: mergedOptions.temperature,@@ -89,6 +120,29 @@ function getLLMConfig(},};+ const creds = parseCredentials(credentials);+ const apiKey = creds[AuthKeys.ANTHROPIC_API_KEY] ?? null;++ if (isAnthropicVertexCredentials(creds)) {+ // Vertex AI configuration - use custom client with optional YAML config+ // Map the visible model name to the actual deployment name for Vertex AI+ const deploymentName = getVertexDeploymentName(+ requestOptions.model ?? '',+ options.vertexConfig,+ );+ requestOptions.model = deploymentName;++ requestOptions.createClient = () =>+ createAnthropicVertexClient(creds, requestOptions.clientOptions, options.vertexOptions);+ } else if (apiKey) {+ // Direct API configuration+ requestOptions.apiKey = apiKey;+ } else {+ throw new Error(+ 'Invalid credentials provided. Please provide either a valid Anthropic API key or service account credentials for Vertex AI.',+ );+ }+requestOptions = configureReasoning(requestOptions, systemOptions);if (!/claude-3[-.]7/.test(mergedOptions.model)) {@@ -180,6 +234,17 @@ function getLLMConfig(type: 'web_search_20250305',name: 'web_search',});++ if (isAnthropicVertexCredentials(creds)) {+ if (!requestOptions.clientOptions) {+ requestOptions.clientOptions = {};+ }++ requestOptions.clientOptions.defaultHeaders = {+ ...requestOptions.clientOptions.defaultHeaders,+ 'anthropic-beta': 'web-search-2025-03-05',+ };+ }}return {diff --git a/packages/api/src/endpoints/anthropic/vertex.ts b/packages/api/src/endpoints/anthropic/vertex.tsnew file mode 100644index 0000000000..116a00875f--- /dev/null+++ b/packages/api/src/endpoints/anthropic/vertex.ts@@ -0,0 +1,222 @@+import path from 'path';+import { AnthropicVertex } from '@anthropic-ai/vertex-sdk';+import { GoogleAuth } from 'google-auth-library';+import { ClientOptions } from '@anthropic-ai/sdk';+import { AuthKeys } from 'librechat-data-provider';+import { loadServiceKey } from '~/utils/key';+import type { AnthropicCredentials, VertexAIClientOptions } from '~/types/anthropic';++/**+ * Options for loading Vertex AI credentials+ */+export interface VertexCredentialOptions {+ /** Path to service account key file (overrides env var) */+ serviceKeyFile?: string;+ /** Project ID for Vertex AI */+ projectId?: string;+ /** Region for Vertex AI */+ region?: string;+}++/**+ * Interface for Vertex AI configuration from YAML config.+ * This matches the TVertexAISchema from librechat-data-provider.+ */+export interface VertexAIConfigInput {+ enabled?: boolean;+ projectId?: string;+ region?: string;+ serviceKeyFile?: string;+ deploymentName?: string;+ models?: string[] | Record<string, boolean | { deploymentName?: string }>;+}++/**+ * Loads Google service account configuration for Vertex AI.+ * Supports both YAML configuration and environment variables.+ * @param options - Optional configuration from YAML or other sources+ */+export async function loadAnthropicVertexCredentials(+ options?: VertexCredentialOptions,+): Promise<AnthropicCredentials> {+ /** Path priority: options > env var > default location */+ const serviceKeyPath =+ options?.serviceKeyFile ||+ process.env.GOOGLE_SERVICE_KEY_FILE ||+ path.join(process.cwd(), 'api', 'data', 'auth.json');++ const serviceKey = await loadServiceKey(serviceKeyPath);++ if (!serviceKey) {+ throw new Error(+ `Google service account not found or could not be loaded from ${serviceKeyPath}`,+ );+ }++ return {+ [AuthKeys.GOOGLE_SERVICE_KEY]: serviceKey,+ };+}++/**+ * Creates Vertex credential options from a Vertex AI configuration object.+ * @param config - The Vertex AI configuration (from YAML config or other sources)+ */+export function getVertexCredentialOptions(config?: VertexAIConfigInput): VertexCredentialOptions {+ return {+ serviceKeyFile: config?.serviceKeyFile,+ projectId: config?.projectId,+ region: config?.region,+ };+}++/**+ * Checks if credentials are for Vertex AI (has service account key but no API key)+ */+export function isAnthropicVertexCredentials(credentials: AnthropicCredentials): boolean {+ return !!credentials[AuthKeys.GOOGLE_SERVICE_KEY] && !credentials[AuthKeys.ANTHROPIC_API_KEY];+}++/**+ * Filters anthropic-beta header values to only include those supported by Vertex AI.+ * Vertex AI rejects prompt-caching-2024-07-31 but we use 'prompt-caching-vertex' as a+ * marker to trigger cache_control application in the agents package.+ */+function filterVertexHeaders(headers?: Record<string, string>): Record<string, string> | undefined {+ if (!headers) {+ return undefined;+ }++ const filteredHeaders = { ...headers };+ const anthropicBeta = filteredHeaders['anthropic-beta'];++ if (anthropicBeta) {+ // Filter out unsupported beta values for Vertex AI+ const supportedValues = anthropicBeta+ .split(',')+ .map((v) => v.trim())+ .filter((v) => {+ // Remove prompt-caching headers (Vertex handles caching via cache_control in body)+ if (v.includes('prompt-caching')) {+ return false;+ }+ // Remove max-tokens headers (Vertex has its own limits)+ if (v.includes('max-tokens')) {+ return false;+ }+ // Remove output-128k headers+ if (v.includes('output-128k')) {+ return false;+ }+ // Remove token-efficient-tools headers+ if (v.includes('token-efficient-tools')) {+ return false;+ }+ // Remove context-1m headers+ if (v.includes('context-1m')) {+ return false;+ }+ return true;+ });++ if (supportedValues.length > 0) {+ filteredHeaders['anthropic-beta'] = supportedValues.join(',');+ } else {+ delete filteredHeaders['anthropic-beta'];+ }+ }++ return Object.keys(filteredHeaders).length > 0 ? filteredHeaders : undefined;+}++/**+ * Gets the deployment name for a given model name from the Vertex AI configuration.+ * Maps visible model names to actual deployment names (model IDs).+ * @param modelName - The visible model name (e.g., "Claude Opus 4.5")+ * @param vertexConfig - The Vertex AI configuration with model mappings+ * @returns The deployment name to use with the API (e.g., "claude-opus-4-5@20251101")+ */+export function getVertexDeploymentName(+ modelName: string,+ vertexConfig?: VertexAIConfigInput,+): string {+ if (!vertexConfig?.models) {+ // No models configuration, return model name as-is+ return modelName;+ }++ // If models is an array, check if modelName is in the array+ if (Array.isArray(vertexConfig.models)) {+ // Legacy format - no deployment mapping+ return modelName;+ }++ // If models is an object, look up the deployment name+ const modelConfig = vertexConfig.models[modelName];++ if (!modelConfig) {+ // Model not found in config, return as-is+ return modelName;+ }++ if (typeof modelConfig === 'boolean') {+ // Model is true/false - use default deployment name or model name+ return vertexConfig.deploymentName || modelName;+ }++ // Model has its own deployment name+ return modelConfig.deploymentName || vertexConfig.deploymentName || modelName;+}++/**+ * Creates and configures a Vertex AI client for Anthropic.+ * Supports both YAML configuration and environment variables for region/projectId.+ * The projectId is automatically extracted from the service key if not explicitly provided.+ * @param credentials - The Google service account credentials+ * @param options - SDK client options+ * @param vertexOptions - Vertex AI specific options (region, projectId) from YAML config+ */+export function createAnthropicVertexClient(+ credentials: AnthropicCredentials,+ options?: ClientOptions,+ vertexOptions?: VertexAIClientOptions,+): AnthropicVertex {+ const serviceKey = credentials[AuthKeys.GOOGLE_SERVICE_KEY];++ if (!serviceKey) {+ throw new Error('Google service account key is required for Vertex AI');+ }++ // Priority: vertexOptions > env vars > service key project_id+ const region = vertexOptions?.region || process.env.ANTHROPIC_VERTEX_REGION || 'us-east5';+ const projectId =+ vertexOptions?.projectId || process.env.VERTEX_PROJECT_ID || serviceKey.project_id;++ try {+ const googleAuth = new GoogleAuth({+ credentials: serviceKey,+ scopes: 'https://www.googleapis.com/auth/cloud-platform',+ ...(projectId && { projectId }),+ });++ // Filter out unsupported anthropic-beta header values for Vertex AI+ const filteredOptions = options+ ? {+ ...options,+ defaultHeaders: filterVertexHeaders(+ options.defaultHeaders as Record<string, string> | undefined,+ ),+ }+ : undefined;++ return new AnthropicVertex({+ region: region,+ googleAuth: googleAuth,+ ...(projectId && { projectId }),+ ...filteredOptions,+ });+ } catch (error) {+ const message = error instanceof Error ? error.message : String(error);+ throw new Error(`Failed to create Vertex AI client: ${message}`);+ }+}diff --git a/packages/api/src/endpoints/models.ts b/packages/api/src/endpoints/models.tsindex 0ca5cb286f..715b806565 100644--- a/packages/api/src/endpoints/models.ts+++ b/packages/api/src/endpoints/models.ts@@ -340,8 +340,16 @@ export async function fetchAnthropicModels(* @param opts - Options for fetching models* @returns Promise resolving to array of model IDs*/-export async function getAnthropicModels(opts: { user?: string } = {}): Promise<string[]> {+export async function getAnthropicModels(+ opts: { user?: string; vertexModels?: string[] } = {},+): Promise<string[]> {const models = defaultModels[EModelEndpoint.anthropic];++ // Vertex AI models from YAML config take priority+ if (opts.vertexModels && opts.vertexModels.length > 0) {+ return opts.vertexModels;+ }+if (process.env.ANTHROPIC_MODELS) {return splitAndTrim(process.env.ANTHROPIC_MODELS);}diff --git a/packages/api/src/types/anthropic.ts b/packages/api/src/types/anthropic.tsindex c57016ebf2..6e9bf7713b 100644--- a/packages/api/src/types/anthropic.ts+++ b/packages/api/src/types/anthropic.ts@@ -1,11 +1,28 @@import { z } from 'zod';import { Dispatcher } from 'undici';-import { anthropicSchema } from 'librechat-data-provider';+import { AuthKeys, anthropicSchema, TVertexAISchema } from 'librechat-data-provider';import type { AnthropicClientOptions } from '@librechat/agents';import type { LLMConfigResult } from './openai';+import type { GoogleServiceKey } from '../utils/key';export type AnthropicParameters = z.infer<typeof anthropicSchema>;+export type AnthropicCredentials = {+ [AuthKeys.GOOGLE_SERVICE_KEY]?: GoogleServiceKey;+ [AuthKeys.ANTHROPIC_API_KEY]?: string;+};++/**+ * Vertex AI client options for configuring the Anthropic Vertex client.+ * These options are typically loaded from the YAML config or environment variables.+ */+export interface VertexAIClientOptions {+ /** Google Cloud region for Vertex AI (e.g., 'us-east5', 'europe-west1') */+ region?: string;+ /** Google Cloud Project ID */+ projectId?: string;+}+export interface ThinkingConfigDisabled {type: 'disabled';}@@ -60,6 +77,10 @@ export interface AnthropicConfigOptions {addParams?: Record<string, unknown>;/** Parameters to drop/exclude from the configuration */dropParams?: string[];+ /** Vertex AI specific options for Google Cloud configuration */+ vertexOptions?: VertexAIClientOptions;+ /** Full Vertex AI configuration including model mappings from YAML config */+ vertexConfig?: TVertexAISchema;}/**diff --git a/packages/data-provider/src/config.ts b/packages/data-provider/src/config.tsindex 1a12507e68..1f6faab9eb 100644--- a/packages/data-provider/src/config.ts+++ b/packages/data-provider/src/config.ts@@ -359,6 +359,67 @@ export const azureEndpointSchema = zexport type TAzureConfig = Omit<z.infer<typeof azureEndpointSchema>, 'groups'> &TAzureConfigValidationResult;+/**+ * Vertex AI model configuration - similar to Azure model config+ * Allows specifying deployment name for each model+ */+export const vertexModelConfigSchema = z+ .object({+ /** The actual model ID/deployment name used by Vertex AI API */+ deploymentName: z.string().optional(),+ })+ .or(z.boolean());++export type TVertexModelConfig = z.infer<typeof vertexModelConfigSchema>;++/**+ * Vertex AI configuration schema for Anthropic models served via Google Cloud Vertex AI.+ * Similar to Azure configuration, this allows running Anthropic models through Google Cloud.+ */+export const vertexAISchema = z.object({+ /** Enable Vertex AI mode for Anthropic (defaults to true when vertex config is present) */+ enabled: z.boolean().optional(),+ /** Google Cloud Project ID (optional - auto-detected from service key file if not provided) */+ projectId: z.string().optional(),+ /** Vertex AI region (e.g., 'us-east5', 'europe-west1') */+ region: z.string().default('us-east5'),+ /** Optional: Path to service account key file */+ serviceKeyFile: z.string().optional(),+ /** Optional: Default deployment name for all models (can be overridden per model) */+ deploymentName: z.string().optional(),+ /** Optional: Available models - can be string array or object with deploymentName mapping */+ models: z.union([z.array(z.string()), z.record(z.string(), vertexModelConfigSchema)]).optional(),+});++export type TVertexAISchema = z.infer<typeof vertexAISchema>;++export type TVertexModelMap = Record<string, string>;++/**+ * Validated Vertex AI configuration result+ */+export type TVertexAIConfig = TVertexAISchema & {+ isValid: boolean;+ errors: string[];+ modelNames?: string[];+ modelDeploymentMap?: TVertexModelMap;+};++/**+ * Anthropic endpoint schema with optional Vertex AI configuration.+ * Extends baseEndpointSchema with Vertex AI support.+ */+export const anthropicEndpointSchema = baseEndpointSchema.merge(+ z.object({+ /** Vertex AI configuration for running Anthropic models on Google Cloud */+ vertex: vertexAISchema.optional(),+ /** Optional: List of available models */+ models: z.array(z.string()).optional(),+ }),+);++export type TAnthropicEndpoint = z.infer<typeof anthropicEndpointSchema>;+const ttsOpenaiSchema = z.object({url: z.string().optional(),apiKey: z.string(),@@ -886,7 +947,7 @@ export const configSchema = z.object({all: baseEndpointSchema.optional(),[EModelEndpoint.openAI]: baseEndpointSchema.optional(),[EModelEndpoint.google]: baseEndpointSchema.optional(),- [EModelEndpoint.anthropic]: baseEndpointSchema.optional(),+ [EModelEndpoint.anthropic]: anthropicEndpointSchema.optional(),[EModelEndpoint.azureOpenAI]: azureEndpointSchema.optional(),[EModelEndpoint.azureAssistants]: assistantEndpointSchema.optional(),[EModelEndpoint.assistants]: assistantEndpointSchema.optional(),@@ -1499,6 +1560,12 @@ export enum AuthKeys {* Note: this is not for Environment Variables, but to access encrypted object values.*/GOOGLE_API_KEY = 'GOOGLE_API_KEY',+ /**+ * API key to use Anthropic.+ *+ * Note: this is not for Environment Variables, but to access encrypted object values.+ */+ ANTHROPIC_API_KEY = 'ANTHROPIC_API_KEY',}/**diff --git a/packages/data-schemas/src/app/endpoints.ts b/packages/data-schemas/src/app/endpoints.tsindex b4bdf2985b..2ad6e07a92 100644--- a/packages/data-schemas/src/app/endpoints.ts+++ b/packages/data-schemas/src/app/endpoints.ts@@ -1,9 +1,10 @@import { EModelEndpoint } from 'librechat-data-provider';-import type { TCustomConfig, TAgentsEndpoint } from 'librechat-data-provider';+import type { TCustomConfig, TAgentsEndpoint, TAnthropicEndpoint } from 'librechat-data-provider';import type { AppConfig } from '~/types';import { azureAssistantsDefaults, assistantsConfigSetup } from './assistants';import { agentsConfigSetup } from './agents';import { azureConfigSetup } from './azure';+import { vertexConfigSetup } from './vertex';/*** Loads custom config endpoints@@ -43,12 +44,26 @@ export const loadEndpoints = (loadedEndpoints[EModelEndpoint.agents] = agentsConfigSetup(config, agentsDefaults);+ // Handle Anthropic endpoint with Vertex AI configuration+ if (endpoints?.[EModelEndpoint.anthropic]) {+ const anthropicConfig = endpoints[EModelEndpoint.anthropic] as TAnthropicEndpoint;+ const vertexConfig = vertexConfigSetup(config);++ loadedEndpoints[EModelEndpoint.anthropic] = {+ ...anthropicConfig,+ // If Vertex AI is enabled, use the visible model names from vertex config+ // Otherwise, use the models array from anthropic config+ ...(vertexConfig?.modelNames && { models: vertexConfig.modelNames }),+ // Attach validated Vertex AI config if present+ ...(vertexConfig && { vertexConfig }),+ };+ }+const endpointKeys = [EModelEndpoint.openAI,EModelEndpoint.google,EModelEndpoint.custom,EModelEndpoint.bedrock,- EModelEndpoint.anthropic,];endpointKeys.forEach((key) => {diff --git a/packages/data-schemas/src/app/index.ts b/packages/data-schemas/src/app/index.tsindex 4912946329..77cb799f8c 100644--- a/packages/data-schemas/src/app/index.ts+++ b/packages/data-schemas/src/app/index.ts@@ -3,4 +3,5 @@ export * from './interface';export * from './service';export * from './specs';export * from './turnstile';+export * from './vertex';export * from './web';diff --git a/packages/data-schemas/src/app/vertex.ts b/packages/data-schemas/src/app/vertex.tsnew file mode 100644index 0000000000..cc5eff7ff5--- /dev/null+++ b/packages/data-schemas/src/app/vertex.ts@@ -0,0 +1,198 @@+import logger from '~/config/winston';+import {+ EModelEndpoint,+ extractEnvVariable,+ envVarRegex,+ TVertexModelMap,+} from 'librechat-data-provider';+import type {+ TCustomConfig,+ TVertexAISchema,+ TVertexAIConfig,+ TAnthropicEndpoint,+ TVertexModelConfig,+} from 'librechat-data-provider';++/**+ * Default Vertex AI models available through Google Cloud+ * These are the standard Anthropic model names as served by Vertex AI+ */+export const defaultVertexModels = [+ 'claude-sonnet-4-20250514',+ 'claude-3-7-sonnet-20250219',+ 'claude-3-5-sonnet-v2@20241022',+ 'claude-3-5-sonnet@20240620',+ 'claude-3-5-haiku@20241022',+ 'claude-3-opus@20240229',+ 'claude-3-haiku@20240307',+];++/**+ * Processes models configuration and creates deployment name mapping+ * Similar to Azure's model mapping logic+ * @param models - The models configuration (can be array or object)+ * @param defaultDeploymentName - Optional default deployment name+ * @returns Object containing modelNames array and modelDeploymentMap+ */+function processVertexModels(+ models: string[] | Record<string, TVertexModelConfig> | undefined,+ defaultDeploymentName?: string,+): { modelNames: string[]; modelDeploymentMap: TVertexModelMap } {+ const modelNames: string[] = [];+ const modelDeploymentMap: TVertexModelMap = {};++ if (!models) {+ // No models specified, use defaults+ for (const model of defaultVertexModels) {+ modelNames.push(model);+ modelDeploymentMap[model] = model; // Default: model name = deployment name+ }+ return { modelNames, modelDeploymentMap };+ }++ if (Array.isArray(models)) {+ // Legacy format: simple array of model names+ for (const modelName of models) {+ modelNames.push(modelName);+ // If a default deployment name is provided, use it for all models+ // Otherwise, model name is the deployment name+ modelDeploymentMap[modelName] = defaultDeploymentName || modelName;+ }+ } else {+ // New format: object with model names as keys and config as values+ for (const [modelName, modelConfig] of Object.entries(models)) {+ modelNames.push(modelName);++ if (typeof modelConfig === 'boolean') {+ // Model is set to true/false - use default deployment name or model name+ modelDeploymentMap[modelName] = defaultDeploymentName || modelName;+ } else if (modelConfig?.deploymentName) {+ // Model has its own deployment name specified+ modelDeploymentMap[modelName] = modelConfig.deploymentName;+ } else {+ // Model is an object but no deployment name - use default or model name+ modelDeploymentMap[modelName] = defaultDeploymentName || modelName;+ }+ }+ }++ return { modelNames, modelDeploymentMap };+}++/**+ * Validates and processes Vertex AI configuration+ * @param vertexConfig - The Vertex AI configuration object+ * @returns Validated configuration with errors if any+ */+export function validateVertexConfig(+ vertexConfig: TVertexAISchema | undefined,+): TVertexAIConfig | null {+ if (!vertexConfig) {+ return null;+ }++ const errors: string[] = [];++ // Extract and validate environment variables+ // projectId is optional - will be auto-detected from service key if not provided+ const projectId = vertexConfig.projectId ? extractEnvVariable(vertexConfig.projectId) : undefined;+ const region = extractEnvVariable(vertexConfig.region || 'us-east5');+ const serviceKeyFile = vertexConfig.serviceKeyFile+ ? extractEnvVariable(vertexConfig.serviceKeyFile)+ : undefined;+ const defaultDeploymentName = vertexConfig.deploymentName+ ? extractEnvVariable(vertexConfig.deploymentName)+ : undefined;++ // Check for unresolved environment variables+ if (projectId && envVarRegex.test(projectId)) {+ errors.push(+ `Vertex AI projectId environment variable "${vertexConfig.projectId}" was not found.`,+ );+ }++ if (envVarRegex.test(region)) {+ errors.push(`Vertex AI region environment variable "${vertexConfig.region}" was not found.`);+ }++ if (serviceKeyFile && envVarRegex.test(serviceKeyFile)) {+ errors.push(+ `Vertex AI serviceKeyFile environment variable "${vertexConfig.serviceKeyFile}" was not found.`,+ );+ }++ if (defaultDeploymentName && envVarRegex.test(defaultDeploymentName)) {+ errors.push(+ `Vertex AI deploymentName environment variable "${vertexConfig.deploymentName}" was not found.`,+ );+ }++ // Process models and create deployment mapping+ const { modelNames, modelDeploymentMap } = processVertexModels(+ vertexConfig.models,+ defaultDeploymentName,+ );++ // Note: projectId is optional - if not provided, it will be auto-detected from the service key file++ const isValid = errors.length === 0;++ return {+ enabled: vertexConfig.enabled !== false,+ projectId,+ region,+ serviceKeyFile,+ deploymentName: defaultDeploymentName,+ models: vertexConfig.models,+ modelNames,+ modelDeploymentMap,+ isValid,+ errors,+ };+}++/**+ * Sets up the Vertex AI configuration from the config (`librechat.yaml`) file.+ * Similar to azureConfigSetup, this processes and validates the Vertex AI configuration.+ * @param config - The loaded custom configuration.+ * @returns The validated Vertex AI configuration or null if not configured.+ */+export function vertexConfigSetup(config: Partial<TCustomConfig>): TVertexAIConfig | null {+ const anthropicConfig = config.endpoints?.[EModelEndpoint.anthropic] as+ | TAnthropicEndpoint+ | undefined;++ if (!anthropicConfig?.vertex) {+ return null;+ }++ const vertexConfig = anthropicConfig.vertex;++ // Skip if explicitly disabled (enabled: false)+ // When vertex config exists, it's enabled by default unless explicitly set to false+ if (vertexConfig.enabled === false) {+ return null;+ }++ const validatedConfig = validateVertexConfig(vertexConfig);++ if (!validatedConfig) {+ return null;+ }++ if (!validatedConfig.isValid) {+ const errorString = validatedConfig.errors.join('\n');+ const errorMessage = 'Invalid Vertex AI configuration:\n' + errorString;+ logger.error(errorMessage);+ throw new Error(errorMessage);+ }++ logger.info('Vertex AI configuration loaded successfully', {+ projectId: validatedConfig.projectId,+ region: validatedConfig.region,+ modelCount: validatedConfig.modelNames?.length || 0,+ models: validatedConfig.modelNames,+ });++ return validatedConfig;+}diff --git a/packages/data-schemas/src/types/app.ts b/packages/data-schemas/src/types/app.tsindex 9157fabd44..36891bfaec 100644--- a/packages/data-schemas/src/types/app.ts+++ b/packages/data-schemas/src/types/app.ts@@ -6,9 +6,11 @@ import type {TCustomConfig,TMemoryConfig,EModelEndpoint,+ TVertexAIConfig,TAgentsEndpoint,TCustomEndpoints,TAssistantEndpoint,+ TAnthropicEndpoint,} from 'librechat-data-provider';export type JsonSchemaType = {@@ -99,8 +101,11 @@ export interface AppConfig {google?: Partial<TEndpoint>;/** Bedrock endpoint configuration */bedrock?: Partial<TEndpoint>;- /** Anthropic endpoint configuration */- anthropic?: Partial<TEndpoint>;+ /** Anthropic endpoint configuration with optional Vertex AI support */+ anthropic?: Partial<TAnthropicEndpoint> & {+ /** Validated Vertex AI configuration */+ vertexConfig?: TVertexAIConfig;+ };/** Azure OpenAI endpoint configuration */azureOpenAI?: TAzureConfig;/** Assistants endpoint configuration */