Skip to content

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

feat(openrouter-rotation): workspace support

varonix647de5cc89e8
diff --git a/backend/src/ee/services/secret-rotation-v2/open-router-api-key/open-router-api-key-rotation-fns.ts b/backend/src/ee/services/secret-rotation-v2/open-router-api-key/open-router-api-key-rotation-fns.ts
index 333bd589b4..510f0a0c5b 100644
--- a/backend/src/ee/services/secret-rotation-v2/open-router-api-key/open-router-api-key-rotation-fns.ts
+++ b/backend/src/ee/services/secret-rotation-v2/open-router-api-key/open-router-api-key-rotation-fns.ts
@@ -45,7 +45,7 @@ export const openRouterApiKeyRotationFactory: TRotationFactory<
> = (secretRotation) => {
const {
connection,
- parameters: { name, limit, limitReset, includeByokInLimit },
+ parameters: { name, workspaceId, limit, limitReset, includeByokInLimit },
secretsMapping
} = secretRotation;
@@ -56,22 +56,15 @@ export const openRouterApiKeyRotationFactory: TRotationFactory<
*/
const $createApiKey = async () => {
try {
- const requestBody: {
- name: string;
- limit?: number | null;
- limit_reset?: string | null;
- include_byok_in_limit?: boolean | null;
- } = { name };
-
- if (limit !== undefined && limit !== null) {
- requestBody.limit = limit;
- }
- if (limitReset !== undefined && limitReset !== null) {
- requestBody.limit_reset = limitReset;
- }
- if (includeByokInLimit !== undefined && includeByokInLimit !== null) {
- requestBody.include_byok_in_limit = includeByokInLimit;
- }
+ const requestBody = {
+ name,
+ ...(workspaceId ? { workspace_id: workspaceId } : {}),
+ ...(limit !== undefined && limit !== null ? { limit } : {}),
+ ...(limitReset !== undefined && limitReset !== null ? { limit_reset: limitReset } : {}),
+ ...(includeByokInLimit !== undefined && includeByokInLimit !== null
+ ? { include_byok_in_limit: includeByokInLimit }
+ : {})
+ };
const { data } = await request.post<TOpenRouterApiKeyCreateResponse>(
`${OPEN_ROUTER_API_BASE_URL}/keys`,
diff --git a/backend/src/ee/services/secret-rotation-v2/open-router-api-key/open-router-api-key-rotation-schemas.ts b/backend/src/ee/services/secret-rotation-v2/open-router-api-key/open-router-api-key-rotation-schemas.ts
index e88edb55bd..26dde201ef 100644
--- a/backend/src/ee/services/secret-rotation-v2/open-router-api-key/open-router-api-key-rotation-schemas.ts
+++ b/backend/src/ee/services/secret-rotation-v2/open-router-api-key/open-router-api-key-rotation-schemas.ts
@@ -38,6 +38,7 @@ const OpenRouterApiKeyRotationParametersSchema = z.object({
`Key name must be ${OPEN_ROUTER_API_KEY_NAME_MAX_LENGTH} characters or fewer`
)
.describe(SecretRotations.PARAMETERS.OPEN_ROUTER_API_KEY.name),
+ workspaceId: z.string().trim().optional().describe(SecretRotations.PARAMETERS.OPEN_ROUTER_API_KEY.workspaceId),
limit: z.number().positive().optional().nullable().describe(SecretRotations.PARAMETERS.OPEN_ROUTER_API_KEY.limit),
limitReset: z
.nativeEnum(OpenRouterLimitReset)
diff --git a/backend/src/ee/services/secret-rotation-v2/open-router-api-key/open-router-api-key-rotation-types.ts b/backend/src/ee/services/secret-rotation-v2/open-router-api-key/open-router-api-key-rotation-types.ts
index f7d71ef362..2248466fcc 100644
--- a/backend/src/ee/services/secret-rotation-v2/open-router-api-key/open-router-api-key-rotation-types.ts
+++ b/backend/src/ee/services/secret-rotation-v2/open-router-api-key/open-router-api-key-rotation-types.ts
@@ -25,6 +25,7 @@ export type TOpenRouterApiKeyRotationGeneratedCredentials = z.infer<
export interface TOpenRouterApiKeyRotationParameters {
name: string;
+ workspaceId?: string;
limit?: number | null;
limitReset?: "daily" | "weekly" | "monthly" | null;
includeByokInLimit?: boolean | null;
diff --git a/backend/src/ee/services/secret-rotation-v2/secret-rotation-v2-fns.ts b/backend/src/ee/services/secret-rotation-v2/secret-rotation-v2-fns.ts
index a7664998b7..0d6356b7d7 100644
--- a/backend/src/ee/services/secret-rotation-v2/secret-rotation-v2-fns.ts
+++ b/backend/src/ee/services/secret-rotation-v2/secret-rotation-v2-fns.ts
@@ -28,7 +28,7 @@ import { MONGODB_CREDENTIALS_ROTATION_LIST_OPTION } from "./mongodb-credentials"
import { MSSQL_CREDENTIALS_ROTATION_LIST_OPTION } from "./mssql-credentials";
import { MYSQL_CREDENTIALS_ROTATION_LIST_OPTION } from "./mysql-credentials";
import { OKTA_CLIENT_SECRET_ROTATION_LIST_OPTION } from "./okta-client-secret";
-import { OPEN_ROUTER_API_KEY_ROTATION_LIST_OPTION } from "./open-router-api-key";
+import { OPEN_ROUTER_API_KEY_ROTATION_LIST_OPTION, TOpenRouterApiKeyRotation } from "./open-router-api-key";
import { OPENAI_SERVICE_ACCOUNT_ROTATION_LIST_OPTION, TOpenAIServiceAccountRotation } from "./openai-service-account";
import { ORACLEDB_CREDENTIALS_ROTATION_LIST_OPTION } from "./oracledb-credentials";
import { POSTGRES_CREDENTIALS_ROTATION_LIST_OPTION } from "./postgres-credentials";
@@ -429,6 +429,20 @@ export const throwOnImmutableParameterUpdate = (
throw new BadRequestError({ message: "Cannot update project ID" });
}
break;
+ case SecretRotation.OpenRouterApiKey:
+ if (
+ haveUnequalProperties(
+ updatePayload.parameters as TOpenRouterApiKeyRotation["parameters"],
+ secretRotation.parameters as TOpenRouterApiKeyRotation["parameters"],
+ ["workspaceId"]
+ )
+ ) {
+ throw new BadRequestError({
+ message:
+ "Cannot update the OpenRouter workspace of an existing rotation. Create a new rotation to use a different workspace."
+ });
+ }
+ break;
case SecretRotation.SnowflakeUserKeyPair:
if (
haveUnequalProperties(
diff --git a/backend/src/lib/api-docs/constants.ts b/backend/src/lib/api-docs/constants.ts
index 4b51107802..ca789122e9 100644
--- a/backend/src/lib/api-docs/constants.ts
+++ b/backend/src/lib/api-docs/constants.ts
@@ -3717,6 +3717,8 @@ export const SecretRotations = {
},
OPEN_ROUTER_API_KEY: {
name: "The name for the generated OpenRouter API key.",
+ workspaceId:
+ "The optional ID of the OpenRouter workspace to create API keys in. If omitted, OpenRouter creates keys in the account's Default workspace.",
limit: "The optional spending limit in USD for the generated API key.",
limitReset: "The type of limit reset for the API key (daily, weekly, monthly, or null for no reset).",
includeByokInLimit:
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
index 7e3a1a2d84..ec58c525b1 100644
--- 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
@@ -1,9 +1,14 @@
+import { z } from "zod";
+
+import { readLimit } from "@app/server/config/rateLimiter";
+import { verifyAuth } from "@app/server/plugins/auth/verify-auth";
import { AppConnection } from "@app/services/app-connection/app-connection-enums";
import {
CreateOpenRouterConnectionSchema,
SanitizedOpenRouterConnectionSchema,
UpdateOpenRouterConnectionSchema
} from "@app/services/app-connection/open-router";
+import { AuthMode } from "@app/services/auth/auth-type";
import { registerAppConnectionEndpoints } from "./app-connection-endpoints";
@@ -15,4 +20,33 @@ export const registerOpenRouterConnectionRouter = async (server: FastifyZodProvi
createSchema: CreateOpenRouterConnectionSchema,
updateSchema: UpdateOpenRouterConnectionSchema
});
+
+ // The below endpoints are not exposed and for Infisical App use
+
+ server.route({
+ method: "GET",
+ url: `/:connectionId/workspaces`,
+ config: {
+ rateLimit: readLimit
+ },
+ schema: {
+ operationId: "listOpenRouterConnectionWorkspaces",
+ params: z.object({
+ connectionId: z.string().uuid()
+ }),
+ response: {
+ 200: z.object({
+ workspaces: z.object({ id: z.string(), name: z.string(), slug: z.string() }).array()
+ })
+ }
+ },
+ onRequest: verifyAuth([AuthMode.JWT, AuthMode.OAUTH]),
+ handler: async (req) => {
+ const { connectionId } = req.params;
+
+ const workspaces = await server.services.appConnection.openRouter.listWorkspaces(connectionId, req.permission);
+
+ return { workspaces };
+ }
+ });
};
diff --git a/backend/src/services/app-connection/app-connection-service.ts b/backend/src/services/app-connection/app-connection-service.ts
index 0ee7e65120..49feff953d 100644
--- a/backend/src/services/app-connection/app-connection-service.ts
+++ b/backend/src/services/app-connection/app-connection-service.ts
@@ -167,6 +167,7 @@ import { oktaConnectionService } from "./okta/okta-connection-service";
import { ValidateOnaConnectionCredentialsSchema } from "./ona";
import { onaConnectionService } from "./ona/ona-connection-service";
import { ValidateOpenRouterConnectionCredentialsSchema } from "./open-router";
+import { openRouterConnectionService } from "./open-router/open-router-connection-service";
import { ValidateOpenAIConnectionCredentialsSchema } from "./openai";
import { openaiConnectionService } from "./openai/openai-connection-service";
import { ValidateOvhConnectionCredentialsSchema } from "./ovh";
@@ -1487,6 +1488,7 @@ export const appConnectionServiceFactory = ({
okta: oktaConnectionService(connectAppConnectionById),
datadog: datadogConnectionService(connectAppConnectionById),
openai: openaiConnectionService(connectAppConnectionById),
+ openRouter: openRouterConnectionService(connectAppConnectionById),
laravelForge: laravelForgeConnectionService(connectAppConnectionById),
chef: chefConnectionService(connectAppConnectionById, licenseService, gatewayV2Service, gatewayPoolService),
octopusDeploy: octopusDeployConnectionService(connectAppConnectionById),
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
index a635e33754..5dfb137d87 100644
--- 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
@@ -1,12 +1,23 @@
+import { AxiosError } from "axios";
+
import { request } from "@app/lib/config/request";
-import { UnauthorizedError } from "@app/lib/errors";
+import { BadRequestError, UnauthorizedError } from "@app/lib/errors";
+import { logger } from "@app/lib/logger";
import { AppConnection } from "@app/services/app-connection/app-connection-enums";
import { OpenRouterConnectionMethod } from "./open-router-connection-enums";
-import { TOpenRouterConnectionConfig } from "./open-router-connection-types";
+import {
+ TOpenRouterConnection,
+ TOpenRouterConnectionConfig,
+ TOpenRouterListWorkspacesResponse,
+ TOpenRouterWorkspace
+} from "./open-router-connection-types";
export const OPEN_ROUTER_API_BASE_URL = "https://openrouter.ai/api/v1";
+const OPEN_ROUTER_WORKSPACES_PAGE_SIZE = 100;
+const OPEN_ROUTER_WORKSPACES_MAX_PAGES = 50;
+
export const getOpenRouterConnectionListItem = () => {
return {
name: "OpenRouter" as const,
@@ -15,6 +26,52 @@ export const getOpenRouterConnectionListItem = () => {
};
};
+export const listOpenRouterWorkspaces = async (
+ appConnection: TOpenRouterConnection
+): Promise<Pick<TOpenRouterWorkspace, "id" | "name" | "slug">[]> => {
+ const { apiKey } = appConnection.credentials;
+
+ const workspaces: TOpenRouterWorkspace[] = [];
+
+ try {
+ let totalCount = 0;
+
+ for (let page = 0; page < OPEN_ROUTER_WORKSPACES_MAX_PAGES; page += 1) {
+ // eslint-disable-next-line no-await-in-loop
+ const { data } = await request.get<TOpenRouterListWorkspacesResponse>(`${OPEN_ROUTER_API_BASE_URL}/workspaces`, {
+ params: { offset: page * OPEN_ROUTER_WORKSPACES_PAGE_SIZE, limit: OPEN_ROUTER_WORKSPACES_PAGE_SIZE },
+ headers: {
+ Authorization: `Bearer ${apiKey}`,
+ "Content-Type": "application/json"
+ }
+ });
+
+ const pageWorkspaces = data.data ?? [];
+ workspaces.push(...pageWorkspaces);
+ totalCount = data.total_count ?? workspaces.length;
+
+ if (!pageWorkspaces.length || workspaces.length >= totalCount) break;
+ }
+
+ if (workspaces.length < totalCount) {
+ logger.warn(
+ `listOpenRouterWorkspaces: reached page cap [connectionId=${appConnection.id}] [returned=${workspaces.length}] [totalCount=${totalCount}]`
+ );
+ }
+ } catch (error: unknown) {
+ const upstreamMessage =
+ error instanceof AxiosError
+ ? ((error.response?.data as { error?: { message?: string } } | undefined)?.error?.message ?? error.message)
+ : "Unknown error";
+
+ throw new BadRequestError({
+ message: `Failed to list OpenRouter workspaces: ${upstreamMessage}`
+ });
+ }
+
+ return workspaces.map(({ id, name, slug }) => ({ id, name, slug }));
+};
+
export const validateOpenRouterConnectionCredentials = async (config: TOpenRouterConnectionConfig) => {
const { apiKey } = config.credentials;
diff --git a/backend/src/services/app-connection/open-router/open-router-connection-service.ts b/backend/src/services/app-connection/open-router/open-router-connection-service.ts
new file mode 100644
index 0000000000..43387fd086
--- /dev/null
+++ b/backend/src/services/app-connection/open-router/open-router-connection-service.ts
@@ -0,0 +1,22 @@
+import { OrgServiceActor } from "@app/lib/types";
+
+import { AppConnection } from "../app-connection-enums";
+import { listOpenRouterWorkspaces } from "./open-router-connection-fns";
+import { TOpenRouterConnection } from "./open-router-connection-types";
+
+type TGetAppConnectionFunc = (
+ app: AppConnection,
+ connectionId: string,
+ actor: OrgServiceActor
+) => Promise<TOpenRouterConnection>;
+
+export const openRouterConnectionService = (getAppConnection: TGetAppConnectionFunc) => {
+ const listWorkspaces = async (connectionId: string, actor: OrgServiceActor) => {
+ const appConnection = await getAppConnection(AppConnection.OpenRouter, connectionId, actor);
+ return listOpenRouterWorkspaces(appConnection);
+ };
+
+ return {
+ listWorkspaces
+ };
+};
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
index 8f9e53ead2..1fbbc4ffeb 100644
--- 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
@@ -23,3 +23,14 @@ export type TOpenRouterConnectionConfig = DiscriminativePick<
> & {
orgId: string;
};
+
+export type TOpenRouterWorkspace = {
+ id: string;
+ name: string;
+ slug: string;
+};
+
+export type TOpenRouterListWorkspacesResponse = {
+ data: TOpenRouterWorkspace[];
+ total_count: number;
+};
diff --git a/docs/documentation/platform/secret-rotation/openrouter-api-key.mdx b/docs/documentation/platform/secret-rotation/openrouter-api-key.mdx
index 11161ee5fc..fa5bfca28f 100644
--- a/docs/documentation/platform/secret-rotation/openrouter-api-key.mdx
+++ b/docs/documentation/platform/secret-rotation/openrouter-api-key.mdx
@@ -38,6 +38,7 @@ description: "Learn how to automatically rotate OpenRouter API keys."
![Rotation Parameters](/images/secret-rotations-v2/openrouter-api-key/parameters.png)
+ - **Workspace** (optional) – The OpenRouter workspace to create keys in, which you can't change after you create the rotation (if you leave this blank, OpenRouter uses your Default workspace)
- **Key name** – Display name for the key in OpenRouter (required).
- **Limit** (optional) – Spending limit in USD for this key.
- **Limit reset** (optional) – How often the limit resets: daily, weekly, or monthly.
@@ -88,6 +89,7 @@ description: "Learn how to automatically rotate OpenRouter API keys."
},
"parameters": {
"name": "my-app-key",
+ "workspaceId": "<openrouter-workspace-id>",
"limit": 100,
"limitReset": "monthly",
"includeByokInLimit": false
@@ -117,6 +119,7 @@ description: "Learn how to automatically rotate OpenRouter API keys."
"type": "openrouter-api-key",
"parameters": {
"name": "my-app-key",
+ "workspaceId": "<openrouter-workspace-id>",
"limit": 100,
"limitReset": "monthly",
"includeByokInLimit": false
diff --git a/frontend/src/components/secret-rotations-v2/forms/SecretRotationV2ParametersFields/OpenRouterApiKeyRotationParametersFields.tsx b/frontend/src/components/secret-rotations-v2/forms/SecretRotationV2ParametersFields/OpenRouterApiKeyRotationParametersFields.tsx
index 3d10bd40f8..33fc17682c 100644
--- a/frontend/src/components/secret-rotations-v2/forms/SecretRotationV2ParametersFields/OpenRouterApiKeyRotationParametersFields.tsx
+++ b/frontend/src/components/secret-rotations-v2/forms/SecretRotationV2ParametersFields/OpenRouterApiKeyRotationParametersFields.tsx
@@ -1,4 +1,5 @@
import { Controller, useFormContext } from "react-hook-form";
+import { SingleValue } from "react-select";
import { TSecretRotationV2Form } from "@app/components/secret-rotations-v2/forms/schemas";
import { FieldLabelWithTooltip } from "@app/components/secret-rotations-v2/forms/shared";
@@ -7,6 +8,7 @@ import {
FieldContent,
FieldError,
FieldFeedback,
+ FilterableSelect,
Input,
Label,
Select,
@@ -16,6 +18,10 @@ import {
SelectValue,
Toggle
} from "@app/components/v3";
+import {
+ TOpenRouterWorkspace,
+ useListOpenRouterConnectionWorkspaces
+} from "@app/hooks/api/appConnections/open-router";
import { SecretRotation } from "@app/hooks/api/secretRotationsV2";
import { OpenRouterLimitReset } from "@app/hooks/api/secretRotationsV2/types/open-router-api-key-rotation";
@@ -39,9 +45,56 @@ export const OpenRouterApiKeyRotationParametersFields = () => {
>();
const limit = watch("parameters.limit");
+ const connectionId = watch("connection.id");
+ const isUpdate = Boolean(watch("id"));
+
+ const { data: workspaces, isPending: isWorkspacesPending } =
+ useListOpenRouterConnectionWorkspaces(connectionId, {
+ enabled: Boolean(connectionId)
+ });
return (
<>
+ <Controller
+ name="parameters.workspaceId"
+ control={control}
+ render={({ field: { value, onChange, onBlur }, fieldState: { error } }) => (
+ <Field data-invalid={Boolean(error)}>
+ <FieldLabelWithTooltip
+ htmlFor="openrouter-workspace"
+ tooltip="The OpenRouter workspace to create API keys in. Leave blank to use your OpenRouter Default workspace. This cannot be changed after the rotation is created."
+ >
+ Workspace <span className="font-normal text-muted">(optional)</span>
+ </FieldLabelWithTooltip>
+ <FilterableSelect
+ inputId="openrouter-workspace"
+ isClearable
+ isLoading={isWorkspacesPending && Boolean(connectionId)}
+ isDisabled={!connectionId || isUpdate}
+ value={
+ workspaces?.find((workspace) => workspace.id === value) ??
+ (value ? { id: value, name: value, slug: value } : null)
+ }
+ onBlur={onBlur}
+ onChange={(option) => {
+ onChange((option as SingleValue<TOpenRouterWorkspace>)?.id || undefined);
+ }}
+ options={workspaces}
+ placeholder="Select a workspace..."
+ getOptionLabel={(option) => option.name}
+ getOptionValue={(option) => option.id}
+ isError={Boolean(error)}
+ />
+ {(isUpdate || error?.message) && (
+ <FieldFeedback
+ id="openrouter-workspace-feedback"
+ description={isUpdate ? "Cannot be updated." : undefined}
+ error={error?.message}
+ />
+ )}
+ </Field>
+ )}
+ />
<Controller
name="parameters.name"
control={control}
diff --git a/frontend/src/components/secret-rotations-v2/forms/SecretRotationV2ReviewFields/OpenRouterApiKeyRotationReviewFields.tsx b/frontend/src/components/secret-rotations-v2/forms/SecretRotationV2ReviewFields/OpenRouterApiKeyRotationReviewFields.tsx
index 99ed4f7c19..f7e5fb451d 100644
--- a/frontend/src/components/secret-rotations-v2/forms/SecretRotationV2ReviewFields/OpenRouterApiKeyRotationReviewFields.tsx
+++ b/frontend/src/components/secret-rotations-v2/forms/SecretRotationV2ReviewFields/OpenRouterApiKeyRotationReviewFields.tsx
@@ -25,6 +25,9 @@ export const OpenRouterApiKeyRotationReviewFields = () => {
<>
<SecretRotationReviewSection label="Parameters">
<ReviewField label="Key Name">{parameters.name}</ReviewField>
+ {parameters.workspaceId && (
+ <ReviewField label="Workspace ID">{parameters.workspaceId}</ReviewField>
+ )}
{parameters.limit != null && (
<ReviewField label="Credit Limit">${parameters.limit} USD</ReviewField>
)}
diff --git a/frontend/src/components/secret-rotations-v2/forms/schemas/open-router-api-key-rotation-schema.ts b/frontend/src/components/secret-rotations-v2/forms/schemas/open-router-api-key-rotation-schema.ts
index bd33a09065..ec3daf9d74 100644
--- a/frontend/src/components/secret-rotations-v2/forms/schemas/open-router-api-key-rotation-schema.ts
+++ b/frontend/src/components/secret-rotations-v2/forms/schemas/open-router-api-key-rotation-schema.ts
@@ -19,6 +19,7 @@ export const OpenRouterApiKeyRotationSchema = z
OPEN_ROUTER_API_KEY_NAME_MAX_LENGTH,
`Key name must be ${OPEN_ROUTER_API_KEY_NAME_MAX_LENGTH} characters or fewer`
),
+ workspaceId: z.string().trim().optional(),
limit: z.number().positive().optional().nullable(),
limitReset: z.nativeEnum(OpenRouterLimitReset).optional().nullable(),
includeByokInLimit: z.boolean().optional().nullable()
diff --git a/frontend/src/hooks/api/appConnections/open-router/index.ts b/frontend/src/hooks/api/appConnections/open-router/index.ts
new file mode 100644
index 0000000000..2c1906d369
--- /dev/null
+++ b/frontend/src/hooks/api/appConnections/open-router/index.ts
@@ -0,0 +1,2 @@
+export * from "./queries";
+export * from "./types";
diff --git a/frontend/src/hooks/api/appConnections/open-router/queries.tsx b/frontend/src/hooks/api/appConnections/open-router/queries.tsx
new file mode 100644
index 0000000000..2e57521ebd
--- /dev/null
+++ b/frontend/src/hooks/api/appConnections/open-router/queries.tsx
@@ -0,0 +1,37 @@
+import { useQuery, UseQueryOptions } from "@tanstack/react-query";
+
+import { apiRequest } from "@app/config/request";
+
+import { appConnectionKeys } from "../queries";
+import { TOpenRouterWorkspace } from "./types";
+
+const openRouterConnectionKeys = {
+ all: [...appConnectionKeys.all, "open-router"] as const,
+ listWorkspaces: (connectionId: string) =>
+ [...openRouterConnectionKeys.all, "workspaces", connectionId] as const
+};
+
+export const useListOpenRouterConnectionWorkspaces = (
+ connectionId: string,
+ options?: Omit<
+ UseQueryOptions<
+ TOpenRouterWorkspace[],
+ unknown,
+ TOpenRouterWorkspace[],
+ ReturnType<typeof openRouterConnectionKeys.listWorkspaces>
+ >,
+ "queryKey" | "queryFn"
+ >
+) => {
+ return useQuery({
+ queryKey: openRouterConnectionKeys.listWorkspaces(connectionId),
+ queryFn: async () => {
+ const { data } = await apiRequest.get<{ workspaces: TOpenRouterWorkspace[] }>(
+ `/api/v1/app-connections/open-router/${connectionId}/workspaces`
+ );
+
+ return data.workspaces;
+ },
+ ...options
+ });
+};
diff --git a/frontend/src/hooks/api/appConnections/open-router/types.ts b/frontend/src/hooks/api/appConnections/open-router/types.ts
new file mode 100644
index 0000000000..14f510d5e6
--- /dev/null
+++ b/frontend/src/hooks/api/appConnections/open-router/types.ts
@@ -0,0 +1,5 @@
+export type TOpenRouterWorkspace = {
+ id: string;
+ name: string;
+ slug: string;
+};
diff --git a/frontend/src/hooks/api/secretRotationsV2/types/open-router-api-key-rotation.ts b/frontend/src/hooks/api/secretRotationsV2/types/open-router-api-key-rotation.ts
index 0dcd7dbe24..3bc301cd41 100644
--- a/frontend/src/hooks/api/secretRotationsV2/types/open-router-api-key-rotation.ts
+++ b/frontend/src/hooks/api/secretRotationsV2/types/open-router-api-key-rotation.ts
@@ -15,6 +15,7 @@ export type TOpenRouterApiKeyRotation = TSecretRotationV2Base & {
type: SecretRotation.OpenRouterApiKey;
parameters: {
name: string;
+ workspaceId?: string;
limit?: number | null;
limitReset?: OpenRouterLimitReset | null;
includeByokInLimit?: boolean | null;