🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
fix(gateway): resolve endpoint and link provider models (#17320)
Tobias Wochingera4571ded38dc
diff --git a/web/src/__tests__/server/ai-gateway-control-plane.servertest.ts b/web/src/__tests__/server/ai-gateway-control-plane.servertest.tsindex 0e6bb9c28b..07290262a8 100644--- a/web/src/__tests__/server/ai-gateway-control-plane.servertest.ts+++ b/web/src/__tests__/server/ai-gateway-control-plane.servertest.ts@@ -181,6 +181,32 @@ async function prepare(role: Role = Role.OWNER) {}describe("AI gateway control plane", () => {+ it.each([+ {+ productUrl: "https://staging.langfuse.com",+ gatewayUrl: "https://gateway.staging.langfuse.com/v1",+ },+ {+ productUrl: "http://localhost:3000",+ gatewayUrl: "http://localhost:8080/v1",+ },+ ])(+ "returns the gateway endpoint for $productUrl",+ async ({ productUrl, gatewayUrl }) => {+ const { caller, org } = await prepare();+ const originalNextAuthUrl = env.NEXTAUTH_URL;+ (env as { NEXTAUTH_URL: string }).NEXTAUTH_URL = productUrl;++ try {+ await expect(+ caller.aiGateway.getConfig({ orgId: org.id }),+ ).resolves.toMatchObject({ gatewayBaseUrl: gatewayUrl });+ } finally {+ (env as { NEXTAUTH_URL: string }).NEXTAUTH_URL = originalNextAuthUrl;+ }+ },+ );+it("applies the environment-specific organization allowlist", async () => {const { caller, org } = await prepare();env.LANGFUSE_AI_GATEWAY_ORGANIZATION_ID_ALLOWLIST.splice(@@ -190,7 +216,7 @@ describe("AI gateway control plane", () => {const request = caller.aiGateway.getConfig({ orgId: org.id });if (env.NODE_ENV === "development") {- await expect(request).resolves.toBeNull();+ await expect(request).resolves.toMatchObject({ config: null });} else {await expect(request).rejects.toMatchObject({ code: "FORBIDDEN" });}diff --git a/web/src/features/ai-gateway/components/GatewayConfigurationPage/GatewayConfigurationPage.tsx b/web/src/features/ai-gateway/components/GatewayConfigurationPage/GatewayConfigurationPage.tsxindex 3963f7c76a..71e68e1cad 100644--- a/web/src/features/ai-gateway/components/GatewayConfigurationPage/GatewayConfigurationPage.tsx+++ b/web/src/features/ai-gateway/components/GatewayConfigurationPage/GatewayConfigurationPage.tsx@@ -70,11 +70,12 @@ export function GatewayConfigurationPage({);}- const config = configQuery.data;+ const { config, gatewayBaseUrl } = configQuery.data;return (<GatewayConfigurationViewkey={`${config?.updatedAt?.toISOString() ?? "new"}:${config?.defaultIngestionProjectId ?? "none"}:${config?.ingestionMode ?? "USAGE"}`}projects={projects}+ gatewayBaseUrl={gatewayBaseUrl}initialProjectId={config?.defaultIngestionProjectId ?? null}initialIngestionMode={config?.ingestionMode ?? "USAGE"}isSaving={createProject.isPending || updateConfig.isPending}diff --git a/web/src/features/ai-gateway/components/GatewayConfigurationPage/components/GatewayConfigurationView/GatewayConfigurationView.stories.tsx b/web/src/features/ai-gateway/components/GatewayConfigurationPage/components/GatewayConfigurationView/GatewayConfigurationView.stories.tsxindex f838002ec1..e3face3286 100644--- a/web/src/features/ai-gateway/components/GatewayConfigurationPage/components/GatewayConfigurationView/GatewayConfigurationView.stories.tsx+++ b/web/src/features/ai-gateway/components/GatewayConfigurationPage/components/GatewayConfigurationView/GatewayConfigurationView.stories.tsx@@ -14,6 +14,7 @@ const projects = [export const Enabled = meta.story({args: {projects,+ gatewayBaseUrl: "https://gateway.staging.langfuse.com/v1",initialProjectId: "project-production",initialIngestionMode: "USAGE",isSaving: false,@@ -26,6 +27,7 @@ export const Enabled = meta.story({export const MissingProjectWarning = meta.story({args: {projects,+ gatewayBaseUrl: "https://gateway.staging.langfuse.com/v1",initialProjectId: "deleted-project",initialIngestionMode: "FULL",isSaving: false,diff --git a/web/src/features/ai-gateway/components/GatewayConfigurationPage/components/GatewayConfigurationView/GatewayConfigurationView.tsx b/web/src/features/ai-gateway/components/GatewayConfigurationPage/components/GatewayConfigurationView/GatewayConfigurationView.tsxindex 5e6772292d..0f4028843c 100644--- a/web/src/features/ai-gateway/components/GatewayConfigurationPage/components/GatewayConfigurationView/GatewayConfigurationView.tsx+++ b/web/src/features/ai-gateway/components/GatewayConfigurationPage/components/GatewayConfigurationView/GatewayConfigurationView.tsx@@ -32,8 +32,6 @@ import { DEFAULT_GATEWAY_INGESTION_PROJECT_NAME } from "@/src/features/ai-gatewaimport { useCopyToClipboard } from "@/src/hooks/useCopyToClipboard";import { cn } from "@/src/utils/tailwind";-const GATEWAY_BASE_URL = "https://gateway.langfuse.com/v1";-type IngestionMode = "USAGE" | "FULL";type Project = {id: string;@@ -63,6 +61,7 @@ const ingestionModes: Array<{export function GatewayConfigurationView({projects,+ gatewayBaseUrl,initialProjectId,initialIngestionMode,isSaving,@@ -71,6 +70,7 @@ export function GatewayConfigurationView({onCreateProject,}: {projects: Project[];+ gatewayBaseUrl: string;initialProjectId: string | null;initialIngestionMode: IngestionMode;isSaving: boolean;@@ -116,7 +116,7 @@ export function GatewayConfigurationView({Use this fixed base URL in any supported SDK.</CardDescription></div>- <GatewayUrl />+ <GatewayUrl gatewayBaseUrl={gatewayBaseUrl} /></div><div>@@ -311,18 +311,18 @@ function CreateIngestionProjectDialog({);}-function GatewayUrl() {+function GatewayUrl({ gatewayBaseUrl }: { gatewayBaseUrl: string }) {const { copy, isCopied } = useCopyToClipboard();return (<div className="bg-muted flex w-fit max-w-full items-center justify-between gap-3 rounded-md border px-3 py-2">- <code className="truncate text-sm" title={GATEWAY_BASE_URL}>- {GATEWAY_BASE_URL}+ <code className="truncate text-sm" title={gatewayBaseUrl}>+ {gatewayBaseUrl}</code><Buttonsize="icon-xs"variant="ghost"aria-label="Copy gateway base URL"- onClick={() => copy(GATEWAY_BASE_URL)}+ onClick={() => copy(gatewayBaseUrl)}>{isCopied ? <Check className="size-4" /> : <Copy className="size-4" />}</Button>diff --git a/web/src/features/ai-gateway/components/GatewayModelsPage/GatewayModelsPage.tsx b/web/src/features/ai-gateway/components/GatewayModelsPage/GatewayModelsPage.tsxindex 82267ea4be..331edf38ce 100644--- a/web/src/features/ai-gateway/components/GatewayModelsPage/GatewayModelsPage.tsx+++ b/web/src/features/ai-gateway/components/GatewayModelsPage/GatewayModelsPage.tsx@@ -16,7 +16,11 @@ const providerFormats: Record<GatewayProvider, string[]> = {type ModelRow = {id: string;- availableVia: Array<{ connectionName: string; provider: GatewayProvider }>;+ availableVia: Array<{+ connectionId: string;+ connectionName: string;+ provider: GatewayProvider;+ }>;apiFormats: string[];};@@ -97,6 +101,7 @@ function aggregateModels(for (const modelId of result.models) {const existing = models.get(modelId);const availableVia = {+ connectionId: connection.id,connectionName: connection.name,provider: connection.provider,};diff --git a/web/src/features/ai-gateway/components/GatewayModelsPage/components/GatewayModelsView/GatewayModelsView.stories.tsx b/web/src/features/ai-gateway/components/GatewayModelsPage/components/GatewayModelsView/GatewayModelsView.stories.tsxindex c43f6e8e3e..81d549eb0b 100644--- a/web/src/features/ai-gateway/components/GatewayModelsPage/components/GatewayModelsView/GatewayModelsView.stories.tsx+++ b/web/src/features/ai-gateway/components/GatewayModelsPage/components/GatewayModelsView/GatewayModelsView.stories.tsx@@ -21,13 +21,23 @@ const meta = preview.meta({const models = [{id: "gpt-5-mini",- availableVia: [{ connectionName: "Primary", provider: "OPENAI" }],+ availableVia: [+ {+ connectionId: "connection-primary",+ connectionName: "Primary",+ provider: "OPENAI",+ },+ ],apiFormats: ["OpenAI Responses", "OpenAI Chat Completions"],},{id: "claude-sonnet-4-5",availableVia: [- { connectionName: "Anthropic production", provider: "ANTHROPIC" },+ {+ connectionId: "connection-anthropic-production",+ connectionName: "Anthropic production",+ provider: "ANTHROPIC",+ },],apiFormats: ["Anthropic Messages"],},@@ -41,6 +51,7 @@ const manyModels = Array.from({ length: 60 }, (_, index) => {id: `gateway-model-${String(index + 1).padStart(3, "0")}`,availableVia: [{+ connectionId: `connection-${(index % 6) + 1}`,connectionName: `Credential ${(index % 6) + 1}`,provider,},diff --git a/web/src/features/ai-gateway/components/GatewayModelsPage/components/GatewayModelsView/GatewayModelsView.tsx b/web/src/features/ai-gateway/components/GatewayModelsPage/components/GatewayModelsView/GatewayModelsView.tsxindex c136499f8b..68e07c80b7 100644--- a/web/src/features/ai-gateway/components/GatewayModelsPage/components/GatewayModelsView/GatewayModelsView.tsx+++ b/web/src/features/ai-gateway/components/GatewayModelsPage/components/GatewayModelsView/GatewayModelsView.tsx@@ -101,6 +101,20 @@ export function GatewayModelsView({const [searchQuery, setSearchQuery] = useState("");const filterOptions = useMemo(() => ({+ connection: [+ ...new Map(+ models+ .flatMap((model) => model.availableVia)+ .map((connection) => [connection.connectionId, connection]),+ ).values(),+ ]+ .toSorted((left, right) =>+ left.connectionName.localeCompare(right.connectionName),+ )+ .map((connection) => ({+ value: connection.connectionId,+ displayValue: connection.connectionName,+ })),provider: uniqueSorted(models.flatMap((model) =>model.availableVia.map((connection) => connection.provider),@@ -114,7 +128,7 @@ export function GatewayModelsView({gatewayModelsFilterConfig,filterOptions,{- stateLocation: "memory",+ stateLocation: "url",},);const filteredModels = useMemo(diff --git a/web/src/features/ai-gateway/components/GatewayModelsPage/components/GatewayModelsView/filterGatewayModels.clienttest.ts b/web/src/features/ai-gateway/components/GatewayModelsPage/components/GatewayModelsView/filterGatewayModels.clienttest.tsindex d069b7a3a9..7232b5bebb 100644--- a/web/src/features/ai-gateway/components/GatewayModelsPage/components/GatewayModelsView/filterGatewayModels.clienttest.ts+++ b/web/src/features/ai-gateway/components/GatewayModelsPage/components/GatewayModelsView/filterGatewayModels.clienttest.ts@@ -12,12 +12,24 @@ import {const models: GatewayModelRow[] = [{id: "model-small",- availableVia: [{ connectionName: "Primary", provider: "OPENAI" }],+ availableVia: [+ {+ connectionId: "connection-primary",+ connectionName: "Primary",+ provider: "OPENAI",+ },+ ],apiFormats: ["OpenAI Responses", "OpenAI Chat Completions"],},{id: "model-large",- availableVia: [{ connectionName: "Secondary", provider: "ANTHROPIC" }],+ availableVia: [+ {+ connectionId: "connection-secondary",+ connectionName: "Secondary",+ provider: "ANTHROPIC",+ },+ ],apiFormats: ["Anthropic Messages"],},];diff --git a/web/src/features/ai-gateway/components/GatewayModelsPage/components/GatewayModelsView/filterGatewayModels.ts b/web/src/features/ai-gateway/components/GatewayModelsPage/components/GatewayModelsView/filterGatewayModels.tsindex 20f65ca7d3..bd9f34f12f 100644--- a/web/src/features/ai-gateway/components/GatewayModelsPage/components/GatewayModelsView/filterGatewayModels.ts+++ b/web/src/features/ai-gateway/components/GatewayModelsPage/components/GatewayModelsView/filterGatewayModels.ts@@ -4,6 +4,7 @@ import type { GatewayProvider } from "@/src/features/ai-gateway/types/gatewayProexport type GatewayModelRow = {id: string;availableVia: Array<{+ connectionId: string;connectionName: string;provider: GatewayProvider;}>;@@ -12,6 +13,8 @@ export type GatewayModelRow = {function getModelFilterValues(model: GatewayModelRow, column: string) {switch (column) {+ case "connection":+ return model.availableVia.map((connection) => connection.connectionId);case "provider":return model.availableVia.map((connection) => connection.provider);case "apiFormat":diff --git a/web/src/features/ai-gateway/components/GatewayProvidersPage/GatewayProvidersPage.tsx b/web/src/features/ai-gateway/components/GatewayProvidersPage/GatewayProvidersPage.tsxindex c114694677..e88f647724 100644--- a/web/src/features/ai-gateway/components/GatewayProvidersPage/GatewayProvidersPage.tsx+++ b/web/src/features/ai-gateway/components/GatewayProvidersPage/GatewayProvidersPage.tsx@@ -9,6 +9,7 @@ import { DeleteProviderDialog } from "@/src/features/ai-gateway/components/Gatewimport { ProviderDialogController } from "@/src/features/ai-gateway/components/GatewayProvidersPage/components/ProviderDialogController/ProviderDialogController";import { GatewayProvidersView } from "@/src/features/ai-gateway/components/GatewayProvidersPage/components/GatewayProvidersView/GatewayProvidersView";import { RetryProviderButton } from "@/src/features/ai-gateway/components/GatewayProvidersPage/components/RetryProviderButton";+import { buildGatewayModelsUrl } from "@/src/features/ai-gateway/fns/gatewayUrls/buildGatewayModelsUrl";import { api, reportNonTrpcError } from "@/src/utils/api";export function GatewayProvidersPage({@@ -74,6 +75,9 @@ export function GatewayProvidersPage({<GatewayProvidersViewconnections={connections}modelCounts={modelCounts}+ getModelsUrl={(connection) =>+ buildGatewayModelsUrl(organizationId, connection.id)+ }hasMore={Boolean(connectionsQuery.hasNextPage)}isLoadingMore={connectionsQuery.isFetchingNextPage}onLoadMore={() => connectionsQuery.fetchNextPage()}diff --git a/web/src/features/ai-gateway/components/GatewayProvidersPage/components/GatewayProvidersView/GatewayProvidersView.clienttest.ts b/web/src/features/ai-gateway/components/GatewayProvidersPage/components/GatewayProvidersView/GatewayProvidersView.clienttest.tsindex eb76d92e52..ef5408054a 100644--- a/web/src/features/ai-gateway/components/GatewayProvidersPage/components/GatewayProvidersView/GatewayProvidersView.clienttest.ts+++ b/web/src/features/ai-gateway/components/GatewayProvidersPage/components/GatewayProvidersView/GatewayProvidersView.clienttest.ts@@ -2,12 +2,10 @@ import { createElement } from "react";import { fireEvent, render, screen, waitFor } from "@testing-library/react";import { describe, expect, it, vi } from "vitest";+import { getProviderReorder } from "@/src/features/ai-gateway/fns/providerReorder/getProviderReorder";+import { reorderProviderIds } from "@/src/features/ai-gateway/fns/providerReorder/reorderProviderIds";import type { GatewayConnection } from "@/src/features/ai-gateway/types/gatewayProvider";-import {- GatewayProvidersView,- getProviderReorder,- reorderProviderIds,-} from "./GatewayProvidersView";+import { GatewayProvidersView } from "./GatewayProvidersView";const connection = (id: string,@@ -42,6 +40,7 @@ describe("provider credential reordering", () => {const gamma = connection("gamma", "Gamma", 2);const props = {modelCounts: {},+ getModelsUrl: (item: GatewayConnection) => `/models/${item.id}`,createAction: null,renderCredentialActions: () => null,hasMore: false,diff --git a/web/src/features/ai-gateway/components/GatewayProvidersPage/components/GatewayProvidersView/GatewayProvidersView.stories.tsx b/web/src/features/ai-gateway/components/GatewayProvidersPage/components/GatewayProvidersView/GatewayProvidersView.stories.tsxindex 2dd5261a50..a756f71b85 100644--- a/web/src/features/ai-gateway/components/GatewayProvidersPage/components/GatewayProvidersView/GatewayProvidersView.stories.tsx+++ b/web/src/features/ai-gateway/components/GatewayProvidersPage/components/GatewayProvidersView/GatewayProvidersView.stories.tsx@@ -59,6 +59,8 @@ const manyModelCounts = Object.fromEntries();const actions = {+ getModelsUrl: (connection) =>+ `/organization/org-1/settings/ai-gateway-models?connection=${connection.id}`,createAction: <Button onClick={onCreate}>Add credential</Button>,renderCredentialActions: (connection) => (<Button@@ -76,6 +78,7 @@ const actions = {onReorder,} satisfies Pick<ComponentProps<typeof GatewayProvidersView>,+ | "getModelsUrl"| "createAction"| "renderCredentialActions"| "hasMore"diff --git a/web/src/features/ai-gateway/components/GatewayProvidersPage/components/GatewayProvidersView/GatewayProvidersView.tsx b/web/src/features/ai-gateway/components/GatewayProvidersPage/components/GatewayProvidersView/GatewayProvidersView.tsxindex 09fb28aa0d..c7d13f0506 100644--- a/web/src/features/ai-gateway/components/GatewayProvidersPage/components/GatewayProvidersView/GatewayProvidersView.tsx+++ b/web/src/features/ai-gateway/components/GatewayProvidersPage/components/GatewayProvidersView/GatewayProvidersView.tsx@@ -30,6 +30,7 @@ import {} from "@dnd-kit/sortable";import { CSS } from "@dnd-kit/utilities";import { ArrowDown, ArrowUp, GripVertical, Route } from "lucide-react";+import Link from "next/link";import { SiAnthropic, SiOpenai } from "react-icons/si";import Header from "@/src/components/layouts/header";@@ -39,6 +40,8 @@ import { Badge } from "@/src/components/ui/badge";import { Button } from "@/src/components/ui/button";import { TableRow } from "@/src/components/ui/table";import { providerLabels } from "@/src/features/ai-gateway/constants/providerLabels";+import { getProviderReorder } from "@/src/features/ai-gateway/fns/providerReorder/getProviderReorder";+import { reorderProviderIds } from "@/src/features/ai-gateway/fns/providerReorder/reorderProviderIds";import type {GatewayConnection,GatewayProvider,@@ -47,24 +50,6 @@ import { cn } from "@/src/utils/tailwind";const TABLE_NAME = "gateway-provider-credentials";-export function reorderProviderIds(- ids: string[],- sourceId: string,- targetId: string,-) {- const sourceIndex = ids.indexOf(sourceId);- const targetIndex = ids.indexOf(targetId);- if (sourceIndex < 0 || targetIndex < 0 || sourceIndex === targetIndex) {- return ids;- }-- const nextIds = [...ids];- const [movedId] = nextIds.splice(sourceIndex, 1);- if (!movedId) return ids;- nextIds.splice(targetIndex, 0, movedId);- return nextIds;-}-type SortableHandleContextValue = Pick<ReturnType<typeof useSortable>,"attributes" | "listeners"@@ -78,6 +63,7 @@ type GatewayConnectionRow = GatewayConnection;type GatewayProvidersViewProps = {connections: GatewayConnectionRow[];modelCounts: Record<string, number | "loading">;+ getModelsUrl: (connection: GatewayConnectionRow) => string;createAction: ReactNode;renderCredentialActions: (connection: GatewayConnectionRow,@@ -100,6 +86,7 @@ export function GatewayProvidersView(props: GatewayProvidersViewProps) {function SortableGatewayProvidersView({connections,modelCounts,+ getModelsUrl,createAction,renderCredentialActions,hasMore,@@ -241,7 +228,12 @@ function SortableGatewayProvidersView({id: "models",header: "Models",size: 180,- cell: ({ row }) => <ModelCount value={modelCounts[row.original.id]} />,+ cell: ({ row }) => (+ <ModelCount+ value={modelCounts[row.original.id]}+ href={getModelsUrl(row.original)}+ />+ ),},{accessorKey: "actions",@@ -259,6 +251,7 @@ function SortableGatewayProvidersView({],[canReorder,+ getModelsUrl,modelCounts,moveConnection,orderedConnections,@@ -335,23 +328,6 @@ function SortableGatewayProvidersView({);}-export function getProviderReorder(- event: Pick<DragEndEvent, "active" | "over">,- canReorder: boolean,-) {- if (- !canReorder ||- !event.over ||- event.active.id === event.over.id ||- typeof event.active.id !== "string" ||- typeof event.over.id !== "string"- ) {- return null;- }-- return { sourceId: event.active.id, targetId: event.over.id };-}-function SortableProviderRow({connection,canReorder,@@ -460,13 +436,19 @@ function ProviderPriorityCell({);}-function ModelCount({ value }: { value: number | "loading" | undefined }) {+function ModelCount({+ value,+ href,+}: {+ value: number | "loading" | undefined;+ href: string;+}) {if (value === "loading") return <>Loading…</>;if (value === undefined) return <>—</>;return (- <>+ <Link className="text-primary hover:underline" href={href}>{value} {value === 1 ? "model" : "models"} available- </>+ </Link>);}diff --git a/web/src/features/ai-gateway/constants/modelsFilterConfig.ts b/web/src/features/ai-gateway/constants/modelsFilterConfig.tsindex c75f2a11d2..a6a786573b 100644--- a/web/src/features/ai-gateway/constants/modelsFilterConfig.ts+++ b/web/src/features/ai-gateway/constants/modelsFilterConfig.ts@@ -3,6 +3,13 @@ import type { FilterConfig } from "@/src/features/filters/lib/filter-config";import { providerLabels } from "./providerLabels";const filterColumns: ColumnDefinition[] = [+ {+ name: "Provider credentials",+ id: "connection",+ type: "arrayOptions",+ internal: "connection",+ options: [],+ },{name: "Provider",id: "provider",@@ -25,8 +32,13 @@ const filterColumns: ColumnDefinition[] = [export const gatewayModelsFilterConfig: FilterConfig = {tableName: "gateway-models",columnDefinitions: filterColumns,- defaultExpanded: ["provider", "apiFormat"],+ defaultExpanded: ["connection", "provider", "apiFormat"],facets: [+ {+ type: "categorical",+ column: "connection",+ label: "Provider credentials",+ },{ type: "categorical", column: "provider", label: "Provider" },{ type: "categorical", column: "apiFormat", label: "API format" },],diff --git a/web/src/features/ai-gateway/fns/gatewayUrls/buildGatewayModelsUrl.ts b/web/src/features/ai-gateway/fns/gatewayUrls/buildGatewayModelsUrl.tsnew file mode 100644index 0000000000..9837e949c6--- /dev/null+++ b/web/src/features/ai-gateway/fns/gatewayUrls/buildGatewayModelsUrl.ts@@ -0,0 +1,19 @@+import { encodeFiltersGeneric } from "@langfuse/shared";++export function buildGatewayModelsUrl(+ organizationId: string,+ connectionId: string,+) {+ const params = new URLSearchParams({+ filter: encodeFiltersGeneric([+ {+ column: "connection",+ type: "arrayOptions",+ operator: "any of",+ value: [connectionId],+ },+ ]),+ });++ return `/organization/${encodeURIComponent(organizationId)}/settings/ai-gateway-models?${params.toString()}`;+}diff --git a/web/src/features/ai-gateway/fns/gatewayUrls/getGatewayBaseUrl.ts b/web/src/features/ai-gateway/fns/gatewayUrls/getGatewayBaseUrl.tsnew file mode 100644index 0000000000..063c8462a5--- /dev/null+++ b/web/src/features/ai-gateway/fns/gatewayUrls/getGatewayBaseUrl.ts@@ -0,0 +1,17 @@+const LOCAL_GATEWAY_HOSTS = new Set(["localhost", "127.0.0.1", "[::1]"]);++export function getGatewayBaseUrl(productBaseUrl: URL) {+ const gatewayBaseUrl = new URL(productBaseUrl);++ if (LOCAL_GATEWAY_HOSTS.has(gatewayBaseUrl.hostname)) {+ gatewayBaseUrl.protocol = "http:";+ gatewayBaseUrl.port = "8080";+ } else {+ gatewayBaseUrl.hostname = `gateway.${gatewayBaseUrl.hostname}`;+ }++ gatewayBaseUrl.pathname = "/v1";+ gatewayBaseUrl.search = "";+ gatewayBaseUrl.hash = "";+ return gatewayBaseUrl.toString();+}diff --git a/web/src/features/ai-gateway/fns/providerReorder/getProviderReorder.ts b/web/src/features/ai-gateway/fns/providerReorder/getProviderReorder.tsnew file mode 100644index 0000000000..d4d7dcb50f--- /dev/null+++ b/web/src/features/ai-gateway/fns/providerReorder/getProviderReorder.ts@@ -0,0 +1,18 @@+import type { DragEndEvent } from "@dnd-kit/core";++export function getProviderReorder(+ event: Pick<DragEndEvent, "active" | "over">,+ canReorder: boolean,+) {+ if (+ !canReorder ||+ !event.over ||+ event.active.id === event.over.id ||+ typeof event.active.id !== "string" ||+ typeof event.over.id !== "string"+ ) {+ return null;+ }++ return { sourceId: event.active.id, targetId: event.over.id };+}diff --git a/web/src/features/ai-gateway/fns/providerReorder/reorderProviderIds.ts b/web/src/features/ai-gateway/fns/providerReorder/reorderProviderIds.tsnew file mode 100644index 0000000000..910d77946a--- /dev/null+++ b/web/src/features/ai-gateway/fns/providerReorder/reorderProviderIds.ts@@ -0,0 +1,17 @@+export function reorderProviderIds(+ ids: string[],+ sourceId: string,+ targetId: string,+) {+ const sourceIndex = ids.indexOf(sourceId);+ const targetIndex = ids.indexOf(targetId);+ if (sourceIndex < 0 || targetIndex < 0 || sourceIndex === targetIndex) {+ return ids;+ }++ const nextIds = [...ids];+ const [movedId] = nextIds.splice(sourceIndex, 1);+ if (!movedId) return ids;+ nextIds.splice(targetIndex, 0, movedId);+ return nextIds;+}diff --git a/web/src/features/ai-gateway/server/router.ts b/web/src/features/ai-gateway/server/router.tsindex e9583a6e4c..e49e8f1fd7 100644--- a/web/src/features/ai-gateway/server/router.ts+++ b/web/src/features/ai-gateway/server/router.ts@@ -7,6 +7,7 @@ import {protectedOrganizationProcedure,protectedOrganizationProcedureWithoutTracing,} from "@/src/server/api/trpc";+import { getProductBaseUrl } from "@/src/utils/base-url";import {GatewayConnectionStatus,GatewayIngestionMode,@@ -16,6 +17,7 @@ import { redis } from "@langfuse/shared/src/server";import { GatewayApiKeyService } from "./apiKey/gatewayApiKeyService";import { requireGatewayEnabledForOrganization } from "./availability";+import { getGatewayBaseUrl } from "@/src/features/ai-gateway/fns/gatewayUrls/getGatewayBaseUrl";import { GatewayConfigService } from "./config/gatewayConfigService";import {GatewayMetadataSchema,@@ -43,7 +45,12 @@ export const aiGatewayRouter = createTRPCRouter({.input(organizationInput).query(async ({ input, ctx }) => {requireGatewayAdmin({ session: ctx.session, orgId: input.orgId });- return new GatewayConfigService(ctx.prisma).getConfig(input.orgId);+ return {+ config: await new GatewayConfigService(ctx.prisma).getConfig(+ input.orgId,+ ),+ gatewayBaseUrl: getGatewayBaseUrl(getProductBaseUrl()),+ };}),updateConfig: protectedOrganizationProcedure