Failed to send notification: ErrorDto: API Key not found

lib/novu.ts
'server-only';

import { Novu } from '@novu/api';
import { env } from '~/env';

export const novu = new Novu({
  secretKey: env.NOVU_SECRET_KEY,
  serverURL: 'https://eu.api.novu.co'
});


router/account-link.ts
sendLinkRequest: protectedProcedure
    .input(z.object({
      target_user_id: z.number(),
      message: z.string().optional(),
    }))
    .mutation(async ({ ctx, input }) => {
      ...
      // Send Novu notification
      try {
        await novu.trigger({
          workflowId: 'account-link-request',
          to: {
            subscriberId: targetUser.clerk_id,
            email: targetUser.email,
            firstName: targetUser.firstname,
            lastName: targetUser.lastname,
          },
          payload: {
            requesterName: `${currentUser.firstname} ${currentUser.lastname}`,
            requesterEmail: currentUser.email,
            requesterType: currentUser.account_type,
            targetType: targetUser.account_type,
            message: input.message || '',
            requestId: linkRequest[0]?.id,
            actionUrl: `${env.NEXT_PUBLIC_BASE_URL}/settings?request=${linkRequest[0]?.id}`,
          },
        });
      } catch (error) {
        console.error('Failed to send notification:', error);
        // Continue even if notification fails
      }


In Nextjs I get the following error:
'data$': {
statusCode: 401,
timestamp: '2025-06-10T11:06:55.596Z',
path: '/v1/events/trigger',
message: 'API Key not found',
ctx: { error: 'Unauthorized', statusCode: 401 }
},

Deps:
"next": "14.2.25",
"@novu/api": "^1.3.0",
"@novu/nextjs": "^3.5.0"

@Pawan Jain
Was this page helpful?