Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

feat(llm-connections-api): allow setting config for Bedrock and VertexAI (#10823)

Hassieb Pakzadcb1627732892
diff --git a/fern/apis/server/definition/llm-connections.yml b/fern/apis/server/definition/llm-connections.yml
index b74a4df22b..17746e27ca 100644
--- a/fern/apis/server/definition/llm-connections.yml
+++ b/fern/apis/server/definition/llm-connections.yml
@@ -53,6 +53,9 @@ types:
extraHeaderKeys:
type: list<string>
docs: Keys of extra headers sent with requests (values excluded for security)
+ config:
+ type: optional<map<string, unknown>>
+ docs: Adapter-specific configuration. Required for Bedrock (`{"region":"us-east-1"}`), optional for VertexAI (`{"location":"us-central1"}`), not used by other adapters.
createdAt: datetime
updatedAt: datetime
@@ -85,6 +88,13 @@ types:
extraHeaders:
type: optional<map<string, string>>
docs: Extra headers to send with requests
+ config:
+ type: optional<map<string, unknown>>
+ docs: >
+ Adapter-specific configuration. Validation rules:
+ - **Bedrock**: Required. Must be `{"region": "<aws-region>"}` (e.g., `{"region":"us-east-1"}`)
+ - **VertexAI**: Optional. If provided, must be `{"location": "<gcp-location>"}` (e.g., `{"location":"us-central1"}`)
+ - **Other adapters**: Not supported. Omit this field or set to null.
LlmAdapter:
enum:
diff --git a/web/src/__tests__/async/llm-connections-api.servertest.ts b/web/src/__tests__/async/llm-connections-api.servertest.ts
index 49abafa371..7ed62d51c2 100644
--- a/web/src/__tests__/async/llm-connections-api.servertest.ts
+++ b/web/src/__tests__/async/llm-connections-api.servertest.ts
@@ -125,10 +125,12 @@ describe("/api/public/llm-connections API Endpoints", () => {
// Ensure no sensitive data is exposed
expect(firstConnection).not.toHaveProperty("secretKey");
expect(firstConnection).not.toHaveProperty("extraHeaders");
- expect(firstConnection).not.toHaveProperty("config");
expect(secondConnection).not.toHaveProperty("secretKey");
expect(secondConnection).not.toHaveProperty("extraHeaders");
- expect(secondConnection).not.toHaveProperty("config");
+
+ // Config is now a valid field (null for connections without config)
+ expect(firstConnection.config).toBeNull();
+ expect(secondConnection.config).toBeNull();
});
it("should handle pagination correctly", async () => {
@@ -310,7 +312,9 @@ describe("/api/public/llm-connections API Endpoints", () => {
// Ensure no sensitive data is exposed
expect(response.body).not.toHaveProperty("secretKey");
expect(response.body).not.toHaveProperty("extraHeaders");
- expect(response.body).not.toHaveProperty("config");
+
+ // Config should be null for adapters that don't use it
+ expect(response.body.config).toBeNull();
// Verify database record was created
const dbConnection = await prisma.llmApiKeys.findUnique({
@@ -493,7 +497,8 @@ describe("/api/public/llm-connections API Endpoints", () => {
});
it("should handle all LLM adapter types", async () => {
- const adapters = [
+ // Adapters that don't require config
+ const adaptersWithoutConfig = [
{
adapter: LLMAdapter.OpenAI,
provider: generateUniqueProvider("test-openai"),
@@ -506,21 +511,13 @@ describe("/api/public/llm-connections API Endpoints", () => {
adapter: LLMAdapter.Azure,
provider: generateUniqueProvider("test-azure"),
},
- {
- adapter: LLMAdapter.Bedrock,
- provider: generateUniqueProvider("test-bedrock"),
- },
- {
- adapter: LLMAdapter.VertexAI,
- provider: generateUniqueProvider("test-vertex"),
- },
{
adapter: LLMAdapter.GoogleAIStudio,
provider: generateUniqueProvider("test-studio"),
},
];
- for (const { adapter, provider } of adapters) {
+ for (const { adapter, provider } of adaptersWithoutConfig) {
const response = await makeZodVerifiedAPICall(
PutLlmConnectionV1Response,
"PUT",
@@ -537,7 +534,60 @@ describe("/api/public/llm-connections API Endpoints", () => {
expect(response.status).toBe(201);
expect(response.body.adapter).toBe(adapter);
expect(response.body.provider).toBe(provider);
+ expect(response.body.config).toBeNull();
}
+
+ // Bedrock requires config with region
+ const bedrockResponse = await makeZodVerifiedAPICall(
+ PutLlmConnectionV1Response,
+ "PUT",
+ "/api/public/llm-connections",
+ {
+ provider: generateUniqueProvider("test-bedrock"),
+ adapter: LLMAdapter.Bedrock,
+ secretKey: JSON.stringify({
+ accessKeyId: "AKIAIOSFODNN7EXAMPLE",
+ secretAccessKey: "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
+ }),
+ config: { region: "us-east-1" },
+ },
+ auth,
+ 201,
+ );
+ expect(bedrockResponse.status).toBe(201);
+ expect(bedrockResponse.body.adapter).toBe(LLMAdapter.Bedrock);
+ expect(bedrockResponse.body.config).toEqual({ region: "us-east-1" });
+
+ // VertexAI works with or without config
+ const vertexResponse = await makeZodVerifiedAPICall(
+ PutLlmConnectionV1Response,
+ "PUT",
+ "/api/public/llm-connections",
+ {
+ provider: generateUniqueProvider("test-vertex"),
+ adapter: LLMAdapter.VertexAI,
+ secretKey: JSON.stringify({
+ type: "service_account",
+ project_id: "test-project",
+ private_key_id: "key123",
+ private_key:
+ "-----BEGIN PRIVATE KEY-----\ntest\n-----END PRIVATE KEY-----",
+ client_email: "[email protected]",
+ client_id: "123456789",
+ auth_uri: "https://accounts.google.com/o/oauth2/auth",
+ token_uri: "https://oauth2.googleapis.com/token",
+ auth_provider_x509_cert_url:
+ "https://www.googleapis.com/oauth2/v1/certs",
+ client_x509_cert_url:
+ "https://www.googleapis.com/robot/v1/metadata/x509/test",
+ }),
+ },
+ auth,
+ 201,
+ );
+ expect(vertexResponse.status).toBe(201);
+ expect(vertexResponse.body.adapter).toBe(LLMAdapter.VertexAI);
+ expect(vertexResponse.body.config).toBeNull();
});
it("should handle optional fields correctly", async () => {
@@ -795,6 +845,304 @@ describe("/api/public/llm-connections API Endpoints", () => {
// Ensure header values are not exposed
expect(response.body).not.toHaveProperty("extraHeaders");
});
+
+ describe("Config validation", () => {
+ it("should create Bedrock connection with region config", async () => {
+ const createData = {
+ provider: generateUniqueProvider("bedrock-config-test"),
+ adapter: LLMAdapter.Bedrock,
+ secretKey: JSON.stringify({
+ accessKeyId: "AKIAIOSFODNN7EXAMPLE",
+ secretAccessKey: "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
+ }),
+ config: {
+ region: "us-east-1",
+ },
+ };
+
+ const response = await makeZodVerifiedAPICall(
+ PutLlmConnectionV1Response,
+ "PUT",
+ "/api/public/llm-connections",
+ createData,
+ auth,
+ 201,
+ );
+
+ expect(response.status).toBe(201);
+ expect(response.body.adapter).toBe(LLMAdapter.Bedrock);
+ expect(response.body.config).toEqual({ region: "us-east-1" });
+
+ // Verify database persistence
+ const dbConnection = await prisma.llmApiKeys.findUnique({
+ where: {
+ projectId_provider: {
+ projectId,
+ provider: createData.provider,
+ },
+ },
+ });
+ expect(dbConnection?.config).toEqual({ region: "us-east-1" });
+ });
+
+ it("should reject Bedrock connection without config", async () => {
+ const createData = {
+ provider: generateUniqueProvider("bedrock-no-config"),
+ adapter: LLMAdapter.Bedrock,
+ secretKey: JSON.stringify({
+ accessKeyId: "AKIAIOSFODNN7EXAMPLE",
+ secretAccessKey: "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
+ }),
+ // No config provided
+ };
+
+ const response = await makeAPICall(
+ "PUT",
+ "/api/public/llm-connections",
+ createData,
+ auth,
+ );
+
+ expect(response.status).toBe(400);
+ expect(JSON.stringify(response.body)).toContain(
+ "Config is required for Bedrock adapter",
+ );
+ });
+
+ it("should reject Bedrock connection with invalid config", async () => {
+ const createData = {
+ provider: generateUniqueProvider("bedrock-bad-config"),
+ adapter: LLMAdapter.Bedrock,
+ secretKey: JSON.stringify({
+ accessKeyId: "AKIAIOSFODNN7EXAMPLE",
+ secretAccessKey: "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
+ }),
+ config: {
+ location: "us-central1", // Wrong key - should be 'region'
+ },
+ };
+
+ const response = await makeAPICall(
+ "PUT",
+ "/api/public/llm-connections",
+ createData,
+ auth,
+ );
+
+ expect(response.status).toBe(400);
+ expect(JSON.stringify(response.body)).toContain(
+ "Invalid Bedrock config",
+ );
+ });
+
+ it("should create VertexAI connection with location config", async () => {
+ const createData = {
+ provider: generateUniqueProvider("vertexai-config-test"),
+ adapter: LLMAdapter.VertexAI,
+ secretKey: JSON.stringify({
+ type: "service_account",
+ project_id: "test-project",
+ private_key_id: "key123",
+ private_key:
+ "-----BEGIN PRIVATE KEY-----\ntest\n-----END PRIVATE KEY-----",
+ client_email: "[email protected]",
+ client_id: "123456789",
+ auth_uri: "https://accounts.google.com/o/oauth2/auth",
+ token_uri: "https://oauth2.googleapis.com/token",
+ auth_provider_x509_cert_url:
+ "https://www.googleapis.com/oauth2/v1/certs",
+ client_x509_cert_url:
+ "https://www.googleapis.com/robot/v1/metadata/x509/test",
+ }),
+ config: {
+ location: "us-central1",
+ },
+ };
+
+ const response = await makeZodVerifiedAPICall(
+ PutLlmConnectionV1Response,
+ "PUT",
+ "/api/public/llm-connections",
+ createData,
+ auth,
+ 201,
+ );
+
+ expect(response.status).toBe(201);
+ expect(response.body.config).toEqual({ location: "us-central1" });
+ });
+
+ it("should create VertexAI connection without config", async () => {
+ const createData = {
+ provider: generateUniqueProvider("vertexai-no-config"),
+ adapter: LLMAdapter.VertexAI,
+ secretKey: JSON.stringify({
+ type: "service_account",
+ project_id: "test-project",
+ private_key_id: "key123",
+ private_key:
+ "-----BEGIN PRIVATE KEY-----\ntest\n-----END PRIVATE KEY-----",
+ client_email: "[email protected]",
+ client_id: "123456789",
+ auth_uri: "https://accounts.google.com/o/oauth2/auth",
+ token_uri: "https://oauth2.googleapis.com/token",
+ auth_provider_x509_cert_url:
+ "https://www.googleapis.com/oauth2/v1/certs",
+ client_x509_cert_url:
+ "https://www.googleapis.com/robot/v1/metadata/x509/test",
+ }),
+ // No config - allowed for VertexAI
+ };
+
+ const response = await makeZodVerifiedAPICall(
+ PutLlmConnectionV1Response,
+ "PUT",
+ "/api/public/llm-connections",
+ createData,
+ auth,
+ 201,
+ );
+
+ expect(response.status).toBe(201);
+ expect(response.body.config).toBeNull();
+ });
+
+ it("should reject OpenAI connection with config", async () => {
+ const createData = {
+ provider: generateUniqueProvider("openai-with-config"),
+ adapter: LLMAdapter.OpenAI,
+ secretKey: "sk-test123",
+ config: {
+ region: "us-east-1", // OpenAI doesn't support config
+ },
+ };
+
+ const response = await makeAPICall(
+ "PUT",
+ "/api/public/llm-connections",
+ createData,
+ auth,
+ );
+
+ expect(response.status).toBe(400);
+ expect(JSON.stringify(response.body)).toContain(
+ "Config is not supported for openai adapter",
+ );
+ });
+
+ it("should update existing Bedrock connection config", async () => {
+ const provider = generateUniqueProvider("bedrock-update-config");
+
+ // Create with initial config
+ await makeZodVerifiedAPICall(
+ PutLlmConnectionV1Response,
+ "PUT",
+ "/api/public/llm-connections",
+ {
+ provider,
+ adapter: LLMAdapter.Bedrock,
+ secretKey: JSON.stringify({
+ accessKeyId: "AKIAIOSFODNN7EXAMPLE",
+ secretAccessKey: "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
+ }),
+ config: { region: "us-east-1" },
+ },
+ auth,
+ 201,
+ );
+
+ // Update config
+ const updateResponse = await makeZodVerifiedAPICall(
+ PutLlmConnectionV1Response,
+ "PUT",
+ "/api/public/llm-connections",
+ {
+ provider,
+ adapter: LLMAdapter.Bedrock,
+ secretKey: JSON.stringify({
+ accessKeyId: "AKIAIOSFODNN7EXAMPLE",
+ secretAccessKey: "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
+ }),
+ config: { region: "eu-west-1" },
+ },
+ auth,
+ 200,
+ );
+
+ expect(updateResponse.status).toBe(200);
+ expect(updateResponse.body.config).toEqual({ region: "eu-west-1" });
+ });
+
+ it("should return config in GET response", async () => {
+ const provider = generateUniqueProvider("bedrock-get-config");
+
+ await prisma.llmApiKeys.create({
+ data: {
+ projectId,
+ provider,
+ adapter: LLMAdapter.Bedrock,
+ secretKey: encrypt(
+ JSON.stringify({
+ accessKeyId: "AKIAIOSFODNN7EXAMPLE",
+ secretAccessKey: "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY",
+ }),
+ ),
+ displaySecretKey: "...KEY",
+ config: { region: "ap-southeast-1" },
+ },
+ });
+
+ const response = await makeZodVerifiedAPICall(
+ GetLlmConnectionsV1Response,
+ "GET",
+ "/api/public/llm-connections?page=1&limit=10",
+ undefined,
+ auth,
+ );
+
+ const connection = response.body.data.find(
+ (c) => c.provider === provider,
+ );
+ expect(connection?.config).toEqual({ region: "ap-southeast-1" });
+ });
+
+ it("should reject VertexAI connection with invalid config", async () => {
+ const createData = {
+ provider: generateUniqueProvider("vertexai-bad-config"),
+ adapter: LLMAdapter.VertexAI,
+ secretKey: JSON.stringify({
+ type: "service_account",
+ project_id: "test-project",
+ private_key_id: "key123",
+ private_key:
+ "-----BEGIN PRIVATE KEY-----\ntest\n-----END PRIVATE KEY-----",
+ client_email: "[email protected]",
+ client_id: "123456789",
+ auth_uri: "https://accounts.google.com/o/oauth2/auth",
+ token_uri: "https://oauth2.googleapis.com/token",
+ auth_provider_x509_cert_url:
+ "https://www.googleapis.com/oauth2/v1/certs",
+ client_x509_cert_url:
+ "https://www.googleapis.com/robot/v1/metadata/x509/test",
+ }),
+ config: {
+ region: "us-east-1", // Wrong key - should be 'location'
+ },
+ };
+
+ const response = await makeAPICall(
+ "PUT",
+ "/api/public/llm-connections",
+ createData,
+ auth,
+ );
+
+ expect(response.status).toBe(400);
+ expect(JSON.stringify(response.body)).toContain(
+ "Invalid VertexAI config",
+ );
+ });
+ });
});
describe("Authorization", () => {
diff --git a/web/src/features/public-api/types/llm-connections.ts b/web/src/features/public-api/types/llm-connections.ts
index c2cea1aab4..7fbc4ac5ea 100644
--- a/web/src/features/public-api/types/llm-connections.ts
+++ b/web/src/features/public-api/types/llm-connections.ts
@@ -1,5 +1,6 @@
import { z } from "zod/v4";
-import { paginationZod, LLMAdapter } from "@langfuse/shared";
+import { paginationZod, LLMAdapter, type JSONValue } from "@langfuse/shared";
+import { BedrockConfigSchema, VertexAIConfigSchema } from "@langfuse/shared";
// Base LLM connection response schema - strict to prevent secret leakage
export const LlmConnectionResponse = z
@@ -12,6 +13,7 @@ export const LlmConnectionResponse = z
customModels: z.array(z.string()),
withDefaultModels: z.boolean(),
extraHeaderKeys: z.array(z.string()),
+ config: z.record(z.string(), z.unknown()).nullable(),
createdAt: z.coerce.date(),
updatedAt: z.coerce.date(),
})
@@ -37,18 +39,66 @@ export const GetLlmConnectionsV1Response = z
})
.strict();
-// PUT /api/public/llm-connections request body (upsert)
-export const PutLlmConnectionV1Body = z
- .object({
- provider: z.string().min(1),
- adapter: z.nativeEnum(LLMAdapter),
- secretKey: z.string().min(1),
- baseURL: z.string().url().nullable().optional(),
- customModels: z.array(z.string().min(1)).optional(),
- withDefaultModels: z.boolean().optional().default(true),
- extraHeaders: z.record(z.string(), z.string()).optional(),
- })
- .strict();
+// Base request schema (before adapter-specific validation)
+const PutLlmConnectionV1BodyBase = z.object({
+ provider: z.string().min(1),
+ adapter: z.nativeEnum(LLMAdapter),
+ secretKey: z.string().min(1),
+ baseURL: z.string().url().nullable().optional(),
+ customModels: z.array(z.string().min(1)).optional(),
+ withDefaultModels: z.boolean().optional().default(true),
+ extraHeaders: z.record(z.string(), z.string()).optional(),
+ config: z.record(z.string(), z.string()).optional(),
+});
+
+// PUT /api/public/llm-connections request body (upsert) with adapter-specific validation
+export const PutLlmConnectionV1Body = PutLlmConnectionV1BodyBase.superRefine(
+ (data, ctx) => {
+ const { adapter, config } = data;
+
+ if (adapter === LLMAdapter.Bedrock) {
+ // Bedrock requires config with region
+ if (!config) {
+ ctx.addIssue({
+ code: z.ZodIssueCode.custom,
+ message:
+ "Config is required for Bedrock adapter. Expected: { region: string }",
+ path: ["config"],
+ });
+ return;
+ }
+ const result = BedrockConfigSchema.safeParse(config);
+ if (!result.success) {
+ ctx.addIssue({
+ code: z.ZodIssueCode.custom,
+ message: `Invalid Bedrock config: ${result.error.issues.map((e) => e.message).join(", ")}. Expected: { region: string }`,
+ path: ["config"],
+ });
+ }
+ } else if (adapter === LLMAdapter.VertexAI) {
+ // VertexAI config is optional, but if provided must be valid
+ if (config) {
+ const result = VertexAIConfigSchema.safeParse(config);
+ if (!result.success) {
+ ctx.addIssue({
+ code: z.ZodIssueCode.custom,
+ message: `Invalid VertexAI config: ${result.error.issues.map((e) => e.message).join(", ")}. Expected: { location: string }`,
+ path: ["config"],
+ });
+ }
+ }
+ } else {
+ // Other adapters should not have config
+ if (config && Object.keys(config).length > 0) {
+ ctx.addIssue({
+ code: z.ZodIssueCode.custom,
+ message: `Config is not supported for ${adapter} adapter. Remove the config field.`,
+ path: ["config"],
+ });
+ }
+ }
+ },
+);
// PUT /api/public/llm-connections response
export const PutLlmConnectionV1Response = LlmConnectionResponse.strict();
@@ -63,6 +113,7 @@ export function transformDbLlmConnectionToAPI(dbConnection: {
customModels: string[];
withDefaultModels: boolean;
extraHeaderKeys: string[];
+ config: JSONValue | null;
createdAt: Date;
updatedAt: Date;
}): z.infer<typeof LlmConnectionResponse> {
@@ -75,6 +126,7 @@ export function transformDbLlmConnectionToAPI(dbConnection: {
customModels: dbConnection.customModels,
withDefaultModels: dbConnection.withDefaultModels,
extraHeaderKeys: dbConnection.extraHeaderKeys,
+ config: dbConnection.config,
createdAt: dbConnection.createdAt,
updatedAt: dbConnection.updatedAt,
});
diff --git a/web/src/pages/api/public/llm-connections/index.ts b/web/src/pages/api/public/llm-connections/index.ts
index 9b34cf602a..78572f9127 100644
--- a/web/src/pages/api/public/llm-connections/index.ts
+++ b/web/src/pages/api/public/llm-connections/index.ts
@@ -32,9 +32,10 @@ export default withMiddlewares({
customModels: true,
withDefaultModels: true,
extraHeaderKeys: true,
+ config: true,
createdAt: true,
updatedAt: true,
- // Explicitly exclude: secretKey, extraHeaders, config
+ // Explicitly exclude: secretKey, extraHeaders
},
where: {
projectId: auth.scope.projectId,
@@ -102,6 +103,7 @@ export default withMiddlewares({
extraHeaderKeys: body.extraHeaders
? Object.keys(body.extraHeaders)
: [],
+ config: body.config,
};
// Perform upsert
@@ -127,9 +129,10 @@ export default withMiddlewares({
customModels: true,
withDefaultModels: true,
extraHeaderKeys: true,
+ config: true,
createdAt: true,
updatedAt: true,
- // Explicitly exclude: secretKey, extraHeaders, config
+ // Explicitly exclude: secretKey, extraHeaders
},
});