Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

feat: add OpenRouter App Connection

IgorHorta50b3aeffea3a
diff --git a/backend/src/lib/api-docs/constants.ts b/backend/src/lib/api-docs/constants.ts
index 74eea4782f..2f27ca4967 100644
--- a/backend/src/lib/api-docs/constants.ts
+++ b/backend/src/lib/api-docs/constants.ts
@@ -2624,6 +2624,9 @@ export const AppConnections = {
password: "The password for SSH authentication (required when authMethod is 'password').",
privateKey: "The private key in PEM format for SSH authentication (required when authMethod is 'ssh-key').",
passphrase: "The passphrase for the private key, if encrypted (optional, only for 'ssh-key' authMethod)."
+ },
+ OPEN_ROUTER: {
+ apiKey: "The OpenRouter Provisioning API key used to manage API keys."
}
}
};
diff --git a/backend/src/server/routes/v1/app-connection-routers/app-connection-router.ts b/backend/src/server/routes/v1/app-connection-routers/app-connection-router.ts
index e65dc88946..a4d069c12c 100644
--- a/backend/src/server/routes/v1/app-connection-routers/app-connection-router.ts
+++ b/backend/src/server/routes/v1/app-connection-routers/app-connection-router.ts
@@ -106,6 +106,10 @@ import {
SanitizedOctopusDeployConnectionSchema
} from "@app/services/app-connection/octopus-deploy";
import { OktaConnectionListItemSchema, SanitizedOktaConnectionSchema } from "@app/services/app-connection/okta";
+import {
+ OpenRouterConnectionListItemSchema,
+ SanitizedOpenRouterConnectionSchema
+} from "@app/services/app-connection/open-router";
import {
PostgresConnectionListItemSchema,
SanitizedPostgresConnectionSchema
@@ -187,7 +191,8 @@ const SanitizedAppConnectionSchema = z.union([
...SanitizedChefConnectionSchema.options,
...SanitizedDNSMadeEasyConnectionSchema.options,
...SanitizedOctopusDeployConnectionSchema.options,
- ...SanitizedSshConnectionSchema.options
+ ...SanitizedSshConnectionSchema.options,
+ ...SanitizedOpenRouterConnectionSchema.options
]);
const AppConnectionOptionsSchema = z.discriminatedUnion("app", [
@@ -236,7 +241,8 @@ const AppConnectionOptionsSchema = z.discriminatedUnion("app", [
ChefConnectionListItemSchema,
DNSMadeEasyConnectionListItemSchema,
OctopusDeployConnectionListItemSchema,
- SshConnectionListItemSchema
+ SshConnectionListItemSchema,
+ OpenRouterConnectionListItemSchema
]);
export const registerAppConnectionRouter = async (server: FastifyZodProvider) => {
diff --git a/backend/src/server/routes/v1/app-connection-routers/index.ts b/backend/src/server/routes/v1/app-connection-routers/index.ts
index 6a1ad4ad97..23fc1127a0 100644
--- a/backend/src/server/routes/v1/app-connection-routers/index.ts
+++ b/backend/src/server/routes/v1/app-connection-routers/index.ts
@@ -46,6 +46,7 @@ import { registerTerraformCloudConnectionRouter } from "./terraform-cloud-router
import { registerVercelConnectionRouter } from "./vercel-connection-router";
import { registerWindmillConnectionRouter } from "./windmill-connection-router";
import { registerZabbixConnectionRouter } from "./zabbix-connection-router";
+import { registerOpenRouterConnectionRouter } from "./open-router-connection-router";
export * from "./app-connection-router";
@@ -96,5 +97,6 @@ export const APP_CONNECTION_REGISTER_ROUTER_MAP: Record<AppConnection, (server:
[AppConnection.MongoDB]: registerMongoDBConnectionRouter,
[AppConnection.Chef]: registerChefConnectionRouter,
[AppConnection.OctopusDeploy]: registerOctopusDeployConnectionRouter,
- [AppConnection.SSH]: registerSshConnectionRouter
+ [AppConnection.SSH]: registerSshConnectionRouter,
+ [AppConnection.OpenRouter]: registerOpenRouterConnectionRouter
};
diff --git a/backend/src/server/routes/v1/app-connection-routers/open-router-connection-router.ts b/backend/src/server/routes/v1/app-connection-routers/open-router-connection-router.ts
new file mode 100644
index 0000000000..7e3a1a2d84
--- /dev/null
+++ b/backend/src/server/routes/v1/app-connection-routers/open-router-connection-router.ts
@@ -0,0 +1,18 @@
+import { AppConnection } from "@app/services/app-connection/app-connection-enums";
+import {
+ CreateOpenRouterConnectionSchema,
+ SanitizedOpenRouterConnectionSchema,
+ UpdateOpenRouterConnectionSchema
+} from "@app/services/app-connection/open-router";
+
+import { registerAppConnectionEndpoints } from "./app-connection-endpoints";
+
+export const registerOpenRouterConnectionRouter = async (server: FastifyZodProvider) => {
+ registerAppConnectionEndpoints({
+ app: AppConnection.OpenRouter,
+ server,
+ sanitizedResponseSchema: SanitizedOpenRouterConnectionSchema,
+ createSchema: CreateOpenRouterConnectionSchema,
+ updateSchema: UpdateOpenRouterConnectionSchema
+ });
+};
diff --git a/backend/src/services/app-connection/app-connection-enums.ts b/backend/src/services/app-connection/app-connection-enums.ts
index 3474914220..244a2a217f 100644
--- a/backend/src/services/app-connection/app-connection-enums.ts
+++ b/backend/src/services/app-connection/app-connection-enums.ts
@@ -44,7 +44,8 @@ export enum AppConnection {
Chef = "chef",
Northflank = "northflank",
OctopusDeploy = "octopus-deploy",
- SSH = "ssh"
+ SSH = "ssh",
+ OpenRouter = "open-router"
}
export enum AWSRegion {
diff --git a/backend/src/services/app-connection/app-connection-fns.ts b/backend/src/services/app-connection/app-connection-fns.ts
index 2b9ce06e75..d99af5b0bd 100644
--- a/backend/src/services/app-connection/app-connection-fns.ts
+++ b/backend/src/services/app-connection/app-connection-fns.ts
@@ -135,6 +135,11 @@ import {
validateOctopusDeployConnectionCredentials
} from "./octopus-deploy";
import { getOktaConnectionListItem, OktaConnectionMethod, validateOktaConnectionCredentials } from "./okta";
+import {
+ getOpenRouterConnectionListItem,
+ OpenRouterConnectionMethod,
+ validateOpenRouterConnectionCredentials
+} from "./open-router";
import { getPostgresConnectionListItem, PostgresConnectionMethod } from "./postgres";
import { getRailwayConnectionListItem, validateRailwayConnectionCredentials } from "./railway";
import { getRedisConnectionListItem, RedisConnectionMethod, validateRedisConnectionCredentials } from "./redis";
@@ -234,7 +239,8 @@ export const listAppConnectionOptions = (projectType?: ProjectType) => {
getRedisConnectionListItem(),
getMongoDBConnectionListItem(),
getChefConnectionListItem(),
- getSshConnectionListItem()
+ getSshConnectionListItem(),
+ getOpenRouterConnectionListItem()
]
.filter((option) => {
switch (projectType) {
@@ -370,7 +376,8 @@ export const validateAppConnectionCredentials = async (
[AppConnection.Redis]: validateRedisConnectionCredentials as TAppConnectionCredentialsValidator,
[AppConnection.MongoDB]: validateMongoDBConnectionCredentials as TAppConnectionCredentialsValidator,
[AppConnection.OctopusDeploy]: validateOctopusDeployConnectionCredentials as TAppConnectionCredentialsValidator,
- [AppConnection.SSH]: validateSshConnectionCredentials as TAppConnectionCredentialsValidator
+ [AppConnection.SSH]: validateSshConnectionCredentials as TAppConnectionCredentialsValidator,
+ [AppConnection.OpenRouter]: validateOpenRouterConnectionCredentials as TAppConnectionCredentialsValidator
};
return VALIDATE_APP_CONNECTION_CREDENTIALS_MAP[appConnection.app](appConnection, gatewayService, gatewayV2Service);
@@ -445,6 +452,7 @@ export const getAppConnectionMethodName = (method: TAppConnection["method"]) =>
case RenderConnectionMethod.ApiKey:
case ChecklyConnectionMethod.ApiKey:
case OctopusDeployConnectionMethod.ApiKey:
+ case OpenRouterConnectionMethod.ApiKey:
return "API Key";
case ChefConnectionMethod.UserKey:
return "User Key";
@@ -527,7 +535,8 @@ export const TRANSITION_CONNECTION_CREDENTIALS_TO_PLATFORM: Record<
[AppConnection.LaravelForge]: platformManagedCredentialsNotSupported,
[AppConnection.Chef]: platformManagedCredentialsNotSupported,
[AppConnection.OctopusDeploy]: platformManagedCredentialsNotSupported,
- [AppConnection.SSH]: platformManagedCredentialsNotSupported
+ [AppConnection.SSH]: platformManagedCredentialsNotSupported,
+ [AppConnection.OpenRouter]: platformManagedCredentialsNotSupported
};
export const enterpriseAppCheck = async (
diff --git a/backend/src/services/app-connection/app-connection-maps.ts b/backend/src/services/app-connection/app-connection-maps.ts
index 3e8f006f66..5952c16e5a 100644
--- a/backend/src/services/app-connection/app-connection-maps.ts
+++ b/backend/src/services/app-connection/app-connection-maps.ts
@@ -46,7 +46,8 @@ export const APP_CONNECTION_NAME_MAP: Record<AppConnection, string> = {
[AppConnection.Chef]: "Chef",
[AppConnection.Northflank]: "Northflank",
[AppConnection.OctopusDeploy]: "Octopus Deploy",
- [AppConnection.SSH]: "SSH"
+ [AppConnection.SSH]: "SSH",
+ [AppConnection.OpenRouter]: "OpenRouter"
};
export const APP_CONNECTION_PLAN_MAP: Record<AppConnection, AppConnectionPlanType> = {
@@ -95,5 +96,6 @@ export const APP_CONNECTION_PLAN_MAP: Record<AppConnection, AppConnectionPlanTyp
[AppConnection.Chef]: AppConnectionPlanType.Enterprise,
[AppConnection.Northflank]: AppConnectionPlanType.Regular,
[AppConnection.OctopusDeploy]: AppConnectionPlanType.Regular,
- [AppConnection.SSH]: AppConnectionPlanType.Regular
+ [AppConnection.SSH]: AppConnectionPlanType.Regular,
+ [AppConnection.OpenRouter]: AppConnectionPlanType.Regular
};
diff --git a/backend/src/services/app-connection/app-connection-types.ts b/backend/src/services/app-connection/app-connection-types.ts
index d40975d36b..0effd99c6c 100644
--- a/backend/src/services/app-connection/app-connection-types.ts
+++ b/backend/src/services/app-connection/app-connection-types.ts
@@ -204,6 +204,12 @@ import {
TOktaConnectionInput,
TValidateOktaConnectionCredentialsSchema
} from "./okta";
+import {
+ TOpenRouterConnection,
+ TOpenRouterConnectionConfig,
+ TOpenRouterConnectionInput,
+ TValidateOpenRouterConnectionCredentialsSchema
+} from "./open-router";
import {
TPostgresConnection,
TPostgresConnectionInput,
@@ -317,6 +323,7 @@ export type TAppConnection = { id: string } & (
| TChefConnection
| TOctopusDeployConnection
| TSshConnection
+ | TOpenRouterConnection
);
export type TAppConnectionRaw = NonNullable<Awaited<ReturnType<TAppConnectionDALFactory["findById"]>>>;
@@ -370,6 +377,7 @@ export type TAppConnectionInput = { id: string } & (
| TChefConnectionInput
| TOctopusDeployConnectionInput
| TSshConnectionInput
+ | TOpenRouterConnectionInput
);
export type TSqlConnectionInput =
@@ -440,7 +448,8 @@ export type TAppConnectionConfig =
| TMongoDBConnectionConfig
| TChefConnectionConfig
| TOctopusDeployConnectionConfig
- | TSshConnectionConfig;
+ | TSshConnectionConfig
+ | TOpenRouterConnectionConfig;
export type TValidateAppConnectionCredentialsSchema =
| TValidateAwsConnectionCredentialsSchema
@@ -488,7 +497,8 @@ export type TValidateAppConnectionCredentialsSchema =
| TValidateMongoDBConnectionCredentialsSchema
| TValidateChefConnectionCredentialsSchema
| TValidateOctopusDeployConnectionCredentialsSchema
- | TValidateSshConnectionCredentialsSchema;
+ | TValidateSshConnectionCredentialsSchema
+ | TValidateOpenRouterConnectionCredentialsSchema;
export type TListAwsConnectionKmsKeys = {
connectionId: string;
diff --git a/backend/src/services/app-connection/open-router/index.ts b/backend/src/services/app-connection/open-router/index.ts
new file mode 100644
index 0000000000..24222eb257
--- /dev/null
+++ b/backend/src/services/app-connection/open-router/index.ts
@@ -0,0 +1,4 @@
+export * from "./open-router-connection-enums";
+export * from "./open-router-connection-fns";
+export * from "./open-router-connection-schemas";
+export * from "./open-router-connection-types";
diff --git a/backend/src/services/app-connection/open-router/open-router-connection-enums.ts b/backend/src/services/app-connection/open-router/open-router-connection-enums.ts
new file mode 100644
index 0000000000..19a5ddaa09
--- /dev/null
+++ b/backend/src/services/app-connection/open-router/open-router-connection-enums.ts
@@ -0,0 +1,3 @@
+export enum OpenRouterConnectionMethod {
+ ApiKey = "api-key"
+}
diff --git a/backend/src/services/app-connection/open-router/open-router-connection-fns.ts b/backend/src/services/app-connection/open-router/open-router-connection-fns.ts
new file mode 100644
index 0000000000..ae36a9d837
--- /dev/null
+++ b/backend/src/services/app-connection/open-router/open-router-connection-fns.ts
@@ -0,0 +1,37 @@
+import { request } from "@app/lib/config/request";
+import { UnauthorizedError } from "@app/lib/errors";
+import { AppConnection } from "@app/services/app-connection/app-connection-enums";
+
+import { OpenRouterConnectionMethod } from "./open-router-connection-enums";
+import { TOpenRouterConnectionConfig } from "./open-router-connection-types";
+
+const OPEN_ROUTER_API_BASE_URL = "https://openrouter.ai/api/v1";
+
+export const getOpenRouterConnectionListItem = () => {
+ return {
+ name: "OpenRouter" as const,
+ app: AppConnection.OpenRouter as const,
+ methods: Object.values(OpenRouterConnectionMethod) as [OpenRouterConnectionMethod.ApiKey]
+ };
+};
+
+export const validateOpenRouterConnectionCredentials = async (config: TOpenRouterConnectionConfig) => {
+ const { apiKey } = config.credentials;
+
+ try {
+ // Validate by attempting to list API keys (requires a valid provisioning key)
+ await request.get(`${OPEN_ROUTER_API_BASE_URL}/keys`, {
+ headers: {
+ Authorization: `Bearer ${apiKey}`,
+ "Content-Type": "application/json"
+ },
+ validateStatus: (status) => status === 200
+ });
+ } catch (error: unknown) {
+ throw new UnauthorizedError({
+ message: "Unable to validate connection: invalid API key or insufficient permissions"
+ });
+ }
+
+ return config.credentials;
+};
diff --git a/backend/src/services/app-connection/open-router/open-router-connection-schemas.ts b/backend/src/services/app-connection/open-router/open-router-connection-schemas.ts
new file mode 100644
index 0000000000..b2b9332bd8
--- /dev/null
+++ b/backend/src/services/app-connection/open-router/open-router-connection-schemas.ts
@@ -0,0 +1,65 @@
+import z from "zod";
+
+import { AppConnections } from "@app/lib/api-docs";
+import { AppConnection } from "@app/services/app-connection/app-connection-enums";
+import {
+ BaseAppConnectionSchema,
+ GenericCreateAppConnectionFieldsSchema,
+ GenericUpdateAppConnectionFieldsSchema
+} from "@app/services/app-connection/app-connection-schemas";
+
+import { APP_CONNECTION_NAME_MAP } from "../app-connection-maps";
+import { OpenRouterConnectionMethod } from "./open-router-connection-enums";
+
+export const OpenRouterConnectionApiKeyCredentialsSchema = z.object({
+ apiKey: z
+ .string()
+ .trim()
+ .min(1, "API Key required")
+ .describe(AppConnections.CREDENTIALS.OPEN_ROUTER.apiKey)
+});
+
+const BaseOpenRouterConnectionSchema = BaseAppConnectionSchema.extend({ app: z.literal(AppConnection.OpenRouter) });
+
+export const OpenRouterConnectionSchema = BaseOpenRouterConnectionSchema.extend({
+ method: z.literal(OpenRouterConnectionMethod.ApiKey),
+ credentials: OpenRouterConnectionApiKeyCredentialsSchema
+});
+
+export const SanitizedOpenRouterConnectionSchema = z.discriminatedUnion("method", [
+ BaseOpenRouterConnectionSchema.extend({
+ method: z.literal(OpenRouterConnectionMethod.ApiKey),
+ credentials: z.object({})
+ }).describe(JSON.stringify({ title: `${APP_CONNECTION_NAME_MAP[AppConnection.OpenRouter]} (API Key)` }))
+]);
+
+export const ValidateOpenRouterConnectionCredentialsSchema = z.discriminatedUnion("method", [
+ z.object({
+ method: z
+ .literal(OpenRouterConnectionMethod.ApiKey)
+ .describe(AppConnections.CREATE(AppConnection.OpenRouter).method),
+ credentials: OpenRouterConnectionApiKeyCredentialsSchema.describe(
+ AppConnections.CREATE(AppConnection.OpenRouter).credentials
+ )
+ })
+]);
+
+export const CreateOpenRouterConnectionSchema = ValidateOpenRouterConnectionCredentialsSchema.and(
+ GenericCreateAppConnectionFieldsSchema(AppConnection.OpenRouter)
+);
+
+export const UpdateOpenRouterConnectionSchema = z
+ .object({
+ credentials: OpenRouterConnectionApiKeyCredentialsSchema.optional().describe(
+ AppConnections.UPDATE(AppConnection.OpenRouter).credentials
+ )
+ })
+ .and(GenericUpdateAppConnectionFieldsSchema(AppConnection.OpenRouter));
+
+export const OpenRouterConnectionListItemSchema = z
+ .object({
+ name: z.literal("OpenRouter"),
+ app: z.literal(AppConnection.OpenRouter),
+ methods: z.nativeEnum(OpenRouterConnectionMethod).array()
+ })
+ .describe(JSON.stringify({ title: APP_CONNECTION_NAME_MAP[AppConnection.OpenRouter] }));
diff --git a/backend/src/services/app-connection/open-router/open-router-connection-types.ts b/backend/src/services/app-connection/open-router/open-router-connection-types.ts
new file mode 100644
index 0000000000..8f9e53ead2
--- /dev/null
+++ b/backend/src/services/app-connection/open-router/open-router-connection-types.ts
@@ -0,0 +1,25 @@
+import z from "zod";
+
+import { DiscriminativePick } from "@app/lib/types";
+
+import { AppConnection } from "../app-connection-enums";
+import {
+ CreateOpenRouterConnectionSchema,
+ OpenRouterConnectionSchema,
+ ValidateOpenRouterConnectionCredentialsSchema
+} from "./open-router-connection-schemas";
+
+export type TOpenRouterConnection = z.infer<typeof OpenRouterConnectionSchema>;
+
+export type TOpenRouterConnectionInput = z.infer<typeof CreateOpenRouterConnectionSchema> & {
+ app: AppConnection.OpenRouter;
+};
+
+export type TValidateOpenRouterConnectionCredentialsSchema = typeof ValidateOpenRouterConnectionCredentialsSchema;
+
+export type TOpenRouterConnectionConfig = DiscriminativePick<
+ TOpenRouterConnectionInput,
+ "method" | "app" | "credentials"
+> & {
+ orgId: string;
+};
diff --git a/frontend/public/images/integrations/OpenRouter.png b/frontend/public/images/integrations/OpenRouter.png
new file mode 100644
index 0000000000..9643a73a6a
Binary files /dev/null and b/frontend/public/images/integrations/OpenRouter.png differ
diff --git a/frontend/src/helpers/appConnections.ts b/frontend/src/helpers/appConnections.ts
index f2bac4054d..9191a9015d 100644
--- a/frontend/src/helpers/appConnections.ts
+++ b/frontend/src/helpers/appConnections.ts
@@ -61,6 +61,7 @@ import { RailwayConnectionMethod } from "@app/hooks/api/appConnections/types/rai
import { RenderConnectionMethod } from "@app/hooks/api/appConnections/types/render-connection";
import { SshConnectionMethod } from "@app/hooks/api/appConnections/types/ssh-connection";
import { SupabaseConnectionMethod } from "@app/hooks/api/appConnections/types/supabase-connection";
+import { OpenRouterConnectionMethod } from "@app/hooks/api/appConnections/types/open-router-connection";
export const APP_CONNECTION_MAP: Record<
AppConnection,
@@ -140,7 +141,8 @@ export const APP_CONNECTION_MAP: Record<
},
[AppConnection.Chef]: { name: "Chef", image: "Chef.png", enterprise: true },
[AppConnection.OctopusDeploy]: { name: "Octopus Deploy", image: "Octopus Deploy.png" },
- [AppConnection.SSH]: { name: "SSH", image: "SSH.png" }
+ [AppConnection.SSH]: { name: "SSH", image: "SSH.png" },
+ [AppConnection.OpenRouter]: { name: "OpenRouter", image: "OpenRouter.png" }
};
export const getAppConnectionMethodDetails = (method: TAppConnection["method"]) => {
@@ -213,6 +215,7 @@ export const getAppConnectionMethodDetails = (method: TAppConnection["method"])
return { name: "Project Token", icon: faKey };
case RenderConnectionMethod.ApiKey:
case ChecklyConnectionMethod.ApiKey:
+ case OpenRouterConnectionMethod.ApiKey:
return { name: "API Key", icon: faKey };
case ChefConnectionMethod.UserKey:
return { name: "User Key", icon: faKey };
diff --git a/frontend/src/hooks/api/appConnections/enums.ts b/frontend/src/hooks/api/appConnections/enums.ts
index 634f8ba208..a5d035a13a 100644
--- a/frontend/src/hooks/api/appConnections/enums.ts
+++ b/frontend/src/hooks/api/appConnections/enums.ts
@@ -44,5 +44,6 @@ export enum AppConnection {
LaravelForge = "laravel-forge",
Chef = "chef",
OctopusDeploy = "octopus-deploy",
- SSH = "ssh"
+ SSH = "ssh",
+ OpenRouter = "open-router"
}
diff --git a/frontend/src/hooks/api/appConnections/types/index.ts b/frontend/src/hooks/api/appConnections/types/index.ts
index 4cf63d2182..ed1473c8db 100644
--- a/frontend/src/hooks/api/appConnections/types/index.ts
+++ b/frontend/src/hooks/api/appConnections/types/index.ts
@@ -34,6 +34,7 @@ import { TNorthflankConnection } from "./northflank-connection";
import { TOCIConnection } from "./oci-connection";
import { TOctopusDeployConnection } from "./octopus-deploy-connection";
import { TOktaConnection } from "./okta-connection";
+import { TOpenRouterConnection } from "./open-router-connection";
import { TOracleDBConnection } from "./oracledb-connection";
import { TPostgresConnection } from "./postgres-connection";
import { TRailwayConnection } from "./railway-connection";
@@ -80,6 +81,7 @@ export * from "./northflank-connection";
export * from "./oci-connection";
export * from "./octopus-deploy-connection";
export * from "./okta-connection";
+export * from "./open-router-connection";
export * from "./oracledb-connection";
export * from "./postgres-connection";
export * from "./railway-connection";
@@ -139,7 +141,8 @@ export type TAppConnection =
| TMongoDBConnection
| TChefConnection
| TDNSMadeEasyConnection
- | TSshConnection;
+ | TSshConnection
+ | TOpenRouterConnection;
export type TAvailableAppConnection = Pick<TAppConnection, "name" | "id" | "projectId">;
diff --git a/frontend/src/hooks/api/appConnections/types/open-router-connection.ts b/frontend/src/hooks/api/appConnections/types/open-router-connection.ts
new file mode 100644
index 0000000000..e7cbab45fd
--- /dev/null
+++ b/frontend/src/hooks/api/appConnections/types/open-router-connection.ts
@@ -0,0 +1,13 @@
+import { AppConnection } from "@app/hooks/api/appConnections/enums";
+import { TRootAppConnection } from "@app/hooks/api/appConnections/types/root-connection";
+
+export enum OpenRouterConnectionMethod {
+ ApiKey = "api-key"
+}
+
+export type TOpenRouterConnection = TRootAppConnection & { app: AppConnection.OpenRouter } & {
+ method: OpenRouterConnectionMethod.ApiKey;
+ credentials: {
+ apiKey: string;
+ };
+};
diff --git a/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/AppConnectionForm.tsx b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/AppConnectionForm.tsx
index 199858f47b..3464c1d72a 100644
--- a/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/AppConnectionForm.tsx
+++ b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/AppConnectionForm.tsx
@@ -43,6 +43,7 @@ import { NorthflankConnectionForm } from "./NorthflankConnectionForm";
import { OCIConnectionForm } from "./OCIConnectionForm";
import { OctopusDeployConnectionForm } from "./OctopusDeployConnectionForm";
import { OktaConnectionForm } from "./OktaConnectionForm";
+import { OpenRouterConnectionForm } from "./OpenRouterConnectionForm";
import { OracleDBConnectionForm } from "./OracleDBConnectionForm";
import { PostgresConnectionForm } from "./PostgresConnectionForm";
import { RailwayConnectionForm } from "./RailwayConnectionForm";
@@ -182,6 +183,8 @@ const CreateForm = ({ app, onComplete, projectId }: CreateFormProps) => {
return <OctopusDeployConnectionForm onSubmit={onSubmit} />;
case AppConnection.SSH:
return <SshConnectionForm onSubmit={onSubmit} />;
+ case AppConnection.OpenRouter:
+ return <OpenRouterConnectionForm onSubmit={onSubmit} />;
default:
throw new Error(`Unhandled App ${app}`);
}
@@ -346,6 +349,8 @@ const UpdateForm = ({ appConnection, onComplete }: UpdateFormProps) => {
return <OctopusDeployConnectionForm onSubmit={onSubmit} appConnection={appConnection} />;
case AppConnection.SSH:
return <SshConnectionForm onSubmit={onSubmit} appConnection={appConnection} />;
+ case AppConnection.OpenRouter:
+ return <OpenRouterConnectionForm onSubmit={onSubmit} appConnection={appConnection} />;
default:
throw new Error(`Unhandled App ${(appConnection as TAppConnection).app}`);
}
diff --git a/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/OpenRouterConnectionForm.tsx b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/OpenRouterConnectionForm.tsx
new file mode 100644
index 0000000000..07cc5d7772
--- /dev/null
+++ b/frontend/src/pages/organization/AppConnections/AppConnectionsPage/components/AppConnectionForm/OpenRouterConnectionForm.tsx
@@ -0,0 +1,133 @@
+import { Controller, FormProvider, useForm } from "react-hook-form";
+import { zodResolver } from "@hookform/resolvers/zod";
+import { z } from "zod";
+
+import {
+ Button,
+ FormControl,
+ ModalClose,
+ SecretInput,
+ Select,
+ SelectItem
+} from "@app/components/v2";
+import { APP_CONNECTION_MAP, getAppConnectionMethodDetails } from "@app/helpers/appConnections";
+import { OpenRouterConnectionMethod, TOpenRouterConnection } from "@app/hooks/api/appConnections";
+import { AppConnection } from "@app/hooks/api/appConnections/enums";
+
+import {
+ genericAppConnectionFieldsSchema,
+ GenericAppConnectionsFields
+} from "./GenericAppConnectionFields";
+
+type Props = {
+ appConnection?: TOpenRouterConnection;
+ onSubmit: (formData: FormData) => void;
+};
+
+const rootSchema = genericAppConnectionFieldsSchema.extend({
+ app: z.literal(AppConnection.OpenRouter)
+});
+
+const formSchema = z.discriminatedUnion("method", [
+ rootSchema.extend({
+ method: z.literal(OpenRouterConnectionMethod.ApiKey),
+ credentials: z.object({
+ apiKey: z.string().trim().min(1, "API Key required")
+ })
+ })
+]);
+
+type FormData = z.infer<typeof formSchema>;
+
+export const OpenRouterConnectionForm = ({ appConnection, onSubmit }: Props) => {
+ const isUpdate = Boolean(appConnection);
+
+ const form = useForm<FormData>({
+ resolver: zodResolver(formSchema),
+ defaultValues: appConnection ?? {
+ app: AppConnection.OpenRouter,
+ method: OpenRouterConnectionMethod.ApiKey
+ }
+ });
+
+ const {
+ handleSubmit,
+ control,
+ formState: { isSubmitting, isDirty }
+ } = form;
+
+ return (
+ <FormProvider {...form}>
+ <form onSubmit={handleSubmit(onSubmit)}>
+ {!isUpdate && <GenericAppConnectionsFields />}
+ <Controller
+ name="method"
+ control={control}
+ render={({ field: { value, onChange }, fieldState: { error } }) => (
+ <FormControl
+ tooltipText={`The method you would like to use to connect with ${
+ APP_CONNECTION_MAP[AppConnection.OpenRouter].name
+ }. This field cannot be changed after creation.`}
+ errorText={error?.message}
+ isError={Boolean(error?.message)}
+ label="Method"
+ >
+ <Select
+ isDisabled={isUpdate}
+ value={value}
+ onValueChange={(val) => onChange(val)}
+ className="w-full border border-mineshaft-500"
+ position="popper"
+ dropdownContainerClassName="max-w-none"
+ >
+ {Object.values(OpenRouterConnectionMethod).map((method) => {
+ return (
+ <SelectItem value={method} key={method}>
+ {getAppConnectionMethodDetails(method).name}{" "}
+ </SelectItem>
+ );
+ })}
+ </Select>
+ </FormControl>
+ )}
+ />
+ <Controller
+ name="credentials.apiKey"
+ control={control}
+ shouldUnregister
+ render={({ field: { value, onChange }, fieldState: { error } }) => (
+ <FormControl
+ errorText={error?.message}
+ isError={Boolean(error?.message)}
+ label="Provisioning API Key"
+ tooltipText="The OpenRouter Provisioning API key used to manage API keys."
+ >
+ <SecretInput
+ containerClassName="text-gray-400 group-focus-within:border-primary-400/50! border border-mineshaft-500 bg-mineshaft-900 px-2.5 py-1.5"
+ value={value}
+ onChange={(e) => onChange(e.target.value)}
+ />
+ </FormControl>
+ )}
+ />
+ <div className="mt-8 flex items-center">
+ <Button
+ className="mr-4"
+ size="sm"
+ type="submit"
+ colorSchema="secondary"
+ isLoading={isSubmitting}
+ isDisabled={isSubmitting || !isDirty}
+ >
+ {isUpdate ? "Update Credentials" : "Connect to OpenRouter"}
+ </Button>
+ <ModalClose asChild>
+ <Button colorSchema="secondary" variant="plain">
+ Cancel
+ </Button>
+ </ModalClose>
+ </div>
+ </form>
+ </FormProvider>
+ );
+};