Vercel Functions error tracking your coding agent can read
A Vercel Function can be frozen as soon as it responds, and the Runheed Node SDK batches events for up to 5 seconds, so the send has to be part of the request. waitUntil from @vercel/functions keeps the function alive until the error is sent without making the user wait for it. Vercel also sets VERCEL_ENV and VERCEL_GIT_COMMIT_SHA, so every error carries the deploy that caused it, and your agent can resolve it with the commit that fixed it.
Set it up
1.Install the SDK and Vercel's helper, and add RUNHEED_DSN under Project Settings > Environment Variables (or with the CLI).
terminalbashnpm install https://runheed.com/dl/runheed-0.1.0.tgz @vercel/functions vercel env add RUNHEED_DSN production2.Report the error, return the response, and let waitUntil finish the send.
api/checkout.tstypescriptimport runheed from 'runheed'; import { waitUntil } from '@vercel/functions'; runheed.init({ dsn: process.env.RUNHEED_DSN!, environment: process.env.VERCEL_ENV ?? 'development', release: process.env.VERCEL_GIT_COMMIT_SHA, }); export default { async fetch(request: Request): Promise<Response> { try { const { cartId } = await request.json(); // ...your code return Response.json({ ok: true, cartId }); } catch (err) { runheed.captureException(err as Error, { method: request.method, url: request.url, region: process.env.VERCEL_REGION }); waitUntil(runheed.flush()); return Response.json({ error: 'Internal error' }, { status: 500 }); } }, };3.Next.js 15.1 or later on Vercel: in a route handler, after() from next/server does the same job (Vercel recommends it over waitUntil in Next.js). For errors that escape your code, use the onRequestError setup on the Next.js page.
app/api/checkout/route.tstypescriptimport { after } from 'next/server'; import runheed from 'runheed'; export async function POST(request: Request) { try { // ...your code return Response.json({ ok: true }); } catch (err) { runheed.captureException(err as Error, { route: '/api/checkout' }); after(() => runheed.flush()); return Response.json({ error: 'Internal error' }, { status: 500 }); } }4.Connect your agent with the server URL and a sign-in (Claude Code shown; Cursor, claude.ai and ChatGPT take the same URL).
terminalbashclaude mcp add --transport http runheed https://runheed.com/api/mcp
The npm and PyPI releases are not out yet, so these commands install the same package files straight from runheed.com. Nothing else changes when the registry versions ship.
What it catches
- Errors in Vercel Functions on the Node.js runtime, with method, URL, region, environment and the deploy's commit
- Errors you report yourself with captureException and any context you pass
- Preview and production deploys kept apart by environment (VERCEL_ENV)
What it does not do
- A function that hits its maxDuration is stopped, and pending waitUntil work is cancelled with it
- Edge runtime functions need the fetch-based setup from the Cloudflare Workers page instead of the Node SDK
- Browser errors are not captured; there is no browser SDK yet
Then ask your agent
> what broke in production since the last deploy? fix the top one and resolve it with the commit hash
Common Vercel Functions errors
- SyntaxError: Unexpected token '<', "<!DOCTYPE "... is not valid JSON
- TypeError: fetch failed
- TypeError: Cannot read properties of undefined (reading 'x')
- [UnhandledPromiseRejection: This error originated either by throwing inside of an async...
- Error: Cannot find module 'x'
- Error: Failed to find Server Action "7f3a9c2e". This request might be from an older or ...
- ChunkLoadError: Loading chunk 4512 failed. (missing: https://example.com/_next/static/c...