Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Studio: copy a usable API key prefix, and show a new key from its start (#11652)
Michael Han49752f69e254
diff --git a/studio/frontend/src/features/settings/components/api-key-row.tsx b/studio/frontend/src/features/settings/components/api-key-row.tsxindex 9bfe42becf5..46243ba3309 100644--- a/studio/frontend/src/features/settings/components/api-key-row.tsx+++ b/studio/frontend/src/features/settings/components/api-key-row.tsx@@ -10,6 +10,7 @@ import {} from "@/components/ui/dropdown-menu";import { type Locale, formatRelativeTime, useLocale, useT } from "@/i18n";import { copyToClipboard } from "@/lib/copy-to-clipboard";+import { toast } from "@/lib/toast";import {Copy01Icon,Delete02Icon,@@ -56,7 +57,8 @@ export function ApiKeyRow({}) {const t = useT();const locale = useLocale();- const prefix = `sk-unsloth-${apiKey.key_prefix}…`;+ // The ellipsis is display only; a copied prefix must not carry it.+ const prefix = `sk-unsloth-${apiKey.key_prefix}`;return (<div className="group flex items-center gap-3 border-b border-border/60 px-1 py-3 last:border-b-0 transition-colors hover:bg-accent/40"><span@@ -69,7 +71,7 @@ export function ApiKeyRow({{apiKey.name}</span><code className="shrink-0 font-mono text-ui-11 text-muted-foreground">- {prefix}+ {prefix}…</code></div><div className="flex flex-wrap gap-x-1.5 text-ui-11 text-muted-foreground">@@ -104,7 +106,15 @@ export function ApiKeyRow({</Button></DropdownMenuTrigger><DropdownMenuContent align="end">- <DropdownMenuItem onClick={async () => { await copyToClipboard(prefix); }}>+ <DropdownMenuItem+ onClick={async () => {+ if (await copyToClipboard(prefix)) {+ toast.success(t("settings.apiKeys.copied"));+ } else {+ toast.error(t("settings.apiKeys.copyFailed"));+ }+ }}+ ><HugeiconsIcon icon={Copy01Icon} className="size-3.5 mr-2" />{t("settings.apiKeys.copyPrefix")}</DropdownMenuItem>diff --git a/studio/frontend/src/features/settings/components/key-reveal-card.tsx b/studio/frontend/src/features/settings/components/key-reveal-card.tsxindex 08a4fb8139f..f9bd88bd162 100644--- a/studio/frontend/src/features/settings/components/key-reveal-card.tsx+++ b/studio/frontend/src/features/settings/components/key-reveal-card.tsx@@ -11,8 +11,11 @@ import { HugeiconsIcon } from "@hugeicons/react";import { useEffect, useRef, useState } from "react";function selectToken(input: HTMLInputElement | null) {- input?.focus();- input?.select();+ if (!input) return;+ input.focus();+ input.select();+ // select() scrolls to the end; keep the sk-unsloth- start in view.+ input.scrollLeft = 0;}export function KeyRevealCard({@@ -63,7 +66,7 @@ export function KeyRevealCard({type="text"readOnly={true}value={rawKey}- onFocus={(event) => event.currentTarget.select()}+ onFocus={(event) => selectToken(event.currentTarget)}aria-label={t("settings.apiKeys.newTokenCreated")}className="min-w-0 flex-1 bg-transparent text-foreground outline-none"data-reload-snapshot-sensitive={true}diff --git a/studio/frontend/src/i18n/locales/ar.ts b/studio/frontend/src/i18n/locales/ar.tsindex 515ca526349..d2ff9a7fa9c 100644--- a/studio/frontend/src/i18n/locales/ar.ts+++ b/studio/frontend/src/i18n/locales/ar.ts@@ -1973,6 +1973,7 @@ export const ar = {expires: "الانتهاء: {value}",actionsFor: "إجراءات {name}",copyPrefix: "نسخ البادئة",+ copyFailed: "تعذّر النسخ",revokeToken: "إلغاء التوكن",revokeTitle: 'إلغاء توكن الوصول "{name}"؟',revokeDescription:diff --git a/studio/frontend/src/i18n/locales/de.ts b/studio/frontend/src/i18n/locales/de.tsindex a3d34a43b58..b879fcac99b 100644--- a/studio/frontend/src/i18n/locales/de.ts+++ b/studio/frontend/src/i18n/locales/de.ts@@ -2017,6 +2017,7 @@ export const de = {expires: "Läuft {value} ab",actionsFor: "Aktionen für {name}",copyPrefix: "Präfix kopieren",+ copyFailed: "Kopieren fehlgeschlagen",revokeToken: "Token widerrufen",revokeTitle: "Zugriffstoken „{name}“ widerrufen?",revokeDescription:diff --git a/studio/frontend/src/i18n/locales/en.ts b/studio/frontend/src/i18n/locales/en.tsindex 52e451305e6..8923093bf00 100644--- a/studio/frontend/src/i18n/locales/en.ts+++ b/studio/frontend/src/i18n/locales/en.ts@@ -1964,6 +1964,7 @@ export const en = {expires: "Expires {value}",actionsFor: "Actions for {name}",copyPrefix: "Copy prefix",+ copyFailed: "Could not copy",revokeToken: "Revoke token",revokeTitle: 'Revoke access token "{name}"?',revokeDescription:diff --git a/studio/frontend/src/i18n/locales/es.ts b/studio/frontend/src/i18n/locales/es.tsindex bc2eda16f25..91207070a45 100644--- a/studio/frontend/src/i18n/locales/es.ts+++ b/studio/frontend/src/i18n/locales/es.ts@@ -2008,6 +2008,7 @@ export const es = {expires: "Caduca {value}",actionsFor: "Acciones para {name}",copyPrefix: "Copiar prefijo",+ copyFailed: "No se pudo copiar",revokeToken: "Revocar token",revokeTitle: '¿Revocar el token de acceso "{name}"?',revokeDescription:diff --git a/studio/frontend/src/i18n/locales/fr.ts b/studio/frontend/src/i18n/locales/fr.tsindex 5e4b67d566b..390c3460477 100644--- a/studio/frontend/src/i18n/locales/fr.ts+++ b/studio/frontend/src/i18n/locales/fr.ts@@ -2018,6 +2018,7 @@ export const fr = {expires: "Expire {value}",actionsFor: "Actions pour {name}",copyPrefix: "Copier le préfixe",+ copyFailed: "Impossible de copier",revokeToken: "Révoquer le jeton",revokeTitle: "Révoquer le jeton d’accès « {name} » ?",revokeDescription:diff --git a/studio/frontend/src/i18n/locales/hi.ts b/studio/frontend/src/i18n/locales/hi.tsindex 18f20aefcf4..24ba3cb2f5e 100644--- a/studio/frontend/src/i18n/locales/hi.ts+++ b/studio/frontend/src/i18n/locales/hi.ts@@ -1979,6 +1979,7 @@ export const hi = {expires: "समाप्त होता है {value}",actionsFor: "{name} के लिए कार्रवाइयां",copyPrefix: "प्रीफ़िक्स कॉपी करें",+ copyFailed: "कॉपी नहीं हो सका",revokeToken: "टोकन रद्द करें",revokeTitle: "क्या “{name}” एक्सेस टोकन रद्द करें?",revokeDescription:diff --git a/studio/frontend/src/i18n/locales/it.ts b/studio/frontend/src/i18n/locales/it.tsindex b91f95815cc..a43934f1b5b 100644--- a/studio/frontend/src/i18n/locales/it.ts+++ b/studio/frontend/src/i18n/locales/it.ts@@ -1983,6 +1983,7 @@ export const it = {expires: "Scadenza: {value}",actionsFor: "Azioni per {name}",copyPrefix: "Copia il prefisso",+ copyFailed: "Impossibile copiare",revokeToken: "Revoca il token",revokeTitle: "Revocare il token di accesso «{name}»?",revokeDescription:diff --git a/studio/frontend/src/i18n/locales/ja.ts b/studio/frontend/src/i18n/locales/ja.tsindex c0dd43da4e7..8f0a1b6c640 100644--- a/studio/frontend/src/i18n/locales/ja.ts+++ b/studio/frontend/src/i18n/locales/ja.ts@@ -1944,6 +1944,7 @@ export const ja = {expires: "有効期限 {value}",actionsFor: "{name} のアクション",copyPrefix: "プレフィックスをコピー",+ copyFailed: "コピーできませんでした",revokeToken: "トークンを失効",revokeTitle: 'アクセストークン "{name}" を失効させますか?',revokeDescription: "このトークンを使用しているアプリはすぐにアクセスできなくなります。この操作は取り消せません。",diff --git a/studio/frontend/src/i18n/locales/ko.ts b/studio/frontend/src/i18n/locales/ko.tsindex 12768258cdb..cdf9ed192e0 100644--- a/studio/frontend/src/i18n/locales/ko.ts+++ b/studio/frontend/src/i18n/locales/ko.ts@@ -1966,6 +1966,7 @@ export const ko = {expires: "만료: {value}",actionsFor: "{name} 작업",copyPrefix: "접두사 복사",+ copyFailed: "복사할 수 없습니다",revokeToken: "토큰 폐기",revokeTitle: '액세스 토큰 "{name}"을 폐기하시겠습니까?',revokeDescription:diff --git a/studio/frontend/src/i18n/locales/pt-br.ts b/studio/frontend/src/i18n/locales/pt-br.tsindex 7a6ee2322d6..d76de5deb42 100644--- a/studio/frontend/src/i18n/locales/pt-br.ts+++ b/studio/frontend/src/i18n/locales/pt-br.ts@@ -1989,6 +1989,7 @@ export const ptBR = {expires: "Expira {value}",actionsFor: "Ações para {name}",copyPrefix: "Copiar prefixo",+ copyFailed: "Não foi possível copiar",revokeToken: "Revogar token",revokeTitle: 'Revogar token de acesso "{name}"?',revokeDescription:diff --git a/studio/frontend/src/i18n/locales/ru.ts b/studio/frontend/src/i18n/locales/ru.tsindex ac99b1963f0..fc5a01fb6f4 100644--- a/studio/frontend/src/i18n/locales/ru.ts+++ b/studio/frontend/src/i18n/locales/ru.ts@@ -1986,6 +1986,7 @@ export const ru = {expires: "Срок действия: {value}",actionsFor: "Действия для {name}",copyPrefix: "Копировать префикс",+ copyFailed: "Не удалось скопировать",revokeToken: "Отозвать токен",revokeTitle: 'Отозвать токен доступа «{name}»?',revokeDescription:diff --git a/studio/frontend/src/i18n/locales/zh-CN.ts b/studio/frontend/src/i18n/locales/zh-CN.tsindex 648c0669f91..6f12ec93bb2 100644--- a/studio/frontend/src/i18n/locales/zh-CN.ts+++ b/studio/frontend/src/i18n/locales/zh-CN.ts@@ -1923,6 +1923,7 @@ export const zhCN = {expires: "过期时间:{value}",actionsFor: "{name} 的操作",copyPrefix: "复制前缀",+ copyFailed: "无法复制",revokeToken: "撤销 token",revokeTitle: "撤销访问 token“{name}”?",revokeDescription:diff --git a/studio/frontend/tests/api-key-copy.test.ts b/studio/frontend/tests/api-key-copy.test.tsnew file mode 100644index 00000000000..16a4844dae0--- /dev/null+++ b/studio/frontend/tests/api-key-copy.test.ts@@ -0,0 +1,41 @@+// SPDX-License-Identifier: AGPL-3.0-only+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++import assert from "node:assert/strict";+import test from "node:test";++import { readSrc } from "./helpers/kit.ts";++const ROW = readSrc("features/settings/components/api-key-row.tsx");+const REVEAL = readSrc("features/settings/components/key-reveal-card.tsx");++test("a copied key prefix carries no display ellipsis", () => {+ // The row used to copy "sk-unsloth-abcd1234…", which no client accepts.+ assert.match(ROW, /const prefix = `sk-unsloth-\$\{apiKey\.key_prefix\}`;/);+ assert.match(+ ROW,+ /\{prefix\}…\s*<\/code>/,+ "the row no longer shows the ellipsis",+ );+ assert.match(ROW, /copyToClipboard\(prefix\)/);+});++test("copying a key prefix says whether it worked", () => {+ // The menu closes on select, so a toast is the only feedback there is.+ assert.match(ROW, /toast\.success\(t\("settings\.apiKeys\.copied"\)\)/);+ assert.match(ROW, /toast\.error\(t\("settings\.apiKeys\.copyFailed"\)\)/);+});++test("a new key opens showing its start, fully selected", () => {+ // select() scrolls a long key to its end, hiding the sk-unsloth- start.+ assert.match(+ REVEAL,+ /input\.select\(\);[\s\S]*?input\.scrollLeft = 0;/,+ "the key opens scrolled to its end",+ );+ // Refocusing the field selects it the same way.+ assert.match(+ REVEAL,+ /onFocus=\{\(event\) => selectToken\(event\.currentTarget\)\}/,+ );+});