koala73/worldmonitor · critical · Error

[sendProLaunchBroadcast] RESEND_API_KEY not set

Error message

[sendProLaunchBroadcast] RESEND_API_KEY not set

What it means

Thrown by sendProLaunchBroadcast when process.env.RESEND_API_KEY is falsy (undefined or empty string). This is a pre-flight environment check that fires before any HTTP call to Resend. The Convex environment variable must be set in the deployment's environment configuration.

Source

Thrown at convex/broadcast/sendBroadcast.ts:153

/**
 * Send (or schedule) a previously-created Resend Broadcast.
 *
 * `scheduledAt`: ISO 8601 timestamp string OR a natural-language phrase
 * Resend accepts ("in 2 hours"). Omit for immediate send.
 *
 * Resend's send endpoint is fire-and-forget — it returns immediately
 * after queueing. Track delivery via the `broadcastEvents` table
 * (populated by webhook events) or the `getBroadcastStats` action.
 */
export const sendProLaunchBroadcast = internalAction({
  args: {
    broadcastId: v.string(),
    scheduledAt: v.optional(v.string()),
  },
  handler: async (_ctx, { broadcastId, scheduledAt }) => {
    const apiKey = process.env.RESEND_API_KEY;
    if (!apiKey) {
      throw new Error("[sendProLaunchBroadcast] RESEND_API_KEY not set");
    }

    const body: Record<string, unknown> = {};
    if (scheduledAt) body.scheduled_at = scheduledAt;

    const res = await fetch(
      `${RESEND_API_BASE}/broadcasts/${encodeURIComponent(broadcastId)}/send`,
      {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          Authorization: `Bearer ${apiKey}`,
          "User-Agent": USER_AGENT,
        },
        body: JSON.stringify(body),
      },
    );

View on GitHub (pinned to ffec79ac33)

Solutions

  1. Set the variable: `npx convex env set RESEND_API_KEY re_xxxxx` (use the key from the Resend dashboard > API Keys).
  2. Verify it is set in the correct deployment target — run `npx convex env` or check `npx convex dashboard` for the target you are invoking.
  3. Confirm the key has no leading/trailing whitespace or quotes when pasted.
Defensive patterns

Strategy: validation

Validate before calling

function assertResendKey(): void {
  if (!process.env.RESEND_API_KEY) {
    throw new Error("RESEND_API_KEY not set — run: npx convex env set RESEND_API_KEY re_xxxxx");
  }
}
// call before sendProLaunchBroadcast

Prevention

When it happens

Trigger: Running sendProLaunchBroadcast in a Convex deployment where the RESEND_API_KEY environment variable was never set. The variable was set in the dev deployment but not in production (or vice versa). The variable name has a typo or trailing whitespace in the Convex dashboard.

Common situations: A new Convex deployment was created without copying env vars from the old one. The key was cleared during an environment cleanup. Running against a preview deployment that does not inherit production secrets.

Related errors


AI-assisted analysis of koala73/worldmonitor@ffec79ac33 (2026-08-12). Data as JSON: /api/errors/fd6998df431f5c66. Report an issue: GitHub.