Skip to content

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

feat(api-keys): make CTA more prominent, encourage adding notes (#9720)

Leo Weigandb78d7a97aa02
diff --git a/web/src/components/layouts/header.tsx b/web/src/components/layouts/header.tsx
index 78d2e84b7d..e8e9c2e405 100644
--- a/web/src/components/layouts/header.tsx
+++ b/web/src/components/layouts/header.tsx
@@ -49,7 +49,7 @@ function BaseHeader({ ...props }: HeaderProps & { level: "h3" | "h4" | "h5" }) {
<div className={cn(props.className, props.level === "h3" && "mb-2")}>
<div className="flex flex-wrap items-center justify-between gap-2">
<div className="flex items-center gap-3 md:gap-5">
- <div className="flex min-w-0 flex-row justify-center align-middle">
+ <div className="flex min-w-0 flex-row items-center">
<HeaderTitle title={props.title} level={props.level} />
{props.help ? (
<DocPopup
diff --git a/web/src/features/public-api/components/ApiKeyList.tsx b/web/src/features/public-api/components/ApiKeyList.tsx
index 79ad903e0e..0ecbc06fa5 100644
--- a/web/src/features/public-api/components/ApiKeyList.tsx
+++ b/web/src/features/public-api/components/ApiKeyList.tsx
@@ -90,6 +90,7 @@ export function ApiKeyList(props: { entityId: string; scope: ApiKeyScope }) {
? "https://langfuse.com/docs/api#authentication"
: "https://langfuse.com/docs/api#org-scoped-routes",
}}
+ actionButtons={<CreateApiKeyButton entityId={entityId} scope={scope} />}
/>
<Card className="mb-4 overflow-hidden">
<Table>
@@ -108,7 +109,7 @@ export function ApiKeyList(props: { entityId: string; scope: ApiKeyScope }) {
<TableBody className="text-muted-foreground">
{apiKeysQuery.data?.length === 0 ? (
<TableRow>
- <TableCell colSpan={6} className="text-center">
+ <TableCell colSpan={5} className="text-center">
None
</TableCell>
</TableRow>
@@ -153,7 +154,6 @@ export function ApiKeyList(props: { entityId: string; scope: ApiKeyScope }) {
</TableBody>
</Table>
</Card>
- <CreateApiKeyButton entityId={entityId} scope={scope} />
</div>
);
}
diff --git a/web/src/features/public-api/components/CreateApiKeyButton.tsx b/web/src/features/public-api/components/CreateApiKeyButton.tsx
index ad007e7ca8..b121107dd4 100644
--- a/web/src/features/public-api/components/CreateApiKeyButton.tsx
+++ b/web/src/features/public-api/components/CreateApiKeyButton.tsx
@@ -6,6 +6,7 @@ import {
Dialog,
DialogBody,
DialogContent,
+ DialogFooter,
DialogHeader,
DialogTitle,
DialogTrigger,
@@ -16,6 +17,8 @@ import { useHasOrganizationAccess } from "@/src/features/rbac/utils/checkOrganiz
import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";
import { useUiCustomization } from "@/src/ee/features/ui-customization/useUiCustomization";
import { env } from "@/src/env.mjs";
+import { Input } from "@/src/components/ui/input";
+import { Label } from "@/src/components/ui/label";
import { cn } from "@/src/utils/tailwind";
import { SubHeader } from "@/src/components/layouts/header";
@@ -48,77 +51,108 @@ export function CreateApiKeyButton(props: {
});
const [open, setOpen] = useState(false);
+ const [note, setNote] = useState("");
const [generatedKeys, setGeneratedKeys] = useState<{
secretKey: string;
publicKey: string;
} | null>(null);
- const createApiKey = () => {
- if (open) {
- setOpen(false);
+ const handleOpenChange = (newOpen: boolean) => {
+ setOpen(newOpen);
+ if (!newOpen) {
+ // Reset state when closing
setGeneratedKeys(null);
- } else {
- if (props.scope === "project") {
- mutCreateProjectApiKey
- .mutateAsync({
- projectId: props.entityId,
- })
- .then(({ secretKey, publicKey }) => {
- setGeneratedKeys({
- secretKey,
- publicKey,
- });
- setOpen(true);
- capture(`${props.scope}_settings:api_key_create`);
- })
- .catch((error) => {
- console.error(error);
+ setNote("");
+ }
+ };
+
+ const createApiKey = () => {
+ if (props.scope === "project") {
+ mutCreateProjectApiKey
+ .mutateAsync({
+ projectId: props.entityId,
+ note: note || undefined,
+ })
+ .then(({ secretKey, publicKey }) => {
+ setGeneratedKeys({
+ secretKey,
+ publicKey,
});
- } else {
- mutCreateOrgApiKey
- .mutateAsync({
- orgId: props.entityId,
- })
- .then(({ secretKey, publicKey }) => {
- setGeneratedKeys({
- secretKey,
- publicKey,
- });
- setOpen(true);
- capture(`${props.scope}_settings:api_key_create`);
- })
- .catch((error) => {
- console.error(error);
+ capture(`${props.scope}_settings:api_key_create`);
+ })
+ .catch((error) => {
+ console.error(error);
+ });
+ } else {
+ mutCreateOrgApiKey
+ .mutateAsync({
+ orgId: props.entityId,
+ note: note || undefined,
+ })
+ .then(({ secretKey, publicKey }) => {
+ setGeneratedKeys({
+ secretKey,
+ publicKey,
});
- }
+ capture(`${props.scope}_settings:api_key_create`);
+ })
+ .catch((error) => {
+ console.error(error);
+ });
}
};
if (!hasAccess) return null;
return (
- <Dialog open={open} onOpenChange={createApiKey}>
+ <Dialog open={open} onOpenChange={handleOpenChange}>
<DialogTrigger asChild>
- <Button
- variant="secondary"
- loading={
- mutCreateProjectApiKey.isPending || mutCreateOrgApiKey.isPending
- }
- >
+ <Button variant="secondary">
<PlusIcon className="-ml-0.5 mr-1.5 h-5 w-5" aria-hidden="true" />
Create new API keys
</Button>
</DialogTrigger>
<DialogContent onPointerDownOutside={(e) => e.preventDefault()}>
<DialogHeader>
- <DialogTitle>API Keys</DialogTitle>
+ <DialogTitle>
+ {generatedKeys ? "API Keys" : "Create API Keys"}
+ </DialogTitle>
</DialogHeader>
<DialogBody>
- <ApiKeyRender
- scope={props.scope}
- generatedKeys={generatedKeys ?? undefined}
- />
+ {generatedKeys ? (
+ <ApiKeyRender scope={props.scope} generatedKeys={generatedKeys} />
+ ) : (
+ <div className="space-y-4">
+ <div>
+ <Label htmlFor="note">Note (optional)</Label>
+ <Input
+ id="note"
+ placeholder="Production key"
+ value={note}
+ onChange={(e) => setNote(e.target.value)}
+ onKeyDown={(e) => {
+ if (e.key === "Enter") {
+ createApiKey();
+ }
+ }}
+ className="mt-1.5"
+ />
+ </div>
+ </div>
+ )}
</DialogBody>
+ {!generatedKeys && (
+ <DialogFooter>
+ <Button
+ onClick={createApiKey}
+ loading={
+ mutCreateProjectApiKey.isPending || mutCreateOrgApiKey.isPending
+ }
+ >
+ Create API keys
+ </Button>
+ </DialogFooter>
+ )}
</DialogContent>
</Dialog>
);