Skip to content

Invoke is a leading creative engine that uses image and video generation models to empower professionals, artists, and enthusiasts to generate and create visual media using the latest AI-driven technologies. The solution offers an industry-leading application interface, and serves as the foundation for multiple commercial products.

refactor(ui): split api key cards

Josh Corbettce0e88475341
diff --git a/invokeai/frontend/webv2/src/features/models/ui/credentials/ApiKeysSection.tsx b/invokeai/frontend/webv2/src/features/models/ui/credentials/ApiKeysSection.tsx
index a0419e804d..3e51466ba4 100644
--- a/invokeai/frontend/webv2/src/features/models/ui/credentials/ApiKeysSection.tsx
+++ b/invokeai/frontend/webv2/src/features/models/ui/credentials/ApiKeysSection.tsx
@@ -1,19 +1,13 @@
/* eslint-disable react/react-compiler, react-perf/jsx-no-jsx-as-prop, react-perf/jsx-no-new-array-as-prop, react-perf/jsx-no-new-function-as-prop, react-perf/jsx-no-new-object-as-prop */
import type { HFTokenStatus } from '@features/models/core/types';
+import type { ElementType } from 'react';
-import { Badge, Flex, Grid, HStack, Icon, Input, Stack, Switch, Text } from '@chakra-ui/react';
-import {
- getExternalProviderConfigs,
- getHFTokenStatus,
- resetExternalProviderConfig,
- resetHFToken,
- setExternalProviderConfig,
- setHFToken,
- type ExternalProviderConfig,
-} from '@features/models/data/api';
+import { Grid, HStack, Input, Stack, Text } from '@chakra-ui/react';
+import { getHFTokenStatus, resetHFToken, setHFToken } from '@features/models/data/api';
import { clearCivitaiApiKey, getCivitaiApiKey, setCivitaiApiKey } from '@features/models/data/apiKeys';
-import { refreshInstalls } from '@features/models/data/installsStore';
-import { refreshStartersIfLoaded } from '@features/models/data/startersStore';
+import { ExternalProviderKeyCards } from '@features/models/ui/credentials/ExternalProviderKeyCards';
+import { KeyCardShell, type KeyStatusBadge } from '@features/models/ui/credentials/KeyCardShell';
+import { useScopedAction } from '@features/models/ui/shared/useScopedAction';
import { useNotify } from '@features/models/ui/useModelsNotify';
import { useMountEffect } from '@platform/react/useMountEffect';
import {
@@ -23,10 +17,10 @@ import {
type AccountScope,
} from '@platform/state/accountLifecycle';
import { Button } from '@platform/ui';
-import { BotIcon, HexagonIcon } from 'lucide-react';
-import { useState, type ElementType } from 'react';
+import { HexagonIcon } from 'lucide-react';
+import { useState } from 'react';
import { useTranslation } from 'react-i18next';
-import { SiAlibabacloud, SiBytedance, SiGooglegemini, SiHuggingface } from 'react-icons/si';
+import { SiHuggingface } from 'react-icons/si';
/**
* Credentials for every model source, as one uniform grid of key cards:
@@ -52,11 +46,6 @@ export const ApiKeysSection = () => {
);
};
-interface KeyStatusBadge {
- label: string;
- palette: string;
-}
-
/** The shared card: identical anatomy whether the key is set or not. */
const ApiKeyCard = ({
description,
@@ -84,81 +73,28 @@ const ApiKeyCard = ({
}) => {
const { t } = useTranslation();
const [draft, setDraft] = useState('');
- const [isBusy, setIsBusy] = useState(false);
-
- const runAction = async (
- action: (owner: AccountScope) => Promise<void> | void,
- owner: AccountScope = captureAccountScope()
- ): Promise<boolean> => {
- setIsBusy(true);
-
- try {
- await action(owner);
- assertAccountScopeCurrent(owner);
-
- return true;
- } catch (error) {
- if (!isAccountScopeCurrent(owner)) {
- return false;
- }
-
- onError(error instanceof Error ? error.message : t('common.somethingWentWrong'));
+ const { isBusy, run } = useScopedAction();
- return false;
- } finally {
- if (isAccountScopeCurrent(owner)) {
- setIsBusy(false);
- }
- }
- };
+ const handleActionError = (_message: string, error: unknown) =>
+ onError(error instanceof Error ? error.message : t('common.somethingWentWrong'));
- const handleSave = async () => {
+ const handleSave = () => {
const key = draft.trim();
if (key.length === 0) {
return;
}
- const owner = captureAccountScope();
-
// Keep the draft on failure so the key can be corrected and retried.
- if ((await runAction((actionOwner) => onSave(key, actionOwner), owner)) && isAccountScopeCurrent(owner)) {
+ void run(async (owner) => {
+ await onSave(key, owner);
+ assertAccountScopeCurrent(owner);
setDraft('');
- }
+ }, handleActionError);
};
return (
- <Stack bg="bg.subtle" borderColor="border.subtle" borderWidth="1px" gap="2.5" p="3" rounded="lg">
- <HStack align="start" gap="2.5">
- <Flex
- align="center"
- bg="bg.emphasized"
- borderColor="border.subtle"
- borderWidth="1px"
- boxSize="8"
- color="fg.muted"
- flexShrink={0}
- justify="center"
- rounded="md"
- >
- <Icon as={icon} boxSize="4" />
- </Flex>
- <Stack flex="1" gap="0" minW="0">
- <HStack gap="1.5">
- <Text fontSize="xs" fontWeight="700" truncate>
- {title}
- </Text>
- {status ? (
- <Badge colorPalette={status.palette} flexShrink={0} fontSize="2xs" size="sm" variant="surface">
- {status.label}
- </Badge>
- ) : null}
- </HStack>
- <Text color="fg.subtle" fontSize="2xs" lineClamp={2}>
- {description}
- </Text>
- </Stack>
- </HStack>
+ <KeyCardShell description={description} icon={icon} status={status} title={title}>
<HStack gap="1.5">
<Input
aria-label={t('models.apiKeyFor', { title })}
@@ -171,7 +107,7 @@ const ApiKeyCard = ({
onKeyDown={(event) => {
if (event.key === 'Enter') {
event.preventDefault();
- void handleSave();
+ handleSave();
}
}}
/>
@@ -180,17 +116,26 @@ const ApiKeyCard = ({
loading={isBusy && draft.trim().length > 0}
size="xs"
variant="solid"
- onClick={() => void handleSave()}
+ onClick={handleSave}
>
{t('common.save')}
</Button>
{onClear ? (
- <Button disabled={isBusy || isLoading} size="sm" variant="ghost" onClick={() => void runAction(onClear)}>
+ <Button
+ disabled={isBusy || isLoading}
+ size="sm"
+ variant="ghost"
+ onClick={() =>
+ void run(async (owner) => {
+ await onClear(owner);
+ }, handleActionError)
+ }
+ >
{t('common.clear')}
</Button>
) : null}
</HStack>
- </Stack>
+ </KeyCardShell>
);
};
@@ -290,294 +235,3 @@ const CivitaiKeyCard = ({ onError }: { onError: (message: string) => void }) =>
/>
);
};
-
-const EXTERNAL_PROVIDER_PRESENTATION: Record<string, { title: string; icon: ElementType; placeholder: string }> = {
- alibabacloud: { icon: SiAlibabacloud, placeholder: 'sk-…', title: 'Alibaba Cloud (Qwen)' },
- gemini: { icon: SiGooglegemini, placeholder: 'AIza…', title: 'Google Gemini' },
- openai: { icon: BotIcon, placeholder: 'sk-…', title: 'OpenAI' },
- seedream: { icon: SiBytedance, placeholder: 'byteplus', title: 'Seedream' },
-};
-
-const ExternalProviderKeyCards = ({ onError }: { onError: (title: string, message: string) => void }) => {
- const { t } = useTranslation();
- const [configs, setConfigs] = useState<ExternalProviderConfig[] | null>(null);
- const [loadError, setLoadError] = useState<string | null>(null);
-
- useMountEffect(() => {
- const owner = captureAccountScope();
- let isMounted = true;
-
- getExternalProviderConfigs(owner.signal)
- .then((providerConfigs) => {
- if (isMounted && isAccountScopeCurrent(owner)) {
- setConfigs(providerConfigs);
- }
- })
- .catch((error: unknown) => {
- if (isMounted && isAccountScopeCurrent(owner)) {
- setConfigs([]);
- setLoadError(error instanceof Error ? error.message : t('models.failedToLoadExternalProviders'));
- }
- });
-
- return () => {
- isMounted = false;
- };
- });
-
- const replaceConfig = (next: ExternalProviderConfig) => {
- setConfigs((current) => (current ?? []).map((config) => (config.provider_id === next.provider_id ? next : config)));
- };
-
- if (loadError) {
- return (
- <Text color="fg.error" fontSize="2xs">
- {t('models.externalProvidersUnavailable', { error: loadError })}
- </Text>
- );
- }
-
- return (
- <>
- {(configs ?? []).map((config) => {
- const presentation = EXTERNAL_PROVIDER_PRESENTATION[config.provider_id] ?? {
- icon: HexagonIcon,
- placeholder: 'generic',
- title: config.provider_id,
- };
- const placeholder =
- presentation.placeholder === 'byteplus'
- ? t('models.bytePlusApiKeyPlaceholder')
- : presentation.placeholder === 'generic'
- ? t('models.apiKey')
- : presentation.placeholder;
-
- return (
- <ExternalProviderKeyCard
- config={config}
- key={config.provider_id}
- description={t('models.externalProviderKeyDescription')}
- icon={presentation.icon}
- placeholder={placeholder}
- title={presentation.title}
- onError={(message) => onError(presentation.title, message)}
- onUpdated={replaceConfig}
- />
- );
- })}
- </>
- );
-};
-
-const ExternalProviderKeyCard = ({
- config,
- description,
- icon,
- onError,
- onUpdated,
- placeholder,
- title,
-}: {
- config: ExternalProviderConfig;
- description: string;
- icon: ElementType;
- onError: (message: string) => void;
- onUpdated: (next: ExternalProviderConfig) => void;
- placeholder: string;
- title: string;
-}) => {
- const { t } = useTranslation();
- const [apiKeyDraft, setApiKeyDraft] = useState('');
- const [baseUrlDraft, setBaseUrlDraft] = useState(config.base_url ?? '');
- const [overrideBaseUrl, setOverrideBaseUrl] = useState(config.base_url !== null);
- const [isBusy, setIsBusy] = useState(false);
-
- const hasApiKeyDraft = apiKeyDraft.trim().length > 0;
- const hasBaseUrlChange = overrideBaseUrl ? baseUrlDraft.trim() !== (config.base_url ?? '') : config.base_url !== null;
-
- const runAction = async (
- action: (owner: AccountScope) => Promise<ExternalProviderConfig>,
- onSuccess?: (next: ExternalProviderConfig, owner: AccountScope) => void
- ): Promise<void> => {
- const owner = captureAccountScope();
-
- setIsBusy(true);
-
- try {
- const nextConfig = await action(owner);
-
- assertAccountScopeCurrent(owner);
- onUpdated(nextConfig);
- setApiKeyDraft('');
- setBaseUrlDraft(nextConfig.base_url ?? '');
- setOverrideBaseUrl(nextConfig.base_url !== null);
- onSuccess?.(nextConfig, owner);
- } catch (error) {
- if (!isAccountScopeCurrent(owner)) {
- return;
- }
-
- onError(error instanceof Error ? error.message : t('common.somethingWentWrong'));
- } finally {
- if (isAccountScopeCurrent(owner)) {
- setIsBusy(false);
- }
- }
- };
-
- const handleSave = async () => {
- const apiKey = apiKeyDraft.trim();
- const baseUrl = baseUrlDraft.trim();
- const nextConfig: { api_key?: string; base_url?: string | null } = {};
-
- if (apiKey.length > 0) {
- nextConfig.api_key = apiKey;
- }
-
- if (!overrideBaseUrl && config.base_url !== null) {
- nextConfig.base_url = '';
- } else if (overrideBaseUrl && baseUrl !== (config.base_url ?? '')) {
- nextConfig.base_url = baseUrl;
- }
-
- if (!nextConfig.api_key && nextConfig.base_url === undefined) {
- return;
- }
-
- const apiKeyWasSet = nextConfig.api_key !== undefined;
-
- await runAction(
- (owner) => setExternalProviderConfig(config.provider_id, nextConfig, owner.signal),
- (next, owner) => {
- if (apiKeyWasSet && next.api_key_configured) {
- // The backend queues this provider's external starter models on
- // key-set; pull the new jobs and refresh starters so its rows flip to
- // Installed without an app restart.
- void refreshInstalls(owner);
- refreshStartersIfLoaded();
- }
- }
- );
- };
-
- const canClear = config.api_key_configured || config.base_url !== null;
-
- return (
- <Stack bg="bg.subtle" borderColor="border.subtle" borderWidth="1px" gap="2.5" p="3" rounded="lg">
- <HStack align="start" gap="2.5">
- <Flex
- align="center"
- bg="bg.emphasized"
- borderColor="border.subtle"
- borderWidth="1px"
- boxSize="8"
- color="fg.muted"
- flexShrink={0}
- justify="center"
- rounded="md"
- >
- <Icon as={icon} boxSize="4" />
- </Flex>
- <Stack flex="1" gap="0" minW="0">
- <HStack gap="1.5">
- <Text fontSize="xs" fontWeight="700" truncate>
- {title}
- </Text>
- <Badge
- colorPalette={config.api_key_configured ? 'green' : 'gray'}
- flexShrink={0}
- fontSize="2xs"
- size="sm"
- variant="surface"
- >
- {config.api_key_configured ? t('models.keyStatus.configured') : t('models.keyStatus.unknown')}
- </Badge>
- </HStack>
- <Text color="fg.subtle" fontSize="2xs" lineClamp={2}>
- {description}
- </Text>
- </Stack>
- </HStack>
-
- <Stack gap="2">
- <HStack gap="1.5">
- <Input
- aria-label={t('models.apiKeyFor', { title })}
- disabled={isBusy}
- placeholder={config.api_key_configured ? t('models.apiKeyConfigured') : placeholder}
- size="xs"
- type="password"
- value={apiKeyDraft}
- onChange={(event) => setApiKeyDraft(event.currentTarget.value)}
- onKeyDown={(event) => {
- if (event.key === 'Enter') {
- event.preventDefault();
- void handleSave();
- }
- }}
- />
- </HStack>
- <Switch.Root
- checked={overrideBaseUrl}
- disabled={isBusy}
- size="sm"
- onCheckedChange={(event) => {
- const checked = event.checked === true;
-
- setOverrideBaseUrl(checked);
-
- if (!checked) {
- setBaseUrlDraft('');
- }
- }}
- >
- <Switch.HiddenInput />
- <Switch.Control _checked={{ bg: 'accent.solid' }}>
- <Switch.Thumb />
- </Switch.Control>
- <Switch.Label color="fg.muted" fontSize="2xs">
- {t('models.overrideBaseUrl')}
- </Switch.Label>
- </Switch.Root>
- {overrideBaseUrl ? (
- <Input
- aria-label={t('models.baseUrlFor', { title })}
- disabled={isBusy}
- placeholder="https://api.example.com"
- size="xs"
- value={baseUrlDraft}
- onChange={(event) => setBaseUrlDraft(event.currentTarget.value)}
- onKeyDown={(event) => {
- if (event.key === 'Enter') {
- event.preventDefault();
- void handleSave();
- }
- }}
- />
- ) : null}
- </Stack>
-
- <HStack gap="1.5">
- <Button
- disabled={(!hasApiKeyDraft && !hasBaseUrlChange) || isBusy}
- loading={isBusy}
- size="xs"
- variant="solid"
- onClick={() => void handleSave()}
- >
- {t('common.save')}
- </Button>
- {canClear ? (
- <Button
- disabled={isBusy}
- size="sm"
- variant="ghost"
- onClick={() => void runAction((owner) => resetExternalProviderConfig(config.provider_id, owner.signal))}
- >
- {t('common.clear')}
- </Button>
- ) : null}
- </HStack>
- </Stack>
- );
-};
diff --git a/invokeai/frontend/webv2/src/features/models/ui/credentials/ExternalProviderKeyCards.tsx b/invokeai/frontend/webv2/src/features/models/ui/credentials/ExternalProviderKeyCards.tsx
new file mode 100644
index 0000000000..02d918dade
--- /dev/null
+++ b/invokeai/frontend/webv2/src/features/models/ui/credentials/ExternalProviderKeyCards.tsx
@@ -0,0 +1,255 @@
+import type { ExternalProviderConfig } from '@features/models/data/api';
+/* eslint-disable react-perf/jsx-no-jsx-as-prop, react-perf/jsx-no-new-array-as-prop, react-perf/jsx-no-new-function-as-prop, react-perf/jsx-no-new-object-as-prop */
+import type { ElementType } from 'react';
+
+import { HStack, Input, Stack, Switch, Text } from '@chakra-ui/react';
+import {
+ clearExternalProviderConfig,
+ ensureExternalProvidersLoaded,
+ saveExternalProviderConfig,
+ useExternalProvidersSelector,
+} from '@features/models/data/externalProvidersStore';
+import { refreshInstalls } from '@features/models/data/installsStore';
+import { refreshStartersIfLoaded } from '@features/models/data/startersStore';
+import { KeyCardShell } from '@features/models/ui/credentials/KeyCardShell';
+import { useScopedAction } from '@features/models/ui/shared/useScopedAction';
+import { useMountEffect } from '@platform/react/useMountEffect';
+import { assertAccountScopeCurrent, type AccountScope } from '@platform/state/accountLifecycle';
+import { Button } from '@platform/ui';
+import { BotIcon, HexagonIcon } from 'lucide-react';
+import { useState } from 'react';
+import { useTranslation } from 'react-i18next';
+import { SiAlibabacloud, SiBytedance, SiGooglegemini } from 'react-icons/si';
+
+interface ProviderPresentation {
+ icon: ElementType;
+ /** Literal key-shape hint; `placeholderKey` (an i18n key) wins when set. */
+ placeholder?: string;
+ placeholderKey?: string;
+ title: string;
+}
+
+const EXTERNAL_PROVIDER_PRESENTATION: Record<string, ProviderPresentation> = {
+ alibabacloud: { icon: SiAlibabacloud, placeholder: 'sk-…', title: 'Alibaba Cloud (Qwen)' },
+ gemini: { icon: SiGooglegemini, placeholder: 'AIza…', title: 'Google Gemini' },
+ openai: { icon: BotIcon, placeholder: 'sk-…', title: 'OpenAI' },
+ seedream: { icon: SiBytedance, placeholderKey: 'models.bytePlusApiKeyPlaceholder', title: 'Seedream' },
+};
+
+/** One key card per provider the backend reports, from the shared store. */
+export const ExternalProviderKeyCards = ({ onError }: { onError: (title: string, message: string) => void }) => {
+ const { t } = useTranslation();
+ const configs = useExternalProvidersSelector((snapshot) => snapshot.configs);
+ const loadError = useExternalProvidersSelector((snapshot) => snapshot.error);
+
+ useMountEffect(() => {
+ ensureExternalProvidersLoaded().catch(() => {
+ // The snapshot records the failure; rendered inline below.
+ });
+ });
+
+ if (loadError !== null && (configs === null || configs.length === 0)) {
+ return (
+ <Text color="fg.error" fontSize="2xs">
+ {t('models.externalProvidersUnavailable', { error: loadError })}
+ </Text>
+ );
+ }
+
+ return (
+ <>
+ {(configs ?? []).map((config) => {
+ const presentation = EXTERNAL_PROVIDER_PRESENTATION[config.provider_id] ?? {
+ icon: HexagonIcon,
+ title: config.provider_id,
+ };
+ const placeholder = presentation.placeholderKey
+ ? t(presentation.placeholderKey)
+ : (presentation.placeholder ?? t('models.apiKey'));
+
+ return (
+ <ExternalProviderKeyCard
+ config={config}
+ key={config.provider_id}
+ description={t('models.externalProviderKeyDescription')}
+ icon={presentation.icon}
+ placeholder={placeholder}
+ title={presentation.title}
+ onError={(message) => onError(presentation.title, message)}
+ />
+ );
+ })}
+ </>
+ );
+};
+
+const ExternalProviderKeyCard = ({
+ config,
+ description,
+ icon,
+ onError,
+ placeholder,
+ title,
+}: {
+ config: ExternalProviderConfig;
+ description: string;
+ icon: ElementType;
+ onError: (message: string) => void;
+ placeholder: string;
+ title: string;
+}) => {
+ const { t } = useTranslation();
+ const [apiKeyDraft, setApiKeyDraft] = useState('');
+ const [baseUrlDraft, setBaseUrlDraft] = useState(config.base_url ?? '');
+ const [overrideBaseUrl, setOverrideBaseUrl] = useState(config.base_url !== null);
+ const { isBusy, run } = useScopedAction();
+
+ const hasApiKeyDraft = apiKeyDraft.trim().length > 0;
+ const hasBaseUrlChange = overrideBaseUrl ? baseUrlDraft.trim() !== (config.base_url ?? '') : config.base_url !== null;
+
+ const runProviderAction = (
+ action: () => Promise<ExternalProviderConfig>,
+ onSuccess?: (next: ExternalProviderConfig, owner: AccountScope) => void
+ ): Promise<void> =>
+ run(
+ async (owner) => {
+ const nextConfig = await action();
+
+ assertAccountScopeCurrent(owner);
+ setApiKeyDraft('');
+ setBaseUrlDraft(nextConfig.base_url ?? '');
+ setOverrideBaseUrl(nextConfig.base_url !== null);
+ onSuccess?.(nextConfig, owner);
+ },
+ (_message, error) => onError(error instanceof Error ? error.message : t('common.somethingWentWrong'))
+ );
+
+ const handleSave = async () => {
+ const apiKey = apiKeyDraft.trim();
+ const baseUrl = baseUrlDraft.trim();
+ const nextConfig: { api_key?: string; base_url?: string | null } = {};
+
+ if (apiKey.length > 0) {
+ nextConfig.api_key = apiKey;
+ }
+
+ if (!overrideBaseUrl && config.base_url !== null) {
+ nextConfig.base_url = '';
+ } else if (overrideBaseUrl && baseUrl !== (config.base_url ?? '')) {
+ nextConfig.base_url = baseUrl;
+ }
+
+ if (!nextConfig.api_key && nextConfig.base_url === undefined) {
+ return;
+ }
+
+ const apiKeyWasSet = nextConfig.api_key !== undefined;
+
+ await runProviderAction(
+ () => saveExternalProviderConfig(config.provider_id, nextConfig),
+ (next, owner) => {
+ if (apiKeyWasSet && next.api_key_configured) {
+ // The backend queues this provider's external starter models on
+ // key-set; pull the new jobs and refresh starters so its rows flip to
+ // Installed without an app restart.
+ void refreshInstalls(owner);
+ refreshStartersIfLoaded();
+ }
+ }
+ );
+ };
+
+ const canClear = config.api_key_configured || config.base_url !== null;
+
+ return (
+ <KeyCardShell
+ description={description}
+ icon={icon}
+ status={{
+ label: config.api_key_configured ? t('models.keyStatus.configured') : t('models.keyStatus.unknown'),
+ palette: config.api_key_configured ? 'green' : 'gray',
+ }}
+ title={title}
+ >
+ <Stack gap="2">
+ <HStack gap="1.5">
+ <Input
+ aria-label={t('models.apiKeyFor', { title })}
+ disabled={isBusy}
+ placeholder={config.api_key_configured ? t('models.apiKeyConfigured') : placeholder}
+ size="xs"
+ type="password"
+ value={apiKeyDraft}
+ onChange={(event) => setApiKeyDraft(event.currentTarget.value)}
+ onKeyDown={(event) => {
+ if (event.key === 'Enter') {
+ event.preventDefault();
+ void handleSave();
+ }
+ }}
+ />
+ </HStack>
+ <Switch.Root
+ checked={overrideBaseUrl}
+ disabled={isBusy}
+ size="sm"
+ onCheckedChange={(event) => {
+ const checked = event.checked === true;
+
+ setOverrideBaseUrl(checked);
+
+ if (!checked) {
+ setBaseUrlDraft('');
+ }
+ }}
+ >
+ <Switch.HiddenInput />
+ <Switch.Control _checked={{ bg: 'accent.solid' }}>
+ <Switch.Thumb />
+ </Switch.Control>
+ <Switch.Label color="fg.muted" fontSize="2xs">
+ {t('models.overrideBaseUrl')}
+ </Switch.Label>
+ </Switch.Root>
+ {overrideBaseUrl ? (
+ <Input
+ aria-label={t('models.baseUrlFor', { title })}
+ disabled={isBusy}
+ placeholder="https://api.example.com"
+ size="xs"
+ value={baseUrlDraft}
+ onChange={(event) => setBaseUrlDraft(event.currentTarget.value)}
+ onKeyDown={(event) => {
+ if (event.key === 'Enter') {
+ event.preventDefault();
+ void handleSave();
+ }
+ }}
+ />
+ ) : null}
+ </Stack>
+
+ <HStack gap="1.5">
+ <Button
+ disabled={(!hasApiKeyDraft && !hasBaseUrlChange) || isBusy}
+ loading={isBusy}
+ size="xs"
+ variant="solid"
+ onClick={() => void handleSave()}
+ >
+ {t('common.save')}
+ </Button>
+ {canClear ? (
+ <Button
+ disabled={isBusy}
+ size="sm"
+ variant="ghost"
+ onClick={() => void runProviderAction(() => clearExternalProviderConfig(config.provider_id))}
+ >
+ {t('common.clear')}
+ </Button>
+ ) : null}
+ </HStack>
+ </KeyCardShell>
+ );
+};
diff --git a/invokeai/frontend/webv2/src/features/models/ui/credentials/KeyCardShell.tsx b/invokeai/frontend/webv2/src/features/models/ui/credentials/KeyCardShell.tsx
new file mode 100644
index 0000000000..09bb63257c
--- /dev/null
+++ b/invokeai/frontend/webv2/src/features/models/ui/credentials/KeyCardShell.tsx
@@ -0,0 +1,57 @@
+import type { ElementType, ReactNode } from 'react';
+
+import { Badge, Flex, HStack, Icon, Stack, Text } from '@chakra-ui/react';
+
+export interface KeyStatusBadge {
+ label: string;
+ palette: string;
+}
+
+/** Shared chrome for credential cards: icon tile, title + status badge, description, body. */
+export const KeyCardShell = ({
+ children,
+ description,
+ icon,
+ status,
+ title,
+}: {
+ children: ReactNode;
+ description: string;
+ icon: ElementType;
+ status: KeyStatusBadge | null;
+ title: string;
+}) => (
+ <Stack bg="bg.subtle" borderColor="border.subtle" borderWidth="1px" gap="2.5" p="3" rounded="lg">
+ <HStack align="start" gap="2.5">
+ <Flex
+ align="center"
+ bg="bg.emphasized"
+ borderColor="border.subtle"
+ borderWidth="1px"
+ boxSize="8"
+ color="fg.muted"
+ flexShrink={0}
+ justify="center"
+ rounded="md"
+ >
+ <Icon as={icon} boxSize="4" />
+ </Flex>
+ <Stack flex="1" gap="0" minW="0">
+ <HStack gap="1.5">
+ <Text fontSize="xs" fontWeight="700" truncate>
+ {title}
+ </Text>
+ {status ? (
+ <Badge colorPalette={status.palette} flexShrink={0} fontSize="2xs" size="sm" variant="surface">
+ {status.label}
+ </Badge>
+ ) : null}
+ </HStack>
+ <Text color="fg.subtle" fontSize="2xs" lineClamp={2}>
+ {description}
+ </Text>
+ </Stack>
+ </HStack>
+ {children}
+ </Stack>
+);