Skip to content

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

feat(ai-gateway): describe gateway keys inline and invite people from the keys page (#19310)

Tobias Wochinger8aedbccf805d
diff --git a/web/src/features/ai-gateway/components/GatewayApiKeysPage/GatewayApiKeysPage.tsx b/web/src/features/ai-gateway/components/GatewayApiKeysPage/GatewayApiKeysPage.tsx
index 71d116ce6d..33b4760a46 100644
--- a/web/src/features/ai-gateway/components/GatewayApiKeysPage/GatewayApiKeysPage.tsx
+++ b/web/src/features/ai-gateway/components/GatewayApiKeysPage/GatewayApiKeysPage.tsx
@@ -1,10 +1,12 @@
/* eslint-disable @typescript-eslint/no-use-before-define */
import Header from "@/src/components/layouts/header";
-import { InfoTooltip } from "@/src/components/ui/InfoTooltip/InfoTooltip";
+import { Button } from "@/src/components/design-system/Button/Button";
import { Skeleton } from "@/src/components/ui/skeleton";
import { GatewayNotSetUpNotice } from "@/src/features/ai-gateway/components/GatewayNotSetUpNotice/GatewayNotSetUpNotice";
+import { GATEWAY_API_KEYS_DOCS_URL } from "@/src/features/ai-gateway/constants/gatewayDocsUrls";
import { useGatewaySettingsAccess } from "@/src/features/ai-gateway/hooks/useGatewaySettingsAccess";
-import { ConnectedGatewayApiKeysTable } from "./components/GatewayApiKeysTable/ConnectedGatewayApiKeysTable";
+import { useHasOrganizationAccess } from "@/src/features/rbac";
+import { ConnectedGatewayApiKeysTable } from "@/src/features/ai-gateway/components/GatewayApiKeysPage/components/GatewayApiKeysTable/ConnectedGatewayApiKeysTable";
export function GatewayApiKeysPage({
organizationId,
@@ -13,6 +15,10 @@ export function GatewayApiKeysPage({
}) {
const { canManageGateway, isIngestionConfigured, isSetupStatusPending } =
useGatewaySettingsAccess(organizationId);
+ const canInviteMembers = useHasOrganizationAccess({
+ organizationId,
+ scope: "organizationMembers:CUD",
+ });
if (isSetupStatusPending) {
return <ApiKeysSkeleton />;
@@ -23,17 +29,23 @@ export function GatewayApiKeysPage({
}
return (
<div className="flex flex-col gap-4">
- <div className="flex items-center gap-1">
- <Header title="Gateway API keys" className="mb-0!" />
- <InfoTooltip label="About gateway API keys">
+ <div>
+ <Header title="Gateway API keys" />
+ <p className="text-muted-foreground text-sm">
{canManageGateway
- ? "These organization keys authenticate requests to the AI Gateway only. Each key belongs to the member who created it and is revoked when they leave the organization."
- : "Your keys authenticate requests to the AI Gateway only. They are revoked when you leave the organization or lose gateway access."}
- </InfoTooltip>
+ ? "Keys authenticate requests to the AI Gateway only. User keys are revoked when their owner leaves the organization; service account keys keep working."
+ : "Your keys authenticate requests to the AI Gateway only. They are revoked when you leave the organization or lose gateway access."}{" "}
+ <Button
+ variant="text"
+ text="How gateway keys work"
+ href={GATEWAY_API_KEYS_DOCS_URL}
+ />
+ </p>
</div>
<ConnectedGatewayApiKeysTable
key={organizationId}
organizationId={organizationId}
+ canInvite={canManageGateway && canInviteMembers}
/>
</div>
);
diff --git a/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/GatewayApiKeysTable/ConnectedGatewayApiKeysTable.tsx b/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/GatewayApiKeysTable/ConnectedGatewayApiKeysTable.tsx
index a690648a0b..57536e2960 100644
--- a/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/GatewayApiKeysTable/ConnectedGatewayApiKeysTable.tsx
+++ b/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/GatewayApiKeysTable/ConnectedGatewayApiKeysTable.tsx
@@ -4,6 +4,7 @@ import { keepPreviousData } from "@tanstack/react-query";
import { Alert } from "@/src/components/design-system/Alert/Alert";
import { Button } from "@/src/components/ui/button";
import { CreateGatewayApiKeyDialogController } from "@/src/features/ai-gateway/components/GatewayApiKeysPage/components/CreateGatewayApiKeyDialogController/CreateGatewayApiKeyDialogController";
+import { TeamInviteDialogController } from "@/src/features/ai-gateway/components/GatewayApiKeysPage/components/TeamInviteDialogController/TeamInviteDialogController";
import { ConfirmationDialogController } from "@/src/components/design-system/ConfirmationDialogController/ConfirmationDialogController";
import { usePaginationState } from "@/src/hooks/usePaginationState";
import { api } from "@/src/utils/api";
@@ -11,8 +12,11 @@ import { GatewayApiKeysTable } from "./GatewayApiKeysTable";
export function ConnectedGatewayApiKeysTable({
organizationId,
+ canInvite,
}: {
organizationId: string;
+ /** Owners and admins only: inviting needs gateway management and member management. */
+ canInvite: boolean;
}) {
const [paginationState, setPaginationState] = usePaginationState(0, 10, {
page: "pageIndex",
@@ -79,31 +83,41 @@ export function ConnectedGatewayApiKeysTable({
}}
>
{({ openDialog: openRevokeDialog }) => (
- <CreateGatewayApiKeyDialogController organizationId={organizationId}>
- {({ openDialog }) => {
- return (
- <GatewayApiKeysTable
- data={
- apiKeysQuery.isPending
- ? { status: "loading" }
- : {
- status: "success",
- data: apiKeysQuery.data.data,
- }
- }
- pagination={{
- mode: "offset",
- totalCount: apiKeysQuery.data?.totalCount ?? null,
- state: paginationState,
- onChange: setPaginationState,
- }}
- search={{ value: searchQuery, onChange: handleSearchChange }}
- createAction={openDialog}
- onRevoke={openRevokeDialog}
- />
- );
- }}
- </CreateGatewayApiKeyDialogController>
+ <TeamInviteDialogController organizationId={organizationId}>
+ {({ openDialog: openInviteDialog }) => (
+ <CreateGatewayApiKeyDialogController
+ organizationId={organizationId}
+ >
+ {({ openDialog }) => {
+ return (
+ <GatewayApiKeysTable
+ data={
+ apiKeysQuery.isPending
+ ? { status: "loading" }
+ : {
+ status: "success",
+ data: apiKeysQuery.data.data,
+ }
+ }
+ pagination={{
+ mode: "offset",
+ totalCount: apiKeysQuery.data?.totalCount ?? null,
+ state: paginationState,
+ onChange: setPaginationState,
+ }}
+ search={{
+ value: searchQuery,
+ onChange: handleSearchChange,
+ }}
+ createAction={openDialog}
+ inviteAction={canInvite ? openInviteDialog : undefined}
+ onRevoke={openRevokeDialog}
+ />
+ );
+ }}
+ </CreateGatewayApiKeyDialogController>
+ )}
+ </TeamInviteDialogController>
)}
</ConfirmationDialogController>
);
diff --git a/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/GatewayApiKeysTable/GatewayApiKeysTable.tsx b/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/GatewayApiKeysTable/GatewayApiKeysTable.tsx
index 88d431aab2..6e39b9859f 100644
--- a/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/GatewayApiKeysTable/GatewayApiKeysTable.tsx
+++ b/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/GatewayApiKeysTable/GatewayApiKeysTable.tsx
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/no-use-before-define */
-import { Plus, Trash } from "@langfuse/icons";
+import { Plus, Trash, UserPlus } from "@langfuse/icons";
import { SettingsTable } from "@/src/components/SettingsTable/SettingsTable";
import type { PaginationBarProps } from "@/src/components/design-system/PaginationBar/PaginationBar";
@@ -9,7 +9,6 @@ import { createTextTableColumn } from "@/src/components/design-system/table/colu
import { createUserTableColumn } from "@/src/components/design-system/table/columns/createUserTableColumn";
import type { AsyncTableData } from "@/src/components/design-system/table/Table";
import type { LangfuseColumnDef } from "@/src/components/table/types";
-import { GATEWAY_API_KEYS_DOCS_URL } from "@/src/features/ai-gateway/constants/gatewayDocsUrls";
import { isApiKeyExpired } from "@/src/features/apiKey";
type GatewayApiKey = {
@@ -32,12 +31,15 @@ type GatewayApiKey = {
export function GatewayApiKeysTable({
data,
createAction,
+ inviteAction,
onRevoke,
pagination,
search,
}: {
data: AsyncTableData<GatewayApiKey[]>;
createAction: () => void;
+ /** Omit for callers who cannot invite people to the organization. */
+ inviteAction?: () => void;
onRevoke: (apiKeyId: string) => void;
pagination: PaginationBarProps;
search: { value: string; onChange: (value: string) => void };
@@ -109,12 +111,17 @@ export function GatewayApiKeysTable({
pagination={pagination}
search={{ ...search, placeholder: "Search by name or user" }}
toolbarActions={[
- {
- id: "docs",
- label: "Docs",
- variant: "secondary",
- href: GATEWAY_API_KEYS_DOCS_URL,
- },
+ ...(inviteAction
+ ? [
+ {
+ id: "invite",
+ label: "Invite",
+ variant: "outline" as const,
+ icon: <UserPlus size="base" aria-hidden="true" />,
+ onClick: inviteAction,
+ },
+ ]
+ : []),
{
id: "create-key",
label: "Create key",
diff --git a/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/TeamInviteDialogController/TeamInviteDialogController.tsx b/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/TeamInviteDialogController/TeamInviteDialogController.tsx
new file mode 100644
index 0000000000..0c36455b88
--- /dev/null
+++ b/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/TeamInviteDialogController/TeamInviteDialogController.tsx
@@ -0,0 +1,61 @@
+import type { ReactNode } from "react";
+
+import { DialogController } from "@/src/components/design-system/DialogController/DialogController";
+import {
+ api,
+ reportNonTrpcError,
+ reportTrpcErrorWithoutToast,
+} from "@/src/utils/api";
+import { TeamInviteDialog } from "@/src/features/ai-gateway/components/GatewayApiKeysPage/components/TeamInviteDialogController/components/TeamInviteDialog";
+import { showInviteOutcome } from "@/src/features/ai-gateway/components/GatewayApiKeysPage/components/TeamInviteDialogController/fns/showInviteOutcome";
+
+export function TeamInviteDialogController({
+ organizationId,
+ children,
+}: {
+ organizationId: string;
+ children: (control: { openDialog: () => void }) => ReactNode;
+}) {
+ const invite = api.aiGateway.inviteTeam.useMutation({
+ onError: (error) =>
+ reportTrpcErrorWithoutToast(error, "ai-gateway-team-invite"),
+ });
+
+ async function handleInvite(emails: string[]) {
+ try {
+ const result = await invite.mutateAsync({
+ orgId: organizationId,
+ emails,
+ notifyMembers: false,
+ });
+ if (result.failed.length === 0) showInviteOutcome(result);
+ return result.failed;
+ } catch (error) {
+ reportNonTrpcError(error, "ai-gateway-team-invite");
+ return null;
+ }
+ }
+
+ return (
+ <DialogController
+ onBeforeClose={() => !invite.isPending}
+ renderDialog={({ closeDialog }) => (
+ <TeamInviteDialog
+ isInviting={invite.isPending}
+ errorMessage={invite.error?.message}
+ onInvite={handleInvite}
+ onInvited={closeDialog}
+ />
+ )}
+ >
+ {({ openDialog }) =>
+ children({
+ openDialog: () => {
+ invite.reset();
+ openDialog();
+ },
+ })
+ }
+ </DialogController>
+ );
+}
diff --git a/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/TeamInviteDialogController/components/TeamInviteDialog.tsx b/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/TeamInviteDialogController/components/TeamInviteDialog.tsx
new file mode 100644
index 0000000000..5db7ad05f1
--- /dev/null
+++ b/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/TeamInviteDialogController/components/TeamInviteDialog.tsx
@@ -0,0 +1,71 @@
+import { Alert } from "@/src/components/design-system/Alert/Alert";
+import { Dialog } from "@/src/components/design-system/Dialog/Dialog";
+import { TeamInviteFailuresAlert } from "@/src/features/ai-gateway/components/TeamInviteFailuresAlert";
+import { TeamInviteFields } from "@/src/features/ai-gateway/components/TeamInviteFields/TeamInviteFields";
+import { useTeamInviteEmails } from "@/src/features/ai-gateway/hooks/useTeamInviteEmails";
+import type { TeamInviteFailure } from "@/src/features/ai-gateway/types/teamInviteFailure";
+
+export type TeamInviteDialogProps = {
+ isInviting: boolean;
+ errorMessage: string | undefined;
+ /** Resolves to the addresses that were not invited, or null when the request failed. */
+ onInvite: (emails: string[]) => Promise<TeamInviteFailure[] | null>;
+ /** Called once no address failed. */
+ onInvited: () => void;
+};
+
+export function TeamInviteDialog({
+ isInviting,
+ errorMessage,
+ onInvite,
+ onInvited,
+}: TeamInviteDialogProps) {
+ const invitees = useTeamInviteEmails();
+
+ async function handleSend() {
+ invitees.startAttempt();
+ const failed = await onInvite(invitees.emails);
+ if (!failed) return;
+ if (failed.length === 0) {
+ onInvited();
+ return;
+ }
+ invitees.keepFailed(failed);
+ }
+
+ return (
+ <Dialog
+ title="Invite people"
+ actions={[
+ {
+ label: "Send invites",
+ loading: isInviting,
+ disabled:
+ isInviting || invitees.emails.length === 0 || !invitees.isValid,
+ onClick: handleSend,
+ },
+ ]}
+ >
+ <Dialog.Body>
+ <p className="text-muted-foreground">
+ Invite people to the organization. They can create their own gateway
+ keys.
+ </p>
+ <TeamInviteFields
+ emails={invitees.emails}
+ onEmailsChange={invitees.setEmails}
+ errorMessage={invitees.errorMessage}
+ />
+ {errorMessage ? (
+ <Alert variant="destructive">
+ <Alert.Title>Invitations could not be sent</Alert.Title>
+ <Alert.Description>{errorMessage}</Alert.Description>
+ </Alert>
+ ) : null}
+ {invitees.failures.length > 0 ? (
+ <TeamInviteFailuresAlert failures={invitees.failures} />
+ ) : null}
+ </Dialog.Body>
+ </Dialog>
+ );
+}
diff --git a/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/TeamInviteDialogController/fns/showInviteOutcome.ts b/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/TeamInviteDialogController/fns/showInviteOutcome.ts
new file mode 100644
index 0000000000..3915b622cd
--- /dev/null
+++ b/web/src/features/ai-gateway/components/GatewayApiKeysPage/components/TeamInviteDialogController/fns/showInviteOutcome.ts
@@ -0,0 +1,22 @@
+import { showSuccessToast, showToast } from "@/src/features/notifications";
+import type { RouterOutputs } from "@/src/utils/api";
+
+/** The server silently skips the caller's own address, and members it cannot email. */
+export function showInviteOutcome({
+ invitedCount,
+ notifiedCount,
+}: RouterOutputs["aiGateway"]["inviteTeam"]) {
+ if (invitedCount + notifiedCount === 0) {
+ showToast({
+ type: "INFO",
+ analytics: { operation: "aiGateway.inviteTeam" },
+ title: "No invitations sent: everyone you entered is already a member.",
+ });
+ return;
+ }
+ showSuccessToast({
+ operation: "aiGateway.inviteTeam",
+ title: "Invitations sent",
+ description: "Invited people can create gateway keys once they join.",
+ });
+}
diff --git a/web/src/features/ai-gateway/components/GatewaySetupPage/components/GatewaySetupGuide/components/TeamInviteStep/components/TeamInviteForm/TeamInviteForm.tsx b/web/src/features/ai-gateway/components/GatewaySetupPage/components/GatewaySetupGuide/components/TeamInviteStep/components/TeamInviteForm/TeamInviteForm.tsx
index ae5d38f9ef..e190c14246 100644
--- a/web/src/features/ai-gateway/components/GatewaySetupPage/components/GatewaySetupGuide/components/TeamInviteStep/components/TeamInviteForm/TeamInviteForm.tsx
+++ b/web/src/features/ai-gateway/components/GatewaySetupPage/components/GatewaySetupGuide/components/TeamInviteStep/components/TeamInviteForm/TeamInviteForm.tsx
@@ -1,14 +1,13 @@
import { useState } from "react";
-import { z } from "zod/v4";
-import { Alert } from "@/src/components/design-system/Alert/Alert";
import { Button } from "@/src/components/design-system/Button/Button";
-import { MAX_TEAM_INVITES } from "@/src/features/ai-gateway/constants/gatewayTeamInvites";
-import { TeamInviteFields } from "@/src/features/ai-gateway/components/GatewaySetupPage/components/GatewaySetupGuide/components/TeamInviteStep/components/TeamInviteForm/components/TeamInviteFields/TeamInviteFields";
+import { TeamInviteFailuresAlert } from "@/src/features/ai-gateway/components/TeamInviteFailuresAlert";
+import { TeamInviteFields } from "@/src/features/ai-gateway/components/TeamInviteFields/TeamInviteFields";
import type {
GatewayNotifiableMembers,
GatewayTeamInviteResult,
} from "@/src/features/ai-gateway/components/GatewaySetupPage/types/gatewaySetup";
+import { useTeamInviteEmails } from "@/src/features/ai-gateway/hooks/useTeamInviteEmails";
export type TeamInviteFormProps = {
/** Undefined while loading. */
@@ -34,11 +33,8 @@ export function TeamInviteForm({
onInvite,
onFinish,
}: TeamInviteFormProps) {
- const [emails, setEmails] = useState<string[]>([]);
+ const invitees = useTeamInviteEmails();
const [notifyMembers, setNotifyMembers] = useState(true);
- const [failures, setFailures] = useState<
- Array<{ email: string; message: string }>
- >([]);
// Retrying failed invites must not announce the gateway to every member again.
const [haveMembersBeenNotified, setHaveMembersBeenNotified] = useState(false);
@@ -48,19 +44,18 @@ export function TeamInviteForm({
notifiableMembers.isEmailConfigured &&
notifiableMembers.count > 0;
const willNotify = canNotify && notifyMembers;
- const hasInvalidEmail = emails.some(
- (email) => !z.email().safeParse(email).success,
- );
- const hasTooManyEmails = emails.length > MAX_TEAM_INVITES;
- const sendLabel = getSendLabel(emails.length);
+ const sendLabel = getSendLabel(invitees.emails.length);
async function handleSend() {
- const result = await onInvite({ emails, notifyMembers: willNotify });
+ invitees.startAttempt();
+ const result = await onInvite({
+ emails: invitees.emails,
+ notifyMembers: willNotify,
+ });
if (!result) return;
if (willNotify) setHaveMembersBeenNotified(true);
if (result.failed.length > 0) {
- setFailures(result.failed);
- setEmails(result.failed.map((failure) => failure.email));
+ invitees.keepFailed(result.failed);
return;
}
onFinish();
@@ -69,13 +64,9 @@ export function TeamInviteForm({
return (
<div className="flex flex-col gap-4 pt-1">
<TeamInviteFields
- emails={emails}
- onEmailsChange={setEmails}
- errorMessage={
- hasTooManyEmails
- ? `You can invite up to ${MAX_TEAM_INVITES} people at once.`
- : undefined
- }
+ emails={invitees.emails}
+ onEmailsChange={invitees.setEmails}
+ errorMessage={invitees.errorMessage}
notifyMembers={
canNotify
? {
@@ -87,28 +78,15 @@ export function TeamInviteForm({
: undefined
}
/>
- {failures.length > 0 ? (
- <Alert variant="destructive">
- <Alert.Title>Some invitations were not sent</Alert.Title>
- <Alert.Description>
- <ul className="ph-no-capture">
- {failures.map((failure) => (
- <li key={failure.email}>
- {failure.email}: {failure.message}
- </li>
- ))}
- </ul>
- </Alert.Description>
- </Alert>
+ {invitees.failures.length > 0 ? (
+ <TeamInviteFailuresAlert failures={invitees.failures} />
) : null}
<div className="flex items-center gap-2">
<Button
text={sendLabel}
loading={isInviting}
disabled={
- hasInvalidEmail ||
- hasTooManyEmails ||
- (emails.length === 0 && !willNotify)
+ !invitees.isValid || (invitees.emails.length === 0 && !willNotify)
}
onClick={handleSend}
/>
diff --git a/web/src/features/ai-gateway/components/TeamInviteFailuresAlert.tsx b/web/src/features/ai-gateway/components/TeamInviteFailuresAlert.tsx
new file mode 100644
index 0000000000..f17889d6bf
--- /dev/null
+++ b/web/src/features/ai-gateway/components/TeamInviteFailuresAlert.tsx
@@ -0,0 +1,25 @@
+import { Alert } from "@/src/components/design-system/Alert/Alert";
+import type { TeamInviteFailure } from "@/src/features/ai-gateway/types/teamInviteFailure";
+
+export type TeamInviteFailuresAlertProps = {
+ failures: TeamInviteFailure[];
+};
+
+export function TeamInviteFailuresAlert({
+ failures,
+}: TeamInviteFailuresAlertProps) {
+ return (
+ <Alert variant="destructive">
+ <Alert.Title>Some invitations were not sent</Alert.Title>
+ <Alert.Description>
+ <ul className="ph-no-capture">
+ {failures.map((failure) => (
+ <li key={failure.email}>
+ {failure.email}: {failure.message}
+ </li>
+ ))}
+ </ul>
+ </Alert.Description>
+ </Alert>
+ );
+}
diff --git a/web/src/features/ai-gateway/components/GatewaySetupPage/components/GatewaySetupGuide/components/TeamInviteStep/components/TeamInviteForm/components/TeamInviteFields/TeamInviteFields.stories.tsx b/web/src/features/ai-gateway/components/TeamInviteFields/TeamInviteFields.stories.tsx
similarity index 100%
rename from web/src/features/ai-gateway/components/GatewaySetupPage/components/GatewaySetupGuide/components/TeamInviteStep/components/TeamInviteForm/components/TeamInviteFields/TeamInviteFields.stories.tsx
rename to web/src/features/ai-gateway/components/TeamInviteFields/TeamInviteFields.stories.tsx
diff --git a/web/src/features/ai-gateway/components/GatewaySetupPage/components/GatewaySetupGuide/components/TeamInviteStep/components/TeamInviteForm/components/TeamInviteFields/TeamInviteFields.tsx b/web/src/features/ai-gateway/components/TeamInviteFields/TeamInviteFields.tsx
similarity index 82%
rename from web/src/features/ai-gateway/components/GatewaySetupPage/components/GatewaySetupGuide/components/TeamInviteStep/components/TeamInviteForm/components/TeamInviteFields/TeamInviteFields.tsx
rename to web/src/features/ai-gateway/components/TeamInviteFields/TeamInviteFields.tsx
index ad13c406b8..07b911ee4a 100644
--- a/web/src/features/ai-gateway/components/GatewaySetupPage/components/GatewaySetupGuide/components/TeamInviteStep/components/TeamInviteForm/components/TeamInviteFields/TeamInviteFields.tsx
+++ b/web/src/features/ai-gateway/components/TeamInviteFields/TeamInviteFields.tsx
@@ -1,11 +1,11 @@
import { useId } from "react";
import { Mail } from "@langfuse/icons";
-import { EmailTagInput } from "@/src/features/ai-gateway/components/GatewaySetupPage/components/GatewaySetupGuide/components/TeamInviteStep/components/TeamInviteForm/components/TeamInviteFields/components/EmailTagInput/EmailTagInput";
+import { EmailTagInput } from "@/src/features/ai-gateway/components/TeamInviteFields/components/EmailTagInput/EmailTagInput";
import {
NotifyMembersToggle,
type NotifyMembersToggleProps,
-} from "@/src/features/ai-gateway/components/GatewaySetupPage/components/GatewaySetupGuide/components/TeamInviteStep/components/TeamInviteForm/components/TeamInviteFields/components/NotifyMembersToggle";
+} from "@/src/features/ai-gateway/components/TeamInviteFields/components/NotifyMembersToggle";
export type TeamInviteFieldsProps = {
emails: string[];
diff --git a/web/src/features/ai-gateway/components/GatewaySetupPage/components/GatewaySetupGuide/components/TeamInviteStep/components/TeamInviteForm/components/TeamInviteFields/components/EmailTagInput/EmailTagInput.tsx b/web/src/features/ai-gateway/components/TeamInviteFields/components/EmailTagInput/EmailTagInput.tsx
similarity index 83%
rename from web/src/features/ai-gateway/components/GatewaySetupPage/components/GatewaySetupGuide/components/TeamInviteStep/components/TeamInviteForm/components/TeamInviteFields/components/EmailTagInput/EmailTagInput.tsx
rename to web/src/features/ai-gateway/components/TeamInviteFields/components/EmailTagInput/EmailTagInput.tsx
index 5e2f9c9cbf..71dd4f4b40 100644
--- a/web/src/features/ai-gateway/components/GatewaySetupPage/components/GatewaySetupGuide/components/TeamInviteStep/components/TeamInviteForm/components/TeamInviteFields/components/EmailTagInput/EmailTagInput.tsx
+++ b/web/src/features/ai-gateway/components/TeamInviteFields/components/EmailTagInput/EmailTagInput.tsx
@@ -1,11 +1,11 @@
import { useState, type ChangeEvent, type KeyboardEvent } from "react";
import { z } from "zod/v4";
-import { EmailTag } from "@/src/features/ai-gateway/components/GatewaySetupPage/components/GatewaySetupGuide/components/TeamInviteStep/components/TeamInviteForm/components/TeamInviteFields/components/EmailTagInput/components/EmailTag";
+import { EmailTag } from "@/src/features/ai-gateway/components/TeamInviteFields/components/EmailTagInput/components/EmailTag";
import {
appendEmails,
splitEmailText,
-} from "@/src/features/ai-gateway/components/GatewaySetupPage/components/GatewaySetupGuide/components/TeamInviteStep/components/TeamInviteForm/components/TeamInviteFields/components/EmailTagInput/fns/emailText";
+} from "@/src/features/ai-gateway/components/TeamInviteFields/components/EmailTagInput/fns/emailText";
export type EmailTagInputProps = {
id: string;
diff --git a/web/src/features/ai-gateway/components/GatewaySetupPage/components/GatewaySetupGuide/components/TeamInviteStep/components/TeamInviteForm/components/TeamInviteFields/components/EmailTagInput/components/EmailTag.tsx b/web/src/features/ai-gateway/components/TeamInviteFields/components/EmailTagInput/components/EmailTag.tsx
similarity index 100%
rename from web/src/features/ai-gateway/components/GatewaySetupPage/components/GatewaySetupGuide/components/TeamInviteStep/components/TeamInviteForm/components/TeamInviteFields/components/EmailTagInput/components/EmailTag.tsx
rename to web/src/features/ai-gateway/components/TeamInviteFields/components/EmailTagInput/components/EmailTag.tsx
diff --git a/web/src/features/ai-gateway/components/GatewaySetupPage/components/GatewaySetupGuide/components/TeamInviteStep/components/TeamInviteForm/components/TeamInviteFields/components/EmailTagInput/fns/emailText.ts b/web/src/features/ai-gateway/components/TeamInviteFields/components/EmailTagInput/fns/emailText.ts
similarity index 100%
rename from web/src/features/ai-gateway/components/GatewaySetupPage/components/GatewaySetupGuide/components/TeamInviteStep/components/TeamInviteForm/components/TeamInviteFields/components/EmailTagInput/fns/emailText.ts
rename to web/src/features/ai-gateway/components/TeamInviteFields/components/EmailTagInput/fns/emailText.ts
diff --git a/web/src/features/ai-gateway/components/GatewaySetupPage/components/GatewaySetupGuide/components/TeamInviteStep/components/TeamInviteForm/components/TeamInviteFields/components/NotifyMembersToggle.tsx b/web/src/features/ai-gateway/components/TeamInviteFields/components/NotifyMembersToggle.tsx
similarity index 100%
rename from web/src/features/ai-gateway/components/GatewaySetupPage/components/GatewaySetupGuide/components/TeamInviteStep/components/TeamInviteForm/components/TeamInviteFields/components/NotifyMembersToggle.tsx
rename to web/src/features/ai-gateway/components/TeamInviteFields/components/NotifyMembersToggle.tsx
diff --git a/web/src/features/ai-gateway/hooks/useTeamInviteEmails.ts b/web/src/features/ai-gateway/hooks/useTeamInviteEmails.ts
new file mode 100644
index 0000000000..98b8bf7049
--- /dev/null
+++ b/web/src/features/ai-gateway/hooks/useTeamInviteEmails.ts
@@ -0,0 +1,37 @@
+import { useState } from "react";
+import { z } from "zod/v4";
+
+import { MAX_TEAM_INVITES } from "@/src/features/ai-gateway/constants/gatewayTeamInvites";
+import type { TeamInviteFailure } from "@/src/features/ai-gateway/types/teamInviteFailure";
+
+/** Invitee list for one invite attempt, keeping only failed addresses for a retry. */
+export function useTeamInviteEmails() {
+ const [emails, setEmails] = useState<string[]>([]);
+ const [failures, setFailures] = useState<TeamInviteFailure[]>([]);
+
+ const hasInvalidEmail = emails.some(
+ (email) => !z.email().safeParse(email).success,
+ );
+ const hasTooManyEmails = emails.length > MAX_TEAM_INVITES;
+
+ function startAttempt() {
+ setFailures([]);
+ }
+
+ function keepFailed(failed: TeamInviteFailure[]) {
+ setFailures(failed);
+ setEmails(failed.map((failure) => failure.email));
+ }
+
+ return {
+ emails,
+ setEmails,
+ failures,
+ isValid: !hasInvalidEmail && !hasTooManyEmails,
+ errorMessage: hasTooManyEmails
+ ? `You can invite up to ${MAX_TEAM_INVITES} people at once.`
+ : undefined,
+ startAttempt,
+ keepFailed,
+ };
+}
diff --git a/web/src/features/ai-gateway/types/teamInviteFailure.ts b/web/src/features/ai-gateway/types/teamInviteFailure.ts
new file mode 100644
index 0000000000..a90563309b
--- /dev/null
+++ b/web/src/features/ai-gateway/types/teamInviteFailure.ts
@@ -0,0 +1,4 @@
+import type { RouterOutputs } from "@/src/utils/api";
+
+export type TeamInviteFailure =
+ RouterOutputs["aiGateway"]["inviteTeam"]["failed"][number];