Skip to content

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

feat(ai-gateway): prefill and mask the new gateway key in setup snippets (#19583)

Tobias Wochinger47d2a989cde6
diff --git a/web/src/components/design-system/CodeSection/CodeSection.tsx b/web/src/components/design-system/CodeSection/CodeSection.tsx
index 4d2f32f666..e6989e693a 100644
--- a/web/src/components/design-system/CodeSection/CodeSection.tsx
+++ b/web/src/components/design-system/CodeSection/CodeSection.tsx
@@ -40,6 +40,14 @@ const codeVariants = cva(
true: "line-clamp-6",
false: "block",
},
+ // Keeps text clear of the floating body actions; unwrapped lines can scroll out from under them.
+ reservedButtons: {
+ 0: null,
+ 1: "pr-10",
+ 2: "pr-17",
+ 3: "pr-24",
+ 4: "pr-31",
+ },
},
defaultVariants: {
wrap: true,
@@ -55,7 +63,13 @@ const actionGroupVariants = cva(
variants: {
placement: {
header: null,
- body: "pt-2 pr-2",
+ // Floats over the code so long lines keep the full width.
+ body: "absolute top-1.5 right-1.5 rounded-md",
+ },
+ surface: {
+ filled: "bg-surface-section",
+ outline: "bg-background",
+ plain: "bg-background",
},
// Copy feedback stays visible even when the pointer has already left.
isPinned: {
@@ -63,10 +77,21 @@ const actionGroupVariants = cva(
false: "opacity-0",
},
},
+ compoundVariants: [
+ {
+ // Invisible controls over the code must not swallow clicks on the text below.
+ placement: "body",
+ isPinned: false,
+ class:
+ "pointer-events-none group-hover/codesection:pointer-events-auto focus-within:pointer-events-auto pointer-coarse:pointer-events-auto",
+ },
+ ],
},
);
type CodeSectionAction = {
+ /** Stable React key; set it when `label` changes so focus survives the change. */
+ id?: string;
icon: IconComponent;
label: string;
onClick: () => void;
@@ -123,10 +148,16 @@ export function CodeSection({
}
};
+ const bodyButtonCount = Math.min(
+ actions.length + (isCollapsible ? 1 : 0) + 1,
+ 4,
+ ) as 1 | 2 | 3 | 4;
+
const actionGroup = (
<div
className={actionGroupVariants({
placement: title ? "header" : "body",
+ surface: title ? undefined : variant,
isPinned: isCopied,
})}
>
@@ -139,7 +170,7 @@ export function CodeSection({
</span>
) : null}
{actions.map((action) => (
- <Tooltip key={action.label} label={action.label}>
+ <Tooltip key={action.id ?? action.label} label={action.label}>
{({ getTriggerProps }) => (
<IconButton
{...getTriggerProps()}
@@ -197,6 +228,7 @@ export function CodeSection({
className={codeVariants({
wrap: shouldWrapLines,
collapsed: isCollapsed,
+ reservedButtons: title ? 0 : bodyButtonCount,
})}
dir="auto"
style={{ unicodeBidi: "plaintext" }}
diff --git a/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/GeneratedKeyContent/GeneratedKeyContent.tsx b/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/GeneratedKeyContent/GeneratedKeyContent.tsx
index f674879d4f..4d43011f9e 100644
--- a/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/GeneratedKeyContent/GeneratedKeyContent.tsx
+++ b/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/GeneratedKeyContent/GeneratedKeyContent.tsx
@@ -14,6 +14,11 @@ export function GeneratedKeyContent({
}: GeneratedKeyContentProps) {
const capture = usePostHogClientCapture();
+ const handleAfterSecretCopy = () =>
+ capture("ai_gateway:api_key_secret_copied", { orgId: organizationId });
+ const handleAfterSecretReveal = () =>
+ capture("ai_gateway:api_key_secret_revealed", { orgId: organizationId });
+
return (
<Dialog.Body>
<p className="text-muted-foreground">
@@ -21,17 +26,18 @@ export function GeneratedKeyContent({
</p>
<MaskedGatewayKey
secretKey={secretKey}
- onAfterCopy={() =>
- capture("ai_gateway:api_key_secret_copied", { orgId: organizationId })
- }
- onAfterReveal={() =>
- capture("ai_gateway:api_key_secret_revealed", {
- orgId: organizationId,
- })
- }
+ onAfterCopy={handleAfterSecretCopy}
+ onAfterReveal={handleAfterSecretReveal}
/>
<hr className="-mx-4" />
- <SetupInstructions organizationId={organizationId} />
+ <SetupInstructions
+ organizationId={organizationId}
+ secretKey={{
+ value: secretKey,
+ onAfterCopy: handleAfterSecretCopy,
+ onAfterReveal: handleAfterSecretReveal,
+ }}
+ />
</Dialog.Body>
);
}
diff --git a/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/GeneratedKeyContent/components/MaskedGatewayKey.tsx b/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/GeneratedKeyContent/components/MaskedGatewayKey.tsx
index 9c1a037cdd..7b3de72c9b 100644
--- a/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/GeneratedKeyContent/components/MaskedGatewayKey.tsx
+++ b/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/GeneratedKeyContent/components/MaskedGatewayKey.tsx
@@ -3,22 +3,9 @@ import { Check, Copy, Eye, EyeOff } from "@langfuse/icons";
import { IconButton } from "@/src/components/design-system/IconButton/IconButton";
import { Tooltip } from "@/src/components/design-system/Tooltip/Tooltip";
+import { maskSecretKey } from "@/src/features/ai-gateway/components/GatewayApiKeysPage/fns/maskSecretKey";
import { useCopyToClipboard } from "@/src/hooks/useCopyToClipboard";
-const SECRET_KEY_PREFIX = "sk-lf-";
-const VISIBLE_CHARACTERS = 4;
-const MASK = "•".repeat(20);
-
-/** Keeps the `sk-lf-` prefix plus the first and last four characters readable. */
-function maskSecretKey(secretKey: string) {
- const prefixLength = secretKey.startsWith(SECRET_KEY_PREFIX)
- ? SECRET_KEY_PREFIX.length
- : 0;
- const secretPart = secretKey.slice(prefixLength);
- if (secretPart.length <= VISIBLE_CHARACTERS * 2) return MASK;
- return `${secretKey.slice(0, prefixLength + VISIBLE_CHARACTERS)}${MASK}${secretKey.slice(-VISIBLE_CHARACTERS)}`;
-}
-
type MaskedGatewayKeyProps = {
secretKey: string;
onAfterCopy?: () => void;
diff --git a/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/SetupInstructions/SetupInstructions.tsx b/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/SetupInstructions/SetupInstructions.tsx
index b767982582..dd1233eaf2 100644
--- a/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/SetupInstructions/SetupInstructions.tsx
+++ b/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/SetupInstructions/SetupInstructions.tsx
@@ -1,16 +1,23 @@
import { Alert } from "@/src/components/design-system/Alert/Alert";
import { Skeleton } from "@/src/components/ui/skeleton";
import { SetupInstructionsTabs } from "@/src/features/ai-gateway/components/GatewayApiKeysPage/components/SetupInstructions/components/SetupInstructionsTabs/SetupInstructionsTabs";
+import {
+ type GatewaySecretKey,
+ GatewaySecretKeyContext,
+} from "@/src/features/ai-gateway/components/GatewayApiKeysPage/components/SetupInstructions/contexts/gatewaySecretKeyContext";
import { useAgentSetupInstructions } from "@/src/features/ai-gateway/components/GatewayApiKeysPage/components/SetupInstructions/hooks/useAgentSetupInstructions";
type SetupInstructionsProps = {
organizationId: string;
defaultExpanded?: boolean;
+ /** Fills the snippets with this key instead of the placeholder. */
+ secretKey?: GatewaySecretKey;
};
export function SetupInstructions({
organizationId,
defaultExpanded,
+ secretKey,
}: SetupInstructionsProps) {
const { instructions, isPending, isError } =
useAgentSetupInstructions(organizationId);
@@ -30,10 +37,12 @@ export function SetupInstructions({
}
return (
- <SetupInstructionsTabs
- organizationId={organizationId}
- instructions={instructions}
- defaultExpanded={defaultExpanded}
- />
+ <GatewaySecretKeyContext value={secretKey}>
+ <SetupInstructionsTabs
+ organizationId={organizationId}
+ instructions={instructions}
+ defaultExpanded={defaultExpanded}
+ />
+ </GatewaySecretKeyContext>
);
}
diff --git a/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/SetupInstructions/components/AgentSetupSteps.tsx b/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/SetupInstructions/components/AgentSetupSteps.tsx
index ef63b26168..3d9fd6bdd2 100644
--- a/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/SetupInstructions/components/AgentSetupSteps.tsx
+++ b/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/SetupInstructions/components/AgentSetupSteps.tsx
@@ -1,8 +1,17 @@
+import { use } from "react";
+
import { Alert } from "@/src/components/design-system/Alert/Alert";
import { Button } from "@/src/components/design-system/Button/Button";
-import { CodeSection } from "@/src/components/design-system/CodeSection/CodeSection";
import { Stepper } from "@/src/components/design-system/Stepper/Stepper";
-import type { AgentSetupInstructions } from "@/src/features/ai-gateway/types/agentSetupInstructions";
+import { GatewaySecretKeyContext } from "@/src/features/ai-gateway/components/GatewayApiKeysPage/components/SetupInstructions/contexts/gatewaySecretKeyContext";
+import { GATEWAY_KEY_PLACEHOLDER } from "@/src/features/ai-gateway/constants/agentSetupInstructions";
+import type {
+ AgentSetupInstructions,
+ AgentSetupStep,
+} from "@/src/features/ai-gateway/types/agentSetupInstructions";
+import { StepCodeSection } from "./StepCodeSection";
+
+const REPLACE_KEY_HINT = `Replace ${GATEWAY_KEY_PLACEHOLDER} with your gateway key.`;
type AgentSetupStepsProps = {
instructions: AgentSetupInstructions;
@@ -13,6 +22,8 @@ export function AgentSetupSteps({
instructions,
onAfterStepCopy,
}: AgentSetupStepsProps) {
+ const secretKey = use(GatewaySecretKeyContext)?.value;
+
return (
<div className="flex flex-col gap-3">
{instructions.warning ? (
@@ -29,7 +40,7 @@ export function AgentSetupSteps({
description={
step.link ? (
<>
- {step.description}{" "}
+ {describeStep(step, secretKey)}{" "}
<Button
variant="text"
text={step.link.label}
@@ -37,7 +48,7 @@ export function AgentSetupSteps({
/>
</>
) : (
- step.description
+ describeStep(step, secretKey)
)
}
variant="outline"
@@ -46,11 +57,9 @@ export function AgentSetupSteps({
compactBottomSpacing
>
{step.code === undefined ? null : (
- <CodeSection
- variant="outline"
- content={step.code}
+ <StepCodeSection
+ code={step.code}
language={step.language}
- shouldWrapLines={false}
onAfterCopy={() => onAfterStepCopy?.(index + 1)}
/>
)}
@@ -60,3 +69,12 @@ export function AgentSetupSteps({
</div>
);
}
+
+/** Without a prefilled key, snippets carry the placeholder, so the step says to replace it. */
+function describeStep(step: AgentSetupStep, secretKey: string | undefined) {
+ const needsKeyHint =
+ !secretKey && step.code?.includes(GATEWAY_KEY_PLACEHOLDER) === true;
+ return [step.description, needsKeyHint ? REPLACE_KEY_HINT : undefined]
+ .filter(Boolean)
+ .join(" ");
+}
diff --git a/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/SetupInstructions/components/StepCodeSection.tsx b/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/SetupInstructions/components/StepCodeSection.tsx
new file mode 100644
index 0000000000..1beb8842d7
--- /dev/null
+++ b/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/SetupInstructions/components/StepCodeSection.tsx
@@ -0,0 +1,74 @@
+import { use, useState } from "react";
+import { Eye, EyeOff } from "@langfuse/icons";
+
+import { CodeSection } from "@/src/components/design-system/CodeSection/CodeSection";
+import { SyntaxHighlight } from "@/src/components/design-system/SyntaxHighlight/SyntaxHighlight";
+import { GatewaySecretKeyContext } from "@/src/features/ai-gateway/components/GatewayApiKeysPage/components/SetupInstructions/contexts/gatewaySecretKeyContext";
+import { maskSecretKey } from "@/src/features/ai-gateway/components/GatewayApiKeysPage/fns/maskSecretKey";
+import { GATEWAY_KEY_PLACEHOLDER } from "@/src/features/ai-gateway/constants/agentSetupInstructions";
+
+type StepCodeSectionProps = {
+ code: string;
+ language: string;
+ onAfterCopy?: () => void;
+};
+
+/** Fills in the secret key when it is known: masked until revealed, copied in full. */
+export function StepCodeSection({
+ code,
+ language,
+ onAfterCopy,
+}: StepCodeSectionProps) {
+ const secretKey = use(GatewaySecretKeyContext);
+ const [isRevealed, setIsRevealed] = useState(false);
+
+ if (!secretKey || !code.includes(GATEWAY_KEY_PLACEHOLDER)) {
+ return (
+ <CodeSection
+ variant="outline"
+ content={code}
+ language={language}
+ shouldWrapLines={false}
+ onAfterCopy={onAfterCopy}
+ />
+ );
+ }
+
+ const displayedKey = isRevealed
+ ? secretKey.value
+ : maskSecretKey(secretKey.value);
+
+ const toggleReveal = () => {
+ if (!isRevealed) secretKey.onAfterReveal?.();
+ setIsRevealed(!isRevealed);
+ };
+
+ const handleAfterCopy = () => {
+ onAfterCopy?.();
+ secretKey.onAfterCopy?.();
+ };
+
+ return (
+ <CodeSection
+ variant="outline"
+ content={code.replaceAll(GATEWAY_KEY_PLACEHOLDER, secretKey.value)}
+ shouldWrapLines={false}
+ actions={[
+ {
+ id: "reveal-key",
+ icon: isRevealed ? EyeOff : Eye,
+ label: isRevealed ? "Hide key" : "Show key",
+ onClick: toggleReveal,
+ },
+ ]}
+ onAfterCopy={handleAfterCopy}
+ >
+ <SyntaxHighlight
+ code={code.replaceAll(GATEWAY_KEY_PLACEHOLDER, displayedKey)}
+ language={language}
+ >
+ {({ content }) => content}
+ </SyntaxHighlight>
+ </CodeSection>
+ );
+}
diff --git a/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/SetupInstructions/contexts/gatewaySecretKeyContext.ts b/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/SetupInstructions/contexts/gatewaySecretKeyContext.ts
new file mode 100644
index 0000000000..b20727b869
--- /dev/null
+++ b/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/SetupInstructions/contexts/gatewaySecretKeyContext.ts
@@ -0,0 +1,12 @@
+import { createContext } from "react";
+
+export type GatewaySecretKey = {
+ value: string;
+ onAfterCopy?: () => void;
+ onAfterReveal?: () => void;
+};
+
+/** The just-created secret key; undefined once it can no longer be shown. */
+export const GatewaySecretKeyContext = createContext<
+ GatewaySecretKey | undefined
+>(undefined);
diff --git a/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/SetupInstructions/fns/agentSetupInstructions/AGENTS.md b/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/SetupInstructions/fns/agentSetupInstructions/AGENTS.md
index f18b52f7db..7d3b8c831c 100644
--- a/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/SetupInstructions/fns/agentSetupInstructions/AGENTS.md
+++ b/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/SetupInstructions/fns/agentSetupInstructions/AGENTS.md
@@ -17,8 +17,8 @@ Do not add steps, paths or env vars that the docs do not describe.
## Rules
-- Never put the secret key into a snippet. Use `GATEWAY_KEY_PLACEHOLDER`; the
- key is shown and copied only by the key field above the tabs.
+- Builders never receive the secret key; they emit `GATEWAY_KEY_PLACEHOLDER`. Right after creation, `StepCodeSection` swaps it for the key at render time (masked until revealed, copied in full). Without a key, `AgentSetupSteps` adds a replace-the-placeholder hint, so step descriptions must not mention the placeholder themselves. "Copy for agent" keeps the placeholder.
+- Prefix shell lines that set or write the key (`export`, the Codex heredoc) with a space so shells with `ignorespace` / `HIST_IGNORE_SPACE` skip them in history. Also prefix the first line of every key-bearing snippet: a bracketed multi-line paste is saved as one history entry, and only its first character counts.
- Paths differ per tool (`/anthropic` vs `/anthropic/v1`); keep them as the
docs list them under "Base URLs at a glance".
- Builders are pure: `(context: AgentSetupContext) => AgentSetupInstructions`.
diff --git a/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/SetupInstructions/fns/agentSetupInstructions/__tests__/agentSetupInstructions.clienttest.ts b/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/SetupInstructions/fns/agentSetupInstructions/__tests__/agentSetupInstructions.clienttest.ts
index f667fef47e..9363dec97d 100644
--- a/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/SetupInstructions/fns/agentSetupInstructions/__tests__/agentSetupInstructions.clienttest.ts
+++ b/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/SetupInstructions/fns/agentSetupInstructions/__tests__/agentSetupInstructions.clienttest.ts
@@ -53,6 +53,26 @@ describe("agent setup instructions", () => {
}
});
+ it("keeps shell lines that carry the key out of shell history", () => {
+ for (const instructions of buildAgentSetupInstructions(context)) {
+ for (const step of instructions.steps) {
+ if (step.language !== "sh") continue;
+ const lines = step.code.split("\n");
+ // A bracketed multi-line paste is one history entry, judged by its first character.
+ const firstLine = step.code.includes(GATEWAY_KEY_PLACEHOLDER)
+ ? [lines[0]]
+ : [];
+ const keyLines = lines.filter(
+ (line) => line.includes("export ") || line.includes("cat >>"),
+ );
+
+ for (const line of [...firstLine, ...keyLines]) {
+ expect(line).toMatch(/^ \S/);
+ }
+ }
+ }
+ });
+
it("copies markdown with a heading and docs link", () => {
for (const instructions of buildAgentSetupInstructions(context)) {
const markdown = formatAgentSetupMarkdown(instructions);
diff --git a/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/SetupInstructions/fns/agentSetupInstructions/buildApiInstructions.ts b/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/SetupInstructions/fns/agentSetupInstructions/buildApiInstructions.ts
index 09c0f1198c..a9569c786e 100644
--- a/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/SetupInstructions/fns/agentSetupInstructions/buildApiInstructions.ts
+++ b/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/SetupInstructions/fns/agentSetupInstructions/buildApiInstructions.ts
@@ -53,11 +53,10 @@ export function buildApiInstructions(
steps: [
{
title: "Export the gateway host and key",
- description: "Replace the placeholder with your gateway key.",
language: "sh",
code: [
- `export LANGFUSE_GATEWAY_HOST="${context.gatewayOrigin}"`,
- `export LANGFUSE_GATEWAY_KEY="${GATEWAY_KEY_PLACEHOLDER}"`,
+ ` export LANGFUSE_GATEWAY_HOST="${context.gatewayOrigin}"`,
+ ` export LANGFUSE_GATEWAY_KEY="${GATEWAY_KEY_PLACEHOLDER}"`,
].join("\n"),
},
...providers.map((provider) => LIST_MODELS_STEPS[provider]),
diff --git a/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/SetupInstructions/fns/agentSetupInstructions/buildClaudeCodeInstructions.ts b/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/SetupInstructions/fns/agentSetupInstructions/buildClaudeCodeInstructions.ts
index 12fa936007..bcff2895c7 100644
--- a/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/SetupInstructions/fns/agentSetupInstructions/buildClaudeCodeInstructions.ts
+++ b/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/SetupInstructions/fns/agentSetupInstructions/buildClaudeCodeInstructions.ts
@@ -32,8 +32,8 @@ export function buildClaudeCodeInstructions(
description: "Leave ANTHROPIC_API_KEY unset.",
language: "sh",
code: [
- `export ANTHROPIC_BASE_URL="${context.gatewayOrigin}/anthropic"`,
- `export ANTHROPIC_AUTH_TOKEN="${GATEWAY_KEY_PLACEHOLDER}"`,
+ ` export ANTHROPIC_BASE_URL="${context.gatewayOrigin}/anthropic"`,
+ ` export ANTHROPIC_AUTH_TOKEN="${GATEWAY_KEY_PLACEHOLDER}"`,
"unset ANTHROPIC_API_KEY",
].join("\n"),
},
diff --git a/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/SetupInstructions/fns/agentSetupInstructions/buildCodexInstructions.ts b/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/SetupInstructions/fns/agentSetupInstructions/buildCodexInstructions.ts
index 5967511a68..18ce0abf0b 100644
--- a/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/SetupInstructions/fns/agentSetupInstructions/buildCodexInstructions.ts
+++ b/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/SetupInstructions/fns/agentSetupInstructions/buildCodexInstructions.ts
@@ -23,14 +23,13 @@ export function buildCodexInstructions(
steps: [
{
title: "Store the key in Codex's .env",
- description:
- "Codex loads this file every time it starts. Replace the placeholder with your gateway key.",
+ description: "Codex loads this file every time it starts.",
language: "sh",
code: [
- 'CODEX_DIR="${CODEX_HOME:-$HOME/.codex}"',
+ ' CODEX_DIR="${CODEX_HOME:-$HOME/.codex}"',
'mkdir -p -m 700 "$CODEX_DIR"',
'touch "$CODEX_DIR/.env" && chmod 600 "$CODEX_DIR/.env"',
- `cat >> "$CODEX_DIR/.env" <<'EOF'`,
+ ` cat >> "$CODEX_DIR/.env" <<'EOF'`,
`LANGFUSE_GATEWAY_KEY=${GATEWAY_KEY_PLACEHOLDER}`,
"EOF",
].join("\n"),
diff --git a/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/SetupInstructions/fns/agentSetupInstructions/buildCopilotCliInstructions.ts b/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/SetupInstructions/fns/agentSetupInstructions/buildCopilotCliInstructions.ts
index f727371136..e0ee619120 100644
--- a/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/SetupInstructions/fns/agentSetupInstructions/buildCopilotCliInstructions.ts
+++ b/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/SetupInstructions/fns/agentSetupInstructions/buildCopilotCliInstructions.ts
@@ -15,13 +15,13 @@ const COPILOT_PROVIDERS: Record<
> = {
ANTHROPIC: {
path: "/anthropic",
- env: ['export COPILOT_PROVIDER_TYPE="anthropic"'],
+ env: [' export COPILOT_PROVIDER_TYPE="anthropic"'],
},
OPENAI: {
path: "/openai/v1",
env: [
- 'export COPILOT_PROVIDER_TYPE="openai"',
- 'export COPILOT_PROVIDER_WIRE_API="responses"',
+ ' export COPILOT_PROVIDER_TYPE="openai"',
+ ' export COPILOT_PROVIDER_WIRE_API="responses"',
],
},
};
@@ -49,13 +49,13 @@ export function buildCopilotCliInstructions(
{
title: "Point Copilot CLI at the gateway",
description:
- "Replace the placeholders with your gateway key and a model from your provider credential. If ~/.copilot/providers.json lists providers, it takes precedence over these variables.",
+ "Replace <model> with a model from your provider credential. If ~/.copilot/providers.json lists providers, it takes precedence over these variables.",
language: "sh",
code: [
...env,
- `export COPILOT_PROVIDER_BASE_URL="${context.gatewayOrigin}${path}"`,
- `export COPILOT_PROVIDER_API_KEY="${GATEWAY_KEY_PLACEHOLDER}"`,
- 'export COPILOT_MODEL="<model>"',
+ ` export COPILOT_PROVIDER_BASE_URL="${context.gatewayOrigin}${path}"`,
+ ` export COPILOT_PROVIDER_API_KEY="${GATEWAY_KEY_PLACEHOLDER}"`,
+ ' export COPILOT_MODEL="<model>"',
].join("\n"),
},
{
diff --git a/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/SetupInstructions/fns/agentSetupInstructions/buildOpenCodeInstructions.ts b/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/SetupInstructions/fns/agentSetupInstructions/buildOpenCodeInstructions.ts
index ae93d8c53f..e8752fa7b8 100644
--- a/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/SetupInstructions/fns/agentSetupInstructions/buildOpenCodeInstructions.ts
+++ b/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/SetupInstructions/fns/agentSetupInstructions/buildOpenCodeInstructions.ts
@@ -51,10 +51,9 @@ export function buildOpenCodeInstructions(
steps: [
{
title: "Export the gateway key",
- description:
- "Replace the placeholder with your gateway key. After changing it, run opencode service restart.",
+ description: "After changing the key, run opencode service restart.",
language: "sh",
- code: `export LANGFUSE_GATEWAY_KEY="${GATEWAY_KEY_PLACEHOLDER}"`,
+ code: ` export LANGFUSE_GATEWAY_KEY="${GATEWAY_KEY_PLACEHOLDER}"`,
},
{
title: "Add the gateway providers",
diff --git a/web/src/features/ai-gateway/components/GatewayApiKeysPage/fns/maskSecretKey.ts b/web/src/features/ai-gateway/components/GatewayApiKeysPage/fns/maskSecretKey.ts
new file mode 100644
index 0000000000..c932bc5c37
--- /dev/null
+++ b/web/src/features/ai-gateway/components/GatewayApiKeysPage/fns/maskSecretKey.ts
@@ -0,0 +1,13 @@
+const SECRET_KEY_PREFIX = "sk-lf-";
+const VISIBLE_CHARACTERS = 4;
+const MASK = "•".repeat(20);
+
+/** Keeps the `sk-lf-` prefix plus the first and last four characters readable. */
+export function maskSecretKey(secretKey: string) {
+ const prefixLength = secretKey.startsWith(SECRET_KEY_PREFIX)
+ ? SECRET_KEY_PREFIX.length
+ : 0;
+ const secretPart = secretKey.slice(prefixLength);
+ if (secretPart.length <= VISIBLE_CHARACTERS * 2) return MASK;
+ return `${secretKey.slice(0, prefixLength + VISIBLE_CHARACTERS)}${MASK}${secretKey.slice(-VISIBLE_CHARACTERS)}`;
+}