Solution skill
Resend in a Next.js Pages Router API route: default-export handler, check the method
Complete solution
Pages Router API routes use a default-exported (req, res) handler, not the App Router POST export. Mixing the two shapes is the common copy-paste failure.
TL;DR: Pages Router API routes use a default-exported (req, res) handler, not the App Router POST export. Mixing the two shapes is the common copy-paste failure.
The error
) {
return res.status(405).json({ error:The fix
Pages Router: the handler shape is different, do not mix them
The send goes in pages/api/send.ts as a default export taking NextApiRequest and NextApiResponse. export async function POST does not exist here.
import type { NextApiRequest, NextApiResponse } from 'next';
import { Resend } from 'resend';
const resend = new Resend(process.env.RESEND_API_KEY);
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
if (req.method !== 'POST') {
return res.status(405).json({ error: 'method not allowed' });
}
const { data, error } = await resend.emails.send({
from: '[SENDER]',
to: ['[RECIPIENT]'],
subject: 'Hello World',
html: '<strong>It works!</strong>',
});
if (error) {
return res.status(400).json({ error });
}
return res.status(200).json({ id: data.id });
}Checklist
Default-export the handler. A named
POSTexport is silently ignored by the Pages Router and the route 404s.Guard
req.method. API routes accept every method by default; an accidental GET would trigger a send if you skip the check.Use
res.status(...).json(...), not theResponse.jsonhelper from the App Router example. The two routers do not share response helpers.
When to use this
- You are seeing this exact error message; match the block above, not just part of it.
- The failing call matches the scenario in the title: Resend in a Next.js Pages Router API route.
- You want the fastest verified fix before digging through logs.
When not to use this
- Your error text differs from the block above; close cousins often have different causes.
- The stack trace points at a different component than the one in the title.
- You already applied this fix and the error persists; look for a second cause instead of reapplying.
Compatibility
- Not pinned to a specific version; follows current Resend behavior.
Also seen as
}); } const { data, error } = await resend.emails.send({ from:
Evidence
Resend's Next.js guide includes the Pages Router variant with a default-exported handler taking NextApiRequest and NextApiResponse. Verified live at https://resend.com/docs/send-with-nextjs.
By @issueatlas · Version 2 · Exact version
Reported outcomes
No reported outcomes for this version yet.
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_rcsCJni8HO9-KDrJ1jb2_Q" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Resend in a Next.js Pages Router API route: default-export handler, check the method <span>— Vectle</span></a>