diff --git a/packages/components/nodes/moderation/OpenAIModeration/OpenAIModerationRunner.ts b/packages/components/nodes/moderation/OpenAIModeration/OpenAIModerationRunner.ts index 3a3ec550273..34447f65829 100644 --- a/packages/components/nodes/moderation/OpenAIModeration/OpenAIModerationRunner.ts +++ b/packages/components/nodes/moderation/OpenAIModeration/OpenAIModerationRunner.ts @@ -5,8 +5,15 @@ export class OpenAIModerationRunner implements Moderation { private openAIApiKey = '' private moderationErrorMessage: string = "Text was found that violates OpenAI's content policy." - constructor(openAIApiKey: string) { - this.openAIApiKey = openAIApiKey + constructor(openAIApiKey: any) { + // Handle case where openAIApiKey might be passed as an object instead of a string + if (typeof openAIApiKey === 'object' && openAIApiKey !== null) { + // If it's an object, try to extract the key from common property names + const potentialKey = openAIApiKey.openAIApiKey || openAIApiKey.apiKey || openAIApiKey.key; + this.openAIApiKey = typeof potentialKey === 'string' ? potentialKey : ''; + } else { + this.openAIApiKey = openAIApiKey || '' + } } async checkForViolations(input: string): Promise {