Resend error
Missing API key. Pass it to the constructor new Resend("re_123")
"Missing API key. Pass it to the constructor new Resend("re_123")" is thrown by the resend Node SDK when new Resend() gets no key and process.env.RESEND_API_KEY is unset or empty. It happens before any request to Resend. On Vercel it usually shows up in the build log as "Failed to collect page data" because the client is created at the top of a route file and next build imports that file, or at runtime in a function whose environment lacks the variable. Add RESEND_API_KEY in the project's Environment Variables for each environment that builds or runs the code, then redeploy, because changes apply only to new deployments. Reproduced with resend 6.37.0 on 2026-10-31.
Why does next build fail with this error when next dev works?
The constructor reads the variable at the moment it runs. In resend-node it uses the key you pass, and when that is empty it falls back to process.env.RESEND_API_KEY and throws if that is empty too. Locally the key sits in .env.local. On Vercel the variable has to exist in the environment of the deployment: each variable is applied to the environments you select, and Vercel's docs say your code can read it during the Build Step or during Function execution.
We built a Next.js 15.5.28 app with resend 6.37.0, a client created at the top of app/api/send/route.ts and RESEND_API_KEY unset, on 2026-10-31. The build stopped while collecting page data:
Collecting page data ...
Error: Missing API key. Pass it to the constructor new Resend("re_123")
at new <anonymous> (.next/server/app/api/send/route.js)
> Build error occurred
[Error: Failed to collect page data for /api/send]Is it enough to create the client inside the handler?
It gets the build past the error. In the same app, with the line moved into the POST handler and the variable still unset, next build completed. The error then moves to the first request that sends mail, so the variable still has to be set. Treat this as a way to keep builds independent of the key, not as the fix.
The same pattern with another client is covered in the Next.js collect page data error.
export async function POST() {
const resend = new Resend(process.env.RESEND_API_KEY);
const { data, error } = await resend.emails.send({ from, to, subject, html });
return Response.json({ data, error });
}Is this the same as the 401 "Missing API Key" from the Resend API?
No. The SDK error above is thrown by the constructor, before any request leaves your server. The API has its own errors: 401 missing_api_key with the message "Missing API Key" when the Authorization header is absent, and 400 or 401 validation_error with "API key is invalid" when the key is wrong, per the Resend error list. If you see the SDK message, the key never reached the code. If you see an API message, a key was sent and Resend refused it.
Checklist
How to fix it, then check the fix
- 01Find where the client is created and which variable it reads:
grep -rnE "new Resend\(|RESEND_API_KEY" --exclude-dir=node_modules --exclude-dir=.next . - 02In the Resend dashboard, create or copy an API key from the API Keys page. Do not paste it into code, a chat or a committed file.
- 03In the Vercel project, open Environment Variables and add RESEND_API_KEY, selecting every environment that builds or runs the code (Production, and Preview if previews send mail). Make sure the value is not empty.
- 04Redeploy: Vercel applies changed variables only to new deployments, so the failing deployment will not pick it up.
- 05If the build does not need the key, create the client inside the function that sends mail instead of at the top of the file.
- 06Check the new build log has no "Failed to collect page data" line, then trigger one email and confirm the call returns data with an id and error set to null.
Related
Related guides
Sources
Official docs behind this checklist
Browse all launch guides · Read resources · How to make and check your next change
FAQ
FAQ for builders before launch
If I pass an empty key, does it use RESEND_API_KEY?
Yes. In resend-node, a falsy key makes the constructor read process.env.RESEND_API_KEY, and it throws only if that is empty too. We ran new Resend() with the variable unset and with it set to an empty string, and both threw.
Why does the error only appear on a Preview deployment?
Vercel applies each variable only to the environments you selected for it. A variable set for Production alone is missing from Preview deployments, which are built from other branches.
Where do I get the key to put in the variable?
Resend's error list sends you to the API Keys page in the dashboard to check a key or create a new one. Paste it only into the Vercel Environment Variables screen or a local .env file that is not committed.