🪢 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(settings): improve UX for managing LLM connections (#8312)
Leo Weigand90dca15d8603
diff --git a/web/src/features/public-api/components/CreateLLMApiKeyDialog.tsx b/web/src/features/public-api/components/CreateLLMApiKeyDialog.tsxindex c35a6399c3..a39e3ed991 100644--- a/web/src/features/public-api/components/CreateLLMApiKeyDialog.tsx+++ b/web/src/features/public-api/components/CreateLLMApiKeyDialog.tsx@@ -35,12 +35,12 @@ export function CreateLLMApiKeyDialog() {<DialogTrigger asChild><Button variant="secondary"><PlusIcon className="-ml-0.5 mr-1.5 h-5 w-5" aria-hidden="true" />- Add new LLM API key+ Add LLM Connection</Button></DialogTrigger><DialogContent className="max-h-[90%] min-w-[40vw] overflow-auto"><DialogHeader>- <DialogTitle>Add new LLM API key</DialogTitle>+ <DialogTitle>New LLM Connection</DialogTitle></DialogHeader>{open && (<CreateLLMApiKeyFormdiff --git a/web/src/features/public-api/components/CreateLLMApiKeyForm.tsx b/web/src/features/public-api/components/CreateLLMApiKeyForm.tsxindex 18db195a4e..3ca3f8692c 100644--- a/web/src/features/public-api/components/CreateLLMApiKeyForm.tsx+++ b/web/src/features/public-api/components/CreateLLMApiKeyForm.tsx@@ -1,4 +1,5 @@import { useFieldArray, useForm } from "react-hook-form";+import { useState } from "react";import { zodResolver } from "@hookform/resolvers/zod";import {type BedrockConfig,@@ -8,7 +9,7 @@ import {type LlmApiKeys,BEDROCK_USE_DEFAULT_CREDENTIALS,} from "@langfuse/shared";-import { PlusIcon, TrashIcon } from "lucide-react";+import { ChevronDown, PlusIcon, TrashIcon } from "lucide-react";import { z } from "zod/v4";import { Button } from "@/src/components/ui/button";import {@@ -21,7 +22,6 @@ import {FormMessage,} from "@/src/components/ui/form";import { Input } from "@/src/components/ui/input";-import { PasswordInput } from "@/src/components/ui/password-input";import {Select,SelectContent,@@ -48,7 +48,7 @@ const createFormSchema = (mode: "create" | "update") =>.string().min(1, "Please add a provider name that identifies this connection."),adapter: z.nativeEnum(LLMAdapter),- baseURL: z.union([z.literal(""), z.string().url()]),+ baseURL: z.union([z.literal(""), z.url()]),withDefaultModels: z.boolean(),customModels: z.array(z.object({ value: z.string().min(1) })),awsAccessKeyId: z.string().optional(),@@ -97,6 +97,16 @@ const createFormSchema = (mode: "create" | "update") =>message: "Secret key is required.",path: ["secretKey"],},+ )+ .refine(+ (data) => {+ if (data.adapter !== LLMAdapter.Azure) return true;+ return data.baseURL && data.baseURL.trim() !== "";+ },+ {+ message: "API Base URL is required for Azure connections.",+ path: ["baseURL"],+ },);interface CreateLLMApiKeyFormProps {@@ -114,6 +124,7 @@ export function CreateLLMApiKeyForm({mode = "create",existingKey,}: CreateLLMApiKeyFormProps) {+ const [showAdvancedSettings, setShowAdvancedSettings] = useState(false);const utils = api.useUtils();const capture = usePostHogClientCapture();@@ -383,45 +394,7 @@ export function CreateLLMApiKeyForm({)}/>- {/* baseURL */}- {currentAdapter !== LLMAdapter.Bedrock && (- <FormField- control={form.control}- name="baseURL"- render={({ field }) => (- <FormItem>- <FormLabel>API Base URL</FormLabel>- <FormDescription>- Leave blank to use the default base URL for the given LLM- adapter.{" "}- {currentAdapter === LLMAdapter.OpenAI && (- <span>OpenAI default: https://api.openai.com/v1</span>- )}- {currentAdapter === LLMAdapter.Azure && (- <span>- Please add the base URL in the following format (or- compatible API):- https://{instanceName}.openai.azure.com/openai/deployments- </span>- )}- {currentAdapter === LLMAdapter.Anthropic && (- <span>- Anthropic default: https://api.anthropic.com (excluding- /v1/messages)- </span>- )}- </FormDescription>-- <FormControl>- <Input {...field} placeholder="default" />- </FormControl>-- <FormMessage />- </FormItem>- )}- />- )}-+ {/* API Key or AWS Credentials */}{currentAdapter === LLMAdapter.Bedrock ? (<><FormField@@ -431,7 +404,7 @@ export function CreateLLMApiKeyForm({<FormItem><FormLabel>AWS Region</FormLabel><FormControl>- <Input {...field} />+ <Input {...field} data-1p-ignore /></FormControl><FormMessage /></FormItem>@@ -457,7 +430,7 @@ export function CreateLLMApiKeyForm({: "For self-hosted deployments, AWS credentials are optional. When omitted, authentication will use the AWS SDK default credential provider chain."}</FormDescription><FormControl>- <Input {...field} />+ <Input {...field} data-1p-ignore /></FormControl><FormMessage /></FormItem>@@ -478,7 +451,7 @@ export function CreateLLMApiKeyForm({)}</FormLabel><FormControl>- <PasswordInput {...field} />+ <Input {...field} data-1p-ignore /></FormControl><FormMessage /></FormItem>@@ -547,13 +520,16 @@ export function CreateLLMApiKeyForm({</FormDescription>)}<FormControl>- <PasswordInput+ <Input{...field}placeholder={mode === "update"? existingKey?.displaySecretKey: undefined}+ autoComplete="off"+ spellCheck="false"+ autoCapitalize="off"/></FormControl><FormMessage />@@ -562,21 +538,24 @@ export function CreateLLMApiKeyForm({/>)}- {/* VertexAI Location */}- {currentAdapter === LLMAdapter.VertexAI && (+ {/* Azure Base URL - Always required for Azure */}+ {currentAdapter === LLMAdapter.Azure && (<FormFieldcontrol={form.control}- name="vertexAILocation"+ name="baseURL"render={({ field }) => (<FormItem>- <FormLabel>Location (Optional)</FormLabel>+ <FormLabel>API Base URL</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+ Please add the base URL in the following format (or+ compatible API):+ https://{instanceName}.openai.azure.com/openai/deployments</FormDescription><FormControl>- <Input {...field} placeholder="e.g., us-central1" />+ <Input+ {...field}+ placeholder="https://your-instance.openai.azure.com/openai/deployments"+ /></FormControl><FormMessage /></FormItem>@@ -584,174 +563,264 @@ export function CreateLLMApiKeyForm({/>)}- {/* Extra Headers */}- {currentAdapter === LLMAdapter.OpenAI ||- currentAdapter === LLMAdapter.Azure ? (- <FormField- control={form.control}- name="extraHeaders"- render={() => (- <FormItem>- <FormLabel>Extra Headers</FormLabel>- <FormDescription>- Optional additional HTTP headers to include with requests- towards LLM provider. All header values stored encrypted{" "}- {isLangfuseCloud ? "on our servers" : "in your database"}.- </FormDescription>+ <div className="flex items-center">+ <Button+ type="button"+ variant="link"+ size="sm"+ className="flex items-center pl-0"+ onClick={() => setShowAdvancedSettings(!showAdvancedSettings)}+ >+ <span>+ {showAdvancedSettings+ ? "Hide advanced settings"+ : "Show advanced settings"}+ </span>+ <ChevronDown+ className={`ml-1 h-4 w-4 transition-transform ${showAdvancedSettings ? "rotate-180" : "rotate-0"}`}+ />+ </Button>+ </div>++ {showAdvancedSettings && (+ <div className="space-y-4 border-t pt-4">+ {/* baseURL */}+ {currentAdapter !== LLMAdapter.Bedrock &&+ currentAdapter !== LLMAdapter.Azure && (+ <FormField+ control={form.control}+ name="baseURL"+ render={({ field }) => (+ <FormItem>+ <FormLabel>API Base URL</FormLabel>+ <FormDescription>+ Leave blank to use the default base URL for the given+ LLM adapter.{" "}+ {currentAdapter === LLMAdapter.OpenAI && (+ <span>+ OpenAI default: https://api.openai.com/v1+ </span>+ )}+ {currentAdapter === LLMAdapter.Anthropic && (+ <span>+ Anthropic default: https://api.anthropic.com+ (excluding /v1/messages)+ </span>+ )}+ </FormDescription>++ <FormControl>+ <Input {...field} placeholder="default" />+ </FormControl>++ <FormMessage />+ </FormItem>+ )}+ />+ )}++ {/* 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 ? (+ <FormField+ control={form.control}+ name="extraHeaders"+ render={() => (+ <FormItem>+ <FormLabel>Extra Headers</FormLabel>+ <FormDescription>+ Optional additional HTTP headers to include with+ requests towards LLM provider. All header values stored+ encrypted{" "}+ {isLangfuseCloud+ ? "on our servers"+ : "in your database"}+ .+ </FormDescription>++ {headerFields.map((header, index) => (+ <div+ key={header.id}+ className="flex flex-row space-x-2"+ >+ <Input+ {...form.register(`extraHeaders.${index}.key`)}+ placeholder="Header name"+ />+ <Input+ {...form.register(`extraHeaders.${index}.value`)}+ placeholder={+ mode === "update" &&+ existingKey?.extraHeaderKeys &&+ existingKey.extraHeaderKeys[index]+ ? "***"+ : "Header value"+ }+ />+ <Button+ type="button"+ variant="ghost"+ onClick={() => removeHeader(index)}+ >+ <TrashIcon className="h-4 w-4" />+ </Button>+ </div>+ ))}- {headerFields.map((header, index) => (- <div key={header.id} className="flex flex-row space-x-2">- <Input- {...form.register(`extraHeaders.${index}.key`)}- placeholder="Header name"- />- <Input- {...form.register(`extraHeaders.${index}.value`)}- placeholder={- mode === "update" &&- existingKey?.extraHeaderKeys &&- existingKey.extraHeaderKeys[index]- ? "***"- : "Header value"- }- /><Buttontype="button"variant="ghost"- onClick={() => removeHeader(index)}+ onClick={() => appendHeader({ key: "", value: "" })}+ className="w-full">- <TrashIcon className="h-4 w-4" />+ <PlusIcon+ className="-ml-0.5 mr-1.5 h-5 w-5"+ aria-hidden="true"+ />+ Add Header</Button>- </div>- ))}-- <Button- type="button"- variant="ghost"- onClick={() => appendHeader({ key: "", value: "" })}- className="w-full"- >- <PlusIcon- className="-ml-0.5 mr-1.5 h-5 w-5"- aria-hidden="true"- />- Add Header- </Button>- </FormItem>- )}- />- ) : null}+ </FormItem>+ )}+ />+ ) : null}- {/* With default models */}- <FormField- control={form.control}- name="withDefaultModels"- render={({ field }) => (- <FormItem>- <span className="row flex">- <span className="flex-1">- <FormLabel>Enable default models</FormLabel>+ {/* With default models */}+ <FormField+ control={form.control}+ name="withDefaultModels"+ render={({ field }) => (+ <FormItem>+ <span className="row flex">+ <span className="flex-1">+ <FormLabel>Enable default models</FormLabel>+ <FormDescription>+ Default models for the selected adapter will be+ available in Langfuse features.+ </FormDescription>+ {currentAdapter === LLMAdapter.Azure && (+ <FormDescription className="text-dark-yellow">+ Azure LLM adapter does not support default model+ names maintained by Langfuse. Instead, please add a+ custom model below that is the same as your+ deployment name.+ </FormDescription>+ )}+ {currentAdapter === LLMAdapter.Bedrock && (+ <FormDescription className="text-dark-yellow">+ Bedrock LLM adapter does not support default model+ names maintained by Langfuse. Instead, please add+ the Bedrock model IDs you have enabled in the AWS+ console.+ </FormDescription>+ )}+ </span>++ <FormControl>+ <Switch+ disabled={+ currentAdapter === LLMAdapter.Azure ||+ currentAdapter === LLMAdapter.Bedrock+ }+ checked={+ currentAdapter === LLMAdapter.Azure ||+ currentAdapter === LLMAdapter.Bedrock+ ? false+ : field.value+ }+ onCheckedChange={field.onChange}+ />+ </FormControl>+ </span>++ <FormMessage />+ </FormItem>+ )}+ />++ {/* Custom model names */}+ <FormField+ control={form.control}+ name="customModels"+ render={() => (+ <FormItem>+ <FormLabel>Custom models</FormLabel><FormDescription>- Default models for the selected adapter will be available- in Langfuse features.+ Custom model names accepted by given endpoint.</FormDescription>{currentAdapter === LLMAdapter.Azure && (<FormDescription className="text-dark-yellow">- Azure LLM adapter does not support default model names- maintained by Langfuse. Instead, please add a custom- model below that is the same as your deployment name.+ {+ "For Azure, the model name should be the same as the deployment name in Azure. For evals, choose a model with function calling capabilities."+ }</FormDescription>)}+{currentAdapter === LLMAdapter.Bedrock && (<FormDescription className="text-dark-yellow">- Bedrock LLM adapter does not support default model names- maintained by Langfuse. Instead, please add the Bedrock- model IDs you have enabled in the AWS console.+ {+ "For Bedrock, the model name is the Bedrock Inference Profile ID, e.g. 'eu.anthropic.claude-3-5-sonnet-20240620-v1:0'"+ }</FormDescription>)}- </span>-- <FormControl>- <Switch- disabled={- currentAdapter === LLMAdapter.Azure ||- currentAdapter === LLMAdapter.Bedrock- }- checked={- currentAdapter === LLMAdapter.Azure ||- currentAdapter === LLMAdapter.Bedrock- ? false- : field.value- }- onCheckedChange={field.onChange}- />- </FormControl>- </span>- <FormMessage />- </FormItem>- )}- />-- {/* Custom model names */}- <FormField- control={form.control}- name="customModels"- render={() => (- <FormItem>- <FormLabel>Custom models</FormLabel>- <FormDescription>- Custom model names accepted by given endpoint.- </FormDescription>- {currentAdapter === LLMAdapter.Azure && (- <FormDescription className="text-dark-yellow">- {- "For Azure, the model name should be the same as the deployment name in Azure. For evals, choose a model with function calling capabilities."- }- </FormDescription>- )}-- {currentAdapter === LLMAdapter.Bedrock && (- <FormDescription className="text-dark-yellow">- {- "For Bedrock, the model name is the Bedrock Inference Profile ID, e.g. 'eu.anthropic.claude-3-5-sonnet-20240620-v1:0'"- }- </FormDescription>- )}-- {fields.map((customModel, index) => (- <span- key={customModel.id}- className="flex flex-row space-x-2"- >- <Input- {...form.register(`customModels.${index}.value`)}- placeholder={`Custom model name ${index + 1}`}- />+ {fields.map((customModel, index) => (+ <span+ key={customModel.id}+ className="flex flex-row space-x-2"+ >+ <Input+ {...form.register(`customModels.${index}.value`)}+ placeholder={`Custom model name ${index + 1}`}+ />+ <Button+ type="button"+ variant="ghost"+ onClick={() => remove(index)}+ >+ <TrashIcon className="h-4 w-4" />+ </Button>+ </span>+ ))}<Buttontype="button"variant="ghost"- onClick={() => remove(index)}+ onClick={() => append({ value: "" })}+ className="w-full">- <TrashIcon className="h-4 w-4" />+ <PlusIcon+ className="-ml-0.5 mr-1.5 h-5 w-5"+ aria-hidden="true"+ />+ Add custom model name</Button>- </span>- ))}- <Button- type="button"- variant="ghost"- onClick={() => append({ value: "" })}- className="w-full"- >- <PlusIcon- className="-ml-0.5 mr-1.5 h-5 w-5"- aria-hidden="true"- />- Add custom model name- </Button>- </FormItem>- )}- />+ </FormItem>+ )}+ />+ </div>+ )}</DialogBody><DialogFooter>@@ -761,9 +830,7 @@ export function CreateLLMApiKeyForm({className="w-full"loading={form.formState.isSubmitting}>- {mode === "create"- ? "Save new LLM API key"- : "Update LLM API key"}+ {mode === "create" ? "Create connection" : "Save changes"}</Button>{form.formState.errors.root && (<FormMessage>{form.formState.errors.root.message}</FormMessage>diff --git a/web/src/features/public-api/components/LLMApiKeyList.tsx b/web/src/features/public-api/components/LLMApiKeyList.tsxindex 74730ccff7..075d835cee 100644--- a/web/src/features/public-api/components/LLMApiKeyList.tsx+++ b/web/src/features/public-api/components/LLMApiKeyList.tsx@@ -1,6 +1,5 @@import { TrashIcon } from "lucide-react";import { useState } from "react";-import Header from "@/src/components/layouts/header";import { Button } from "@/src/components/ui/button";import { Card } from "@/src/components/ui/card";@@ -29,6 +28,8 @@ import { CreateLLMApiKeyDialog } from "./CreateLLMApiKeyDialog";import { UpdateLLMApiKeyDialog } from "./UpdateLLMApiKeyDialog";export function LlmApiKeyList(props: { projectId: string }) {+ const [editingKeyId, setEditingKeyId] = useState<string | null>(null);+const hasAccess = useHasProjectAccess({projectId: props.projectId,scope: "llmApiKeys:read",@@ -50,7 +51,7 @@ export function LlmApiKeyList(props: { projectId: string }) {if (!hasAccess) {return (<div>- <Header title="LLM API Keys" />+ <Header title="LLM Connections" /><Alert><AlertTitle>Access Denied</AlertTitle><AlertDescription>@@ -63,18 +64,15 @@ export function LlmApiKeyList(props: { projectId: string }) {return (<div id="llm-api-keys">- <Header title="LLM API keys" />+ <Header title="LLM Connections" /><p className="mb-4 text-sm">- These keys are used to power the Langfuse playground and evaluations- feature and will incur costs based on usage with your key provider.+ Connect your LLM services to enable evaluations and playground features.+ Your provider will charge based on usage.</p><Card className="mb-4 overflow-auto"><Table><TableHeader><TableRow>- <TableHead className="hidden text-primary md:table-cell">- Created- </TableHead><TableHead className="text-primary md:table-cell">Provider</TableHead>@@ -84,7 +82,7 @@ export function LlmApiKeyList(props: { projectId: string }) {<TableHead className="text-primary md:table-cell">Base URL</TableHead>- <TableHead className="text-primary">Secret Key</TableHead>+ <TableHead className="text-primary">API Key</TableHead>{hasExtraHeaderKeys ? (<TableHead className="text-primary">Extra headers</TableHead>) : null}@@ -102,11 +100,9 @@ export function LlmApiKeyList(props: { projectId: string }) {apiKeys.data?.data.map((apiKey) => (<TableRowkey={apiKey.id}- className="hover:bg-primary-foreground"+ className="cursor-default hover:bg-primary-foreground"+ onClick={() => setEditingKeyId(apiKey.id)}>- <TableCell className="hidden md:table-cell">- {apiKey.createdAt.toLocaleDateString()}- </TableCell><TableCell className="font-mono">{apiKey.provider}</TableCell><TableCell className="font-mono">{apiKey.adapter}</TableCell><TableCell className="max-w-md overflow-auto font-mono">@@ -118,8 +114,11 @@ export function LlmApiKeyList(props: { projectId: string }) {{hasExtraHeaderKeys ? (<TableCell> {apiKey.extraHeaderKeys.join(", ")} </TableCell>) : null}- <TableCell>- <div className="flex space-x-2">+ <TableCell className="text-right">+ <div+ className="flex justify-end space-x-2"+ onClick={(e) => e.stopPropagation()}+ ><UpdateLLMApiKeyDialogapiKey={{...apiKey,@@ -128,6 +127,14 @@ export function LlmApiKeyList(props: { projectId: string }) {config: apiKey.config ?? null,}}projectId={props.projectId}+ open={editingKeyId === apiKey.id}+ onOpenChange={(open: boolean) => {+ if (open) {+ setEditingKeyId(apiKey.id);+ } else {+ setEditingKeyId(null);+ }+ }}/><DeleteApiKeyButtonprojectId={props.projectId}@@ -171,10 +178,10 @@ function DeleteApiKeyButton(props: { projectId: string; apiKeyId: string }) {</DialogTrigger><DialogContent><DialogHeader>- <DialogTitle className="mb-5">Delete LLM provider</DialogTitle>+ <DialogTitle className="mb-5">Delete LLM Connection</DialogTitle><DialogDescription>- Are you sure you want to delete this LLM provider? This action- cannot be undone.+ Are you sure you want to delete this connection? This action cannot+ be undone.</DialogDescription></DialogHeader>diff --git a/web/src/features/public-api/components/UpdateLLMApiKeyDialog.tsx b/web/src/features/public-api/components/UpdateLLMApiKeyDialog.tsxindex f48e9ea4ff..91b84dd5b8 100644--- a/web/src/features/public-api/components/UpdateLLMApiKeyDialog.tsx+++ b/web/src/features/public-api/components/UpdateLLMApiKeyDialog.tsx@@ -16,13 +16,21 @@ import { PencilIcon } from "lucide-react";export function UpdateLLMApiKeyDialog({apiKey,projectId,+ open,+ onOpenChange,}: {apiKey: LlmApiKeys;projectId: string;+ open?: boolean;+ onOpenChange?: (open: boolean) => void;}) {- const [open, setOpen] = useState(false);+ const [internalOpen, setInternalOpen] = useState(false);const uiCustomization = useUiCustomization();+ // Use external state if provided, otherwise use internal state+ const isOpen = open !== undefined ? open : internalOpen;+ const setIsOpen = onOpenChange || setInternalOpen;+const hasAccess = useHasProjectAccess({projectId,scope: "llmApiKeys:update",@@ -31,20 +39,23 @@ export function UpdateLLMApiKeyDialog({if (!hasAccess) return null;return (- <Dialog open={open} onOpenChange={setOpen}>+ <Dialog open={isOpen} onOpenChange={setIsOpen}><DialogTrigger asChild><Button variant="ghost" size="icon"><PencilIcon className="h-4 w-4" /></Button></DialogTrigger>- <DialogContent className="max-h-[90%] min-w-[40vw] overflow-auto">+ <DialogContent+ className="max-h-[90%] min-w-[40vw] overflow-auto"+ onClick={(e) => e.stopPropagation()}+ ><DialogHeader>- <DialogTitle>Update LLM API key</DialogTitle>+ <DialogTitle>Update LLM Connection</DialogTitle></DialogHeader>- {open && (+ {isOpen && (<CreateLLMApiKeyFormprojectId={projectId}- onSuccess={() => setOpen(false)}+ onSuccess={() => setIsOpen(false)}customization={uiCustomization}mode="update"existingKey={apiKey}