V Vercel

How to add cron jobs on Vercel

intermediate 12 min read Updated 2026-03-13
Quick Answer

Configure Vercel cron jobs in <code>vercel.json</code> with a <code>crons</code> array specifying <code>path</code> and <code>schedule</code> cron expression, create a matching API route endpoint, deploy to production, and monitor in the dashboard. Free tier limits to 1-2 jobs with daily frequency; use Pro for more. Design handlers as idempotent and secure with <code>CRON_SECRET</code>.

Prerequisites

  • Vercel account and project linked to Git
  • Serverless or Edge Function API route knowledge
  • Basic cron expression syntax
  • Familiarity with Vercel deployments
  • Node.js or TypeScript for handlers

Step-by-Step Instructions

1

Create Serverless or Edge Function endpoint

Add a function file at the path you'll reference, such as api/cron.ts or app/api/cron/route.ts in Next.js. This handles cron invocations via HTTP GET. Example for Node.js:
import type { VercelRequest, VercelResponse } from '@vercel/node';
export default function handler(req: VercelRequest, res: VercelResponse) {
  // Your task logic here (make idempotent for duplicates)
  res.status(200).json({ success: true });
}
Path must start with /; test locally with curl http://localhost:3000/api/cron.
Design for idempotency using unique IDs or timestamps to handle potential duplicates safely.
2

Secure the cron endpoint

Add an environment variable CRON_SECRET (random 16+ chars) in Vercel dashboard. Check Authorization header in handler:
const authHeader = req.headers.authorization;
if (!process.env.CRON_SECRET || authHeader !== `Bearer ${process.env.CRON_SECRET}`) {
  return res.status(401).json({ success: false });
}
// Proceed with task
Vercel auto-sends it as Bearer token on invocation.
3

Configure vercel.json at project root

Create or edit vercel.json with crons array. Each job needs path (starts with /, e.g. "/api/cron") and schedule (5-field cron string, UTC). Example for daily 5 AM:
{
  "crons": [
    {
      "path": "/api/cron",
      "schedule": "0 5 * * *"
    }
  ]
}
Examples: every 24h "0 0 * * *", hourly "0 * * * *".
Validate cron syntax; Hobby limits to once/day max, expressions fail otherwise.
4

Deploy to production

Push to production branch (e.g. main) for auto-deploy, or use CLI vercel --prod. Crons activate only on production deployments (previews ignored). Invocations hit your prod URL like https://your-project.vercel.app/api/cron. Post-build, jobs are live.
Use production domain; preview branches skip crons entirely.
5

Verify in Vercel Dashboard

Log in at vercel.com/dashboard, select Project > Settings > Cron Jobs tab. Lists active jobs with paths/schedules/next run. Click View Logs to filter logs by requestPath:/api/cron.
6

Monitor and test locally

Test endpoint locally: curl http://localhost:3000/api/cron (prod skips redirects). Dashboard shows invocations, errors. Jobs non-concurrent by default; duration matches Function limits.
Cron accuracy: Hobby ~1-hour window; Pro more precise.
7

Update or disable crons

Edit vercel.json (change schedule/path or remove), redeploy. Or use dashboard Disable Cron Jobs button (re-enable via redeploy). Changes reflect post-deploy.
Pro/Enterprise: Up to 40/100 jobs, unlimited frequency.
8

Handle concurrency and idempotency

Design tasks idempotent: use IDs/timestamps, check state before changes. Combine with locks for reliability. Avoid side effects on duplicates.

Common Issues & Troubleshooting

Cron not triggering or no dashboard entry

Ensure production deployment (previews ignored); redeploy via Git push to main or <code>vercel --prod</code>. Check Cron Jobs tab.

Build fails with invalid config

Validate <code>vercel.json</code> JSON and cron syntax (5 fields, path starts with <code>/</code>). Hobby: once/day max.

401 Unauthorized on invocation

Set <code>CRON_SECRET</code> env var and verify <code>Authorization: Bearer ${process.env.CRON_SECRET}</code> in handler.

Timeouts or cold starts

Optimize handler; add <code>?__no_cache=1</code> query if cached. Upgrade to Pro for better reliability.

Frequent jobs fail on Hobby

Free/Hobby limits 1-2 jobs, daily only. Upgrade to Pro for up to 40 jobs, any frequency.