🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
feat(llm-api-keys): allow configuring GCP location for VertexAI (#7367)
Hassieb Pakzadd43f30a40f42
diff --git a/packages/shared/src/interfaces/customLLMProviderConfigSchemas.ts b/packages/shared/src/interfaces/customLLMProviderConfigSchemas.tsindex 15da41445e..1aacb9537a 100644--- a/packages/shared/src/interfaces/customLLMProviderConfigSchemas.ts+++ b/packages/shared/src/interfaces/customLLMProviderConfigSchemas.ts@@ -11,6 +11,9 @@ export const BedrockCredentialSchema = z.optional();export type BedrockCredential = z.infer<typeof BedrockCredentialSchema>;+export const VertexAIConfigSchema = z.object({ location: z.string() });+export type VertexAIConfig = z.infer<typeof VertexAIConfigSchema>;+export const GCPServiceAccountKeySchema = z.object({type: z.literal("service_account"),project_id: z.string(),diff --git a/packages/shared/src/server/llm/fetchLLMCompletion.ts b/packages/shared/src/server/llm/fetchLLMCompletion.tsindex 4adf8bacf9..b48de17a71 100644--- a/packages/shared/src/server/llm/fetchLLMCompletion.ts+++ b/packages/shared/src/server/llm/fetchLLMCompletion.ts@@ -20,6 +20,7 @@ import { ChatOpenAI, AzureChatOpenAI } from "@langchain/openai";import GCPServiceAccountKeySchema, {BedrockConfigSchema,BedrockCredentialSchema,+ VertexAIConfigSchema,} from "../../interfaces/customLLMProviderConfigSchemas";import { processEventBatch } from "../ingestion/processEventBatch";import { logger } from "../logger";@@ -251,6 +252,9 @@ export async function fetchLLMCompletion(});} else if (modelParams.adapter === LLMAdapter.VertexAI) {const credentials = GCPServiceAccountKeySchema.parse(JSON.parse(apiKey));+ const { location } = config+ ? VertexAIConfigSchema.parse(config)+ : { location: undefined };// Requests time out after 60 seconds for both public and private endpoints by default// Reference: https://cloud.google.com/vertex-ai/docs/predictions/get-online-predictions#send-request@@ -261,6 +265,7 @@ export async function fetchLLMCompletion(topP: modelParams.top_p,callbacks: finalCallbacks,maxRetries,+ location,authOptions: {projectId: credentials.project_id,credentials,diff --git a/packages/shared/src/server/llm/types.ts b/packages/shared/src/server/llm/types.tsindex 5fa355595e..f5491e45d6 100644--- a/packages/shared/src/server/llm/types.ts+++ b/packages/shared/src/server/llm/types.ts@@ -1,6 +1,9 @@import { LlmApiKeys } from "@prisma/client";import z from "zod/v4";-import { BedrockConfigSchema } from "../../interfaces/customLLMProviderConfigSchemas";+import {+ BedrockConfigSchema,+ VertexAIConfigSchema,+} from "../../interfaces/customLLMProviderConfigSchemas";import { TokenCountDelegate } from "../ingestion/processEventBatch";import { AuthHeaderValidVerificationResult } from "../auth/types";@@ -319,10 +322,10 @@ export const anthropicModels = [// WARNING: The first entry in the array is chosen as the default model to add LLM API keysexport const vertexAIModels = [+ "gemini-2.0-flash","gemini-2.5-pro-preview-05-06","gemini-2.5-flash-preview-05-20","gemini-2.0-pro-exp-02-05",- "gemini-2.0-flash","gemini-2.0-flash-001","gemini-2.0-flash-lite-preview-02-05","gemini-2.0-flash-exp",@@ -379,7 +382,7 @@ export const LLMApiKeySchema = zbaseURL: z.string().nullable(),customModels: z.array(z.string()),withDefaultModels: z.boolean(),- config: BedrockConfigSchema.nullish(), // currently only Bedrock has additional config+ config: z.union([BedrockConfigSchema, VertexAIConfigSchema]).nullish(), // Bedrock and VertexAI have additional config})// strict mode to prevent extra keys. Thorws error otherwise// https://github.com/colinhacks/zod?tab=readme-ov-file#strictdiff --git a/web/src/features/llm-api-key/server/router.ts b/web/src/features/llm-api-key/server/router.tsindex 6d1d350c7f..019caf08e0 100644--- a/web/src/features/llm-api-key/server/router.ts+++ b/web/src/features/llm-api-key/server/router.ts@@ -17,6 +17,7 @@ import {supportedModels,GCPServiceAccountKeySchema,BedrockConfigSchema,+ VertexAIConfigSchema,} from "@langfuse/shared";import { encrypt, decrypt } from "@langfuse/shared/encryption";import {@@ -80,6 +81,11 @@ async function testLLMConnection(if (params.config && params.adapter === LLMAdapter.Bedrock) {const bedrockConfig = BedrockConfigSchema.parse(params.config);parsedConfig = { region: bedrockConfig.region };+ } else if (params.config && params.adapter === LLMAdapter.VertexAI) {+ const vertexAIConfig = VertexAIConfigSchema.parse(params.config);+ parsedConfig = vertexAIConfig.location+ ? { location: vertexAIConfig.location }+ : null;}await fetchLLMCompletion({diff --git a/web/src/features/llm-api-key/types.ts b/web/src/features/llm-api-key/types.tsindex 4f38eb8cbc..7fcc410ab1 100644--- a/web/src/features/llm-api-key/types.ts+++ b/web/src/features/llm-api-key/types.ts@@ -1,5 +1,9 @@import { z } from "zod/v4";-import { LLMAdapter, BedrockConfigSchema } from "@langfuse/shared";+import {+ LLMAdapter,+ BedrockConfigSchema,+ VertexAIConfigSchema,+} from "@langfuse/shared";export const LlmApiKeySchema = z.object({projectId: z.string(),@@ -8,7 +12,7 @@ export const LlmApiKeySchema = z.object({baseURL: z.string().url().optional(),withDefaultModels: z.boolean().optional(),customModels: z.array(z.string().min(1)).optional(),- config: BedrockConfigSchema.optional(),+ config: z.union([VertexAIConfigSchema, BedrockConfigSchema]).optional(),extraHeaders: z.record(z.string(), z.string()).optional(),});diff --git a/web/src/features/public-api/components/CreateLLMApiKeyForm.tsx b/web/src/features/public-api/components/CreateLLMApiKeyForm.tsxindex 425b5c5df8..dad577ff63 100644--- a/web/src/features/public-api/components/CreateLLMApiKeyForm.tsx+++ b/web/src/features/public-api/components/CreateLLMApiKeyForm.tsx@@ -3,6 +3,7 @@ import { zodResolver } from "@hookform/resolvers/zod";import {type BedrockConfig,type BedrockCredential,+ type VertexAIConfig,LLMAdapter,type LlmApiKeys,} from "@langfuse/shared";@@ -50,6 +51,7 @@ const createFormSchema = (mode: "create" | "update") =>awsAccessKeyId: z.string().optional(),awsSecretAccessKey: z.string().optional(),awsRegion: z.string().optional(),+ vertexAILocation: z.string().optional(),extraHeaders: z.array(z.object({key: z.string().min(1),@@ -155,6 +157,10 @@ export function CreateLLMApiKeyForm({extraHeaders:existingKey.extraHeaderKeys?.map((key) => ({ key, value: "" })) ??[],+ vertexAILocation:+ existingKey.adapter === LLMAdapter.VertexAI && existingKey.config+ ? ((existingKey.config as VertexAIConfig).location ?? "")+ : "",}: {adapter: defaultAdapter,@@ -164,6 +170,7 @@ export function CreateLLMApiKeyForm({withDefaultModels: true,customModels: [],extraHeaders: [],+ vertexAILocation: "",},});@@ -214,7 +221,7 @@ export function CreateLLMApiKeyForm({}let secretKey = values.secretKey;- let config: BedrockConfig | undefined;+ let config: BedrockConfig | VertexAIConfig | undefined;if (currentAdapter === LLMAdapter.Bedrock) {const credentials: BedrockCredential = {@@ -226,6 +233,13 @@ export function CreateLLMApiKeyForm({config = {region: values.awsRegion ?? "",};+ } else if (+ currentAdapter === LLMAdapter.VertexAI &&+ values.vertexAILocation+ ) {+ config = {+ location: values.vertexAILocation.trim(),+ };}const extraHeaders =@@ -490,6 +504,28 @@ export function CreateLLMApiKeyForm({/>)}+ {/* VertexAI Location */}+ {currentAdapter === LLMAdapter.VertexAI && (+ <FormField+ control={form.control}+ name="vertexAILocation"+ render={({ field }) => (+ <FormItem>+ <FormLabel>Location (Optional)</FormLabel>+ <FormDescription>+ Specify the Google Cloud location for Vertex AI. If not+ specified, the default location will be used (us-central1).+ Examples: us-central1, europe-west4, asia-northeast1+ </FormDescription>+ <FormControl>+ <Input {...field} placeholder="e.g., us-central1" />+ </FormControl>+ <FormMessage />+ </FormItem>+ )}+ />+ )}+{/* Extra Headers */}{currentAdapter === LLMAdapter.OpenAI ||currentAdapter === LLMAdapter.Azure ? (