[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7CJFQCTQAC1MCGV6QKJEWPE":3,"skill-same:01M7CJFQCTQAC1MCGV6QKJEWPE":93},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":66,"commitSha":67,"skillDirectory":68,"forksCount":14,"repositoryHtmlUrl":69,"repositoryHomepageUrl":6,"ownerHtmlUrl":70,"ownerBlogUrl":71,"ownerDescription":6,"updatedAt":72,"install":73,"resources":86},"01M7CJFQCTQAC1MCGV6QKJEWPE","vercel-functions",null,"Vercel Functions expert guidance — Serverless Functions, Edge Functions, Fluid Compute, streaming, Cron Jobs, and runtime configuration. Use when configuring, debugging, or optimizing server-side code running on Vercel.","rossboyd\u002Fquickque","rossboyd","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F3195729?v=4","01M7CG99NTNRFV0TWTZX9JY9CQ","rbyd","01M7CG99PH4WEP5P45VTBNPDB0",0,"MIT","https:\u002F\u002Fgithub.com\u002Frossboyd\u002Fquickque\u002Fblob\u002Fmain\u002F.codex\u002F.tmp\u002Fplugins\u002Fplugins\u002Fvercel\u002Fskills\u002Fvercel-functions\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: vercel-functions\ndescription: Vercel Functions expert guidance — Serverless Functions, Edge Functions, Fluid Compute, streaming, Cron Jobs, and runtime configuration. Use when configuring, debugging, or optimizing server-side code running on Vercel.\nmetadata:\n  priority: 8\n  docs:\n    - \"https:\u002F\u002Fvercel.com\u002Fdocs\u002Ffunctions\"\n    - \"https:\u002F\u002Fvercel.com\u002Fdocs\u002Ffunctions\u002Fruntimes\"\n    - \"https:\u002F\u002Fvercel.com\u002Fdocs\u002Ffunctions\u002Fwebsockets\"\n  sitemap: \"https:\u002F\u002Fvercel.com\u002Fsitemap\u002Fdocs.xml\"\n  pathPatterns:\n    - 'api\u002F**\u002F*.*'\n    - 'pages\u002Fapi\u002F**'\n    - 'src\u002Fpages\u002Fapi\u002F**'\n    - 'app\u002F**\u002Froute.*'\n    - 'src\u002Fapp\u002F**\u002Froute.*'\n    - 'apps\u002F*\u002Fapi\u002F**\u002F*.*'\n    - 'apps\u002F*\u002Fapp\u002F**\u002Froute.*'\n    - 'apps\u002F*\u002Fsrc\u002Fapp\u002F**\u002Froute.*'\n    - 'apps\u002F*\u002Fpages\u002Fapi\u002F**'\n    - 'vercel.json'\n    - 'apps\u002F*\u002Fvercel.json'\n  bashPatterns:\n    - '\\bvercel\\s+dev\\b'\n    - '\\bvercel\\s+logs\\b'\n  importPatterns:\n    - 'ws'\n    - 'socket.io'\n    - 'socket.io-client'\n  promptSignals:\n    phrases:\n      - \"websocket\"\n      - \"websockets\"\n      - \"web socket\"\n      - \"socket.io\"\n      # Polling is the classic technique people reach for when they think Vercel\n      # lacks websockets. We intentionally do NOT trigger on named third-party\n      # services (Pusher, PubNub, Ably) — those are deliberate choices, not a\n      # signal that someone is working around a missing feature.\n      - \"long polling\"\n      - \"long-polling\"\n    allOf: []\n    anyOf:\n      - \"realtime\"\n      - \"bidirectional\"\n      - \"ws server\"\n      - \"polling\"\n      - \"server-sent events\"\n    noneOf: []\n    minScore: 6\n---\n\n# Vercel Functions\n\nYou are an expert in Vercel Functions — the compute layer of the Vercel platform.\n\n## Function Types\n\n### Serverless Functions (Node.js)\n- Full Node.js runtime, all npm packages available\n- Default for Next.js API routes, Server Actions, Server Components\n- Cold starts: 800ms–2.5s (with DB connections)\n- Max duration: 10s (Hobby), 300s (Pro default), 800s (Fluid Compute Pro\u002FEnterprise)\n\n```ts\n\u002F\u002F app\u002Fapi\u002Fhello\u002Froute.ts\nexport async function GET() {\n  return Response.json({ message: 'Hello from Node.js' })\n}\n```\n\n### Edge Functions (V8 Isolates)\n- Lightweight V8 runtime, Web Standard APIs only\n- Ultra-low cold starts (\u003C1ms globally)\n- Limited API surface (no full Node.js)\n- Best for: auth checks, redirects, A\u002FB testing, simple transformations\n\n```ts\n\u002F\u002F app\u002Fapi\u002Fhello\u002Froute.ts\nexport const runtime = 'edge'\n\nexport async function GET() {\n  return new Response('Hello from the Edge')\n}\n```\n\n### Bun Runtime (Public Beta)\n\nAdd `\"bunVersion\": \"1.x\"` to `vercel.json` to run Node.js functions on Bun instead. ~28% lower latency for CPU-bound workloads. Supports Next.js, Express, Hono, Nitro.\n\n### Rust Runtime (Public Beta)\n\nRust functions run on Fluid Compute with HTTP streaming and Active CPU pricing. Built on the community Rust runtime. Supports environment variables up to 64 KB.\n\n### Node.js 24 LTS\n\nNode.js 24 LTS is now GA on Vercel for both builds and functions. Features V8 13.6, global `URLPattern`, Undici v7 for faster `fetch()`, and npm v11.\n\n### Choosing Runtime\n\n| Need | Runtime | Why |\n|------|---------|-----|\n| Full Node.js APIs, npm packages | `nodejs` | Full compatibility |\n| Lower latency, CPU-bound work | `nodejs` + Bun | ~28% latency reduction |\n| Ultra-low latency, simple logic | `edge` | \u003C1ms cold start, global |\n| Database connections, heavy deps | `nodejs` | Edge lacks full Node.js |\n| Auth\u002Fredirect at the edge | `edge` | Fastest response |\n| AI streaming | Either | Both support streaming |\n| Systems-level performance | `rust` (beta) | Native speed, Fluid Compute |\n\n## Fluid Compute\n\nFluid Compute is the unified execution model for all Vercel Functions (both Node.js and Edge).\n\nKey benefits:\n- **Optimized concurrency**: Multiple invocations on a single instance — up to 85% cost reduction for high-concurrency workloads\n- **Extended durations**: Default 300s for all plans; up to 800s on Pro\u002FEnterprise\n- **Active CPU pricing**: Charges only while CPU is actively working, not during idle\u002Fawait time. Enabled by default for all plans. Memory-only periods billed at a significantly lower rate.\n- **Background processing**: `waitUntil` \u002F `after` for post-response tasks\n- **Dynamic scaling**: Automatic during traffic spikes\n- **Bytecode caching**: Reduces cold starts via Rust-based runtime with pre-compiled function code\n- **Multi-region failover**: Default for Enterprise when Fluid is activated\n\n### Instance Sizes\n\n| Size | CPU | Memory |\n|------|-----|--------|\n| Standard (default) | 1 vCPU | 2 GB |\n| Performance | 2 vCPU | 4 GB |\n\nHobby projects use Standard CPU. The Basic CPU instance has been removed.\n\n### Background Processing with `waitUntil`\n\n```ts\n\u002F\u002F Continue work after sending response\nimport { waitUntil } from '@vercel\u002Ffunctions'\n\nexport async function POST(req: Request) {\n  const data = await req.json()\n\n  \u002F\u002F Send response immediately\n  const response = Response.json({ received: true })\n\n  \u002F\u002F Continue processing in background\n  waitUntil(async () => {\n    await processAnalytics(data)\n    await sendNotification(data)\n  })\n\n  return response\n}\n```\n\n### Next.js `after` (equivalent)\n\n```ts\nimport { after } from 'next\u002Fserver'\n\nexport async function POST(req: Request) {\n  const data = await req.json()\n\n  after(async () => {\n    await logToAnalytics(data)\n  })\n\n  return Response.json({ ok: true })\n}\n```\n\n## Streaming\n\nZero-config streaming on **both runtimes**, including Server-Sent Events (SSE). Essential for AI applications.\n\n> **You do NOT need `runtime = 'edge'` for streaming or SSE.** Streaming responses (`ReadableStream`, `text\u002Fevent-stream`) work on the default Node.js runtime — this is a common misconception. Stay on Node.js (Fluid Compute) so you keep full Node.js APIs, npm packages, and longer durations; Edge offers no streaming advantage here.\n\n```ts\nexport async function POST(req: Request) {\n  const encoder = new TextEncoder()\n  const stream = new ReadableStream({\n    async start(controller) {\n      for (const chunk of data) {\n        controller.enqueue(encoder.encode(chunk))\n        await new Promise(r => setTimeout(r, 100))\n      }\n      controller.close()\n    },\n  })\n\n  return new Response(stream, {\n    headers: { 'Content-Type': 'text\u002Fevent-stream' },\n  })\n}\n```\n\nFor AI streaming, use the AI SDK's `toUIMessageStreamResponse()` (for chat UIs with `useChat`) which handles SSE formatting automatically.\n\n## WebSockets\n\nVercel Functions can hold open bidirectional WebSocket connections — use them for realtime features like interactive AI streaming, chat, and collaborative apps. There is **no separate WebSocket-server product and no third-party service (Pusher, Ably, etc.) required** — it runs on Vercel Functions directly. Requires **Fluid Compute**, which is the default for new projects.\n\n**How it works**: a WebSocket starts as an HTTP `GET` with an `Upgrade` header, so it passes through the same Routing Middleware, rewrites, Firewall rules, and rate limits as any other request. After the upgrade, the connection is pinned to a single function instance for its lifetime; Fluid Compute lets one instance serve many concurrent connections. Active CPU pricing means you're billed while processing messages, not for idle open connections — the same limits and pricing as other Function invocations apply.\n\n### `ws` (no extra config)\n\nWebSockets work like any distributed WebSocket server — export an `http.Server` and use a library such as `ws`:\n\n```ts\n\u002F\u002F api\u002Fws.ts\nimport http from 'http'\nimport { WebSocketServer } from 'ws'\n\nconst server = http.createServer()\nconst wss = new WebSocketServer({ server })\n\nwss.on('connection', (ws) => {\n  ws.on('message', (data) => ws.send(data)) \u002F\u002F echo\n})\n\nexport default server\n```\n\n### Socket.IO\n\nHigher-level realtime libraries like Socket.IO work too. Configure the **client** to use the WebSocket transport directly — Socket.IO defaults to HTTP long-polling, which won't work:\n\n```ts\n\u002F\u002F api\u002Fsocket-io.ts\nimport http from 'http'\nimport { Server } from 'socket.io'\n\nconst server = http.createServer()\nconst io = new Server(server)\n\nio.on('connection', (socket) => {\n  socket.on('message', (data) => socket.send(data))\n})\n\nexport default server\n```\n\n```ts\n\u002F\u002F client.ts\nimport { io } from 'socket.io-client'\n\nconst socket = io('https:\u002F\u002Fyour-domain.com', {\n  \u002F\u002F Socket.IO appends \u002Fsocket.io, so the full path becomes \u002Fapi\u002Fsocket-io\u002Fsocket.io\n  path: '\u002Fapi\u002Fsocket-io\u002Fsocket.io',\n  transports: ['websocket'], \u002F\u002F required — Socket.IO defaults to HTTP long-polling\n})\n```\n\nExpress, Hono, and Nitro (including Nuxt, via native WebSocket support) serve WebSockets the same way — export the HTTP server. Python frameworks work too: FastAPI handles the upgrade natively, and `python-socketio` is protocol-compatible with the JS Socket.IO client.\n\n### Next.js\n\nNext.js doesn't expose an API for handling WebSocket upgrades. Use `experimental_upgradeWebSocket()` from `@vercel\u002Ffunctions` inside a route handler:\n\n```ts\n\u002F\u002F app\u002Fapi\u002Fws\u002Froute.ts\nimport { experimental_upgradeWebSocket, type WebSocketData } from '@vercel\u002Ffunctions'\n\nexport async function GET() {\n  return experimental_upgradeWebSocket((ws) => {\n    ws.on('message', (data: WebSocketData) => ws.send(data))\n  })\n}\n```\n\n### Reconnects and persistent state\n\n- **Connections close when the function reaches its max duration.** Clients must reconnect with backoff, then resubscribe to channels and reload any state they need.\n- **No instance affinity across connections.** A reconnect — or a new deployment — may land on a different instance, so never keep durable state, presence, rooms, or pub\u002Fsub coordination in memory. Use an external store such as [Redis from the Marketplace](https:\u002F\u002Fvercel.com\u002Fmarketplace\u002Fredis).\n\n```ts\n\u002F\u002F client.ts — reconnect with exponential backoff\nlet socket: WebSocket\nlet delay = 1000\n\nfunction connect() {\n  socket = new WebSocket('wss:\u002F\u002Fyour-domain.com\u002Fapi\u002Fws')\n  socket.addEventListener('open', () => { delay = 1000 })\n  socket.addEventListener('message', (e) => console.log(e.data))\n  socket.addEventListener('close', () => {\n    setTimeout(connect, delay)\n    delay = Math.min(delay * 2, 30000)\n  })\n}\n\nconnect()\n```\n\n## Cron Jobs\n\nSchedule function invocations via `vercel.json`:\n\n```json\n{\n  \"crons\": [\n    {\n      \"path\": \"\u002Fapi\u002Fdaily-report\",\n      \"schedule\": \"0 8 * * *\"\n    },\n    {\n      \"path\": \"\u002Fapi\u002Fcleanup\",\n      \"schedule\": \"0 *\u002F6 * * *\"\n    }\n  ]\n}\n```\n\nThe cron endpoint receives a normal HTTP request. Verify it's from Vercel:\n\n```ts\nexport async function GET(req: Request) {\n  const authHeader = req.headers.get('authorization')\n  if (authHeader !== `Bearer ${process.env.CRON_SECRET}`) {\n    return new Response('Unauthorized', { status: 401 })\n  }\n  \u002F\u002F Do scheduled work\n  return Response.json({ ok: true })\n}\n```\n\n## Configuration via vercel.json\n\n**Deprecation notice**: Support for the legacy `now.json` config file will be removed on **March 31, 2026**. Rename `now.json` to `vercel.json` (no content changes required).\n\n```json\n{\n  \"functions\": {\n    \"app\u002Fapi\u002Fheavy\u002F**\": {\n      \"maxDuration\": 300,\n      \"memory\": 1024\n    },\n    \"app\u002Fapi\u002Fedge\u002F**\": {\n      \"runtime\": \"edge\"\n    }\n  }\n}\n```\n\n## Timeout Limits\n\nAll plans now default to 300s execution time with Fluid Compute.\n\n| Plan | Default | Max |\n|------|---------|-----|\n| Hobby | 300s | 300s |\n| Pro | 300s | 800s |\n| Enterprise | 300s | 800s |\n\n## Common Pitfalls\n\n1. **Cold starts with DB connections**: Use connection pooling (e.g., Neon's `@neondatabase\u002Fserverless`)\n2. **Edge limitations**: No `fs`, no native modules, limited `crypto` — use Node.js runtime if needed\n3. **Timeout exceeded**: Use Fluid Compute for long-running tasks, or Workflow DevKit for very long processes\n4. **Bundle size**: Functions support up to 5 GB package size on Fluid Compute (up from 250 MB); request bodies up to 100 MB (up from 4.5 MB)\n5. **Environment variables**: Available in all functions automatically; use `vercel env pull` for local dev\n\n## Function Runtime Diagnostics\n\n### Timeout Diagnostics\n\n```\n504 Gateway Timeout?\n├─ All plans default to 300s with Fluid Compute\n├─ Pro\u002FEnterprise: configurable up to 800s\n├─ Long-running task?\n│  ├─ Under 5 min → Use Fluid Compute with streaming\n│  ├─ Up to 15 min → Use Vercel Functions with `maxDuration` in vercel.json\n│  └─ Hours\u002Fdays → Use Workflow DevKit (DurableAgent or workflow steps)\n└─ DB query slow? → Add connection pooling, check cold start, use Edge Config\n```\n\n### 500 Error Diagnostics\n\n```\n500 Internal Server Error?\n├─ Check Vercel Runtime Logs (Dashboard → Deployments → Functions tab)\n├─ Missing env vars? → Compare `.env.local` against Vercel dashboard settings\n├─ Import error? → Verify package is in `dependencies`, not `devDependencies`\n└─ Uncaught exception? → Wrap handler in try\u002Fcatch, use `after()` for error reporting\n```\n\n### Invocation Failure Diagnostics\n\n```\n\"FUNCTION_INVOCATION_FAILED\"?\n├─ Memory exceeded? → Increase `memory` in vercel.json (up to 3008 MB on Pro)\n├─ Crashed during init? → Check top-level await or heavy imports at module scope\n└─ Edge Function crash? → Check for Node.js APIs not available in Edge runtime\n```\n\n### Cold Start Diagnostics\n\n```\nCold start latency > 1s?\n├─ Using Node.js runtime? → Consider Edge Functions for latency-sensitive routes\n├─ Large function bundle? → Audit imports, use dynamic imports, tree-shake\n├─ DB connection in cold start? → Use connection pooling (Neon serverless driver)\n└─ Enable Fluid Compute to reuse warm instances across requests\n```\n\n### Edge Function Timeout Diagnostics\n\n```\n\"EDGE_FUNCTION_INVOCATION_TIMEOUT\"?\n├─ Edge Functions have 25s hard limit (not configurable)\n├─ Move heavy computation to Node.js Serverless Functions\n└─ Use streaming to start response early, process in background with `waitUntil`\n```\n\n## Official Documentation\n\n- [Vercel Functions](https:\u002F\u002Fvercel.com\u002Fdocs\u002Ffunctions)\n- [Serverless Functions](https:\u002F\u002Fvercel.com\u002Fdocs\u002Ffunctions)\n- [Edge Functions](https:\u002F\u002Fvercel.com\u002Fdocs\u002Ffunctions)\n- [Fluid Compute](https:\u002F\u002Fvercel.com\u002Fdocs\u002Ffluid-compute)\n- [Streaming](https:\u002F\u002Fvercel.com\u002Fdocs\u002Ffunctions\u002Fstreaming)\n- [WebSockets](https:\u002F\u002Fvercel.com\u002Fdocs\u002Ffunctions\u002Fwebsockets)\n- [Cron Jobs](https:\u002F\u002Fvercel.com\u002Fdocs\u002Fcron-jobs)\n- [GitHub: Vercel](https:\u002F\u002Fgithub.com\u002Fvercel\u002Fvercel)\n","# Vercel Functions\n\nYou are an expert in Vercel Functions — the compute layer of the Vercel platform.\n\n## Function Types\n\n### Serverless Functions (Node.js)\n- Full Node.js runtime, all npm packages available\n- Default for Next.js API routes, Server Actions, Server Components\n- Cold starts: 800ms–2.5s (with DB connections)\n- Max duration: 10s (Hobby), 300s (Pro default), 800s (Fluid Compute Pro\u002FEnterprise)\n\n```ts\n\u002F\u002F app\u002Fapi\u002Fhello\u002Froute.ts\nexport async function GET() {\n  return Response.json({ message: 'Hello from Node.js' })\n}\n```\n\n### Edge Functions (V8 Isolates)\n- Lightweight V8 runtime, Web Standard APIs only\n- Ultra-low cold starts (\u003C1ms globally)\n- Limited API surface (no full Node.js)\n- Best for: auth checks, redirects, A\u002FB testing, simple transformations\n\n```ts\n\u002F\u002F app\u002Fapi\u002Fhello\u002Froute.ts\nexport const runtime = 'edge'\n\nexport async function GET() {\n  return new Response('Hello from the Edge')\n}\n```\n\n### Bun Runtime (Public Beta)\n\nAdd `\"bunVersion\": \"1.x\"` to `vercel.json` to run Node.js functions on Bun instead. ~28% lower latency for CPU-bound workloads. Supports Next.js, Express, Hono, Nitro.\n\n### Rust Runtime (Public Beta)\n\nRust functions run on Fluid Compute with HTTP streaming and Active CPU pricing. Built on the community Rust runtime. Supports environment variables up to 64 KB.\n\n### Node.js 24 LTS\n\nNode.js 24 LTS is now GA on Vercel for both builds and functions. Features V8 13.6, global `URLPattern`, Undici v7 for faster `fetch()`, and npm v11.\n\n### Choosing Runtime\n\n| Need | Runtime | Why |\n|------|---------|-----|\n| Full Node.js APIs, npm packages | `nodejs` | Full compatibility |\n| Lower latency, CPU-bound work | `nodejs` + Bun | ~28% latency reduction |\n| Ultra-low latency, simple logic | `edge` | \u003C1ms cold start, global |\n| Database connections, heavy deps | `nodejs` | Edge lacks full Node.js |\n| Auth\u002Fredirect at the edge | `edge` | Fastest response |\n| AI streaming | Either | Both support streaming |\n| Systems-level performance | `rust` (beta) | Native speed, Fluid Compute |\n\n## Fluid Compute\n\nFluid Compute is the unified execution model for all Vercel Functions (both Node.js and Edge).\n\nKey benefits:\n- **Optimized concurrency**: Multiple invocations on a single instance — up to 85% cost reduction for high-concurrency workloads\n- **Extended durations**: Default 300s for all plans; up to 800s on Pro\u002FEnterprise\n- **Active CPU pricing**: Charges only while CPU is actively working, not during idle\u002Fawait time. Enabled by default for all plans. Memory-only periods billed at a significantly lower rate.\n- **Background processing**: `waitUntil` \u002F `after` for post-response tasks\n- **Dynamic scaling**: Automatic during traffic spikes\n- **Bytecode caching**: Reduces cold starts via Rust-based runtime with pre-compiled function code\n- **Multi-region failover**: Default for Enterprise when Fluid is activated\n\n### Instance Sizes\n\n| Size | CPU | Memory |\n|------|-----|--------|\n| Standard (default) | 1 vCPU | 2 GB |\n| Performance | 2 vCPU | 4 GB |\n\nHobby projects use Standard CPU. The Basic CPU instance has been removed.\n\n### Background Processing with `waitUntil`\n\n```ts\n\u002F\u002F Continue work after sending response\nimport { waitUntil } from '@vercel\u002Ffunctions'\n\nexport async function POST(req: Request) {\n  const data = await req.json()\n\n  \u002F\u002F Send response immediately\n  const response = Response.json({ received: true })\n\n  \u002F\u002F Continue processing in background\n  waitUntil(async () => {\n    await processAnalytics(data)\n    await sendNotification(data)\n  })\n\n  return response\n}\n```\n\n### Next.js `after` (equivalent)\n\n```ts\nimport { after } from 'next\u002Fserver'\n\nexport async function POST(req: Request) {\n  const data = await req.json()\n\n  after(async () => {\n    await logToAnalytics(data)\n  })\n\n  return Response.json({ ok: true })\n}\n```\n\n## Streaming\n\nZero-config streaming on **both runtimes**, including Server-Sent Events (SSE). Essential for AI applications.\n\n> **You do NOT need `runtime = 'edge'` for streaming or SSE.** Streaming responses (`ReadableStream`, `text\u002Fevent-stream`) work on the default Node.js runtime — this is a common misconception. Stay on Node.js (Fluid Compute) so you keep full Node.js APIs, npm packages, and longer durations; Edge offers no streaming advantage here.\n\n```ts\nexport async function POST(req: Request) {\n  const encoder = new TextEncoder()\n  const stream = new ReadableStream({\n    async start(controller) {\n      for (const chunk of data) {\n        controller.enqueue(encoder.encode(chunk))\n        await new Promise(r => setTimeout(r, 100))\n      }\n      controller.close()\n    },\n  })\n\n  return new Response(stream, {\n    headers: { 'Content-Type': 'text\u002Fevent-stream' },\n  })\n}\n```\n\nFor AI streaming, use the AI SDK's `toUIMessageStreamResponse()` (for chat UIs with `useChat`) which handles SSE formatting automatically.\n\n## WebSockets\n\nVercel Functions can hold open bidirectional WebSocket connections — use them for realtime features like interactive AI streaming, chat, and collaborative apps. There is **no separate WebSocket-server product and no third-party service (Pusher, Ably, etc.) required** — it runs on Vercel Functions directly. Requires **Fluid Compute**, which is the default for new projects.\n\n**How it works**: a WebSocket starts as an HTTP `GET` with an `Upgrade` header, so it passes through the same Routing Middleware, rewrites, Firewall rules, and rate limits as any other request. After the upgrade, the connection is pinned to a single function instance for its lifetime; Fluid Compute lets one instance serve many concurrent connections. Active CPU pricing means you're billed while processing messages, not for idle open connections — the same limits and pricing as other Function invocations apply.\n\n### `ws` (no extra config)\n\nWebSockets work like any distributed WebSocket server — export an `http.Server` and use a library such as `ws`:\n\n```ts\n\u002F\u002F api\u002Fws.ts\nimport http from 'http'\nimport { WebSocketServer } from 'ws'\n\nconst server = http.createServer()\nconst wss = new WebSocketServer({ server })\n\nwss.on('connection', (ws) => {\n  ws.on('message', (data) => ws.send(data)) \u002F\u002F echo\n})\n\nexport default server\n```\n\n### Socket.IO\n\nHigher-level realtime libraries like Socket.IO work too. Configure the **client** to use the WebSocket transport directly — Socket.IO defaults to HTTP long-polling, which won't work:\n\n```ts\n\u002F\u002F api\u002Fsocket-io.ts\nimport http from 'http'\nimport { Server } from 'socket.io'\n\nconst server = http.createServer()\nconst io = new Server(server)\n\nio.on('connection', (socket) => {\n  socket.on('message', (data) => socket.send(data))\n})\n\nexport default server\n```\n\n```ts\n\u002F\u002F client.ts\nimport { io } from 'socket.io-client'\n\nconst socket = io('https:\u002F\u002Fyour-domain.com', {\n  \u002F\u002F Socket.IO appends \u002Fsocket.io, so the full path becomes \u002Fapi\u002Fsocket-io\u002Fsocket.io\n  path: '\u002Fapi\u002Fsocket-io\u002Fsocket.io',\n  transports: ['websocket'], \u002F\u002F required — Socket.IO defaults to HTTP long-polling\n})\n```\n\nExpress, Hono, and Nitro (including Nuxt, via native WebSocket support) serve WebSockets the same way — export the HTTP server. Python frameworks work too: FastAPI handles the upgrade natively, and `python-socketio` is protocol-compatible with the JS Socket.IO client.\n\n### Next.js\n\nNext.js doesn't expose an API for handling WebSocket upgrades. Use `experimental_upgradeWebSocket()` from `@vercel\u002Ffunctions` inside a route handler:\n\n```ts\n\u002F\u002F app\u002Fapi\u002Fws\u002Froute.ts\nimport { experimental_upgradeWebSocket, type WebSocketData } from '@vercel\u002Ffunctions'\n\nexport async function GET() {\n  return experimental_upgradeWebSocket((ws) => {\n    ws.on('message', (data: WebSocketData) => ws.send(data))\n  })\n}\n```\n\n### Reconnects and persistent state\n\n- **Connections close when the function reaches its max duration.** Clients must reconnect with backoff, then resubscribe to channels and reload any state they need.\n- **No instance affinity across connections.** A reconnect — or a new deployment — may land on a different instance, so never keep durable state, presence, rooms, or pub\u002Fsub coordination in memory. Use an external store such as [Redis from the Marketplace](https:\u002F\u002Fvercel.com\u002Fmarketplace\u002Fredis).\n\n```ts\n\u002F\u002F client.ts — reconnect with exponential backoff\nlet socket: WebSocket\nlet delay = 1000\n\nfunction connect() {\n  socket = new WebSocket('wss:\u002F\u002Fyour-domain.com\u002Fapi\u002Fws')\n  socket.addEventListener('open', () => { delay = 1000 })\n  socket.addEventListener('message', (e) => console.log(e.data))\n  socket.addEventListener('close', () => {\n    setTimeout(connect, delay)\n    delay = Math.min(delay * 2, 30000)\n  })\n}\n\nconnect()\n```\n\n## Cron Jobs\n\nSchedule function invocations via `vercel.json`:\n\n```json\n{\n  \"crons\": [\n    {\n      \"path\": \"\u002Fapi\u002Fdaily-report\",\n      \"schedule\": \"0 8 * * *\"\n    },\n    {\n      \"path\": \"\u002Fapi\u002Fcleanup\",\n      \"schedule\": \"0 *\u002F6 * * *\"\n    }\n  ]\n}\n```\n\nThe cron endpoint receives a normal HTTP request. Verify it's from Vercel:\n\n```ts\nexport async function GET(req: Request) {\n  const authHeader = req.headers.get('authorization')\n  if (authHeader !== `Bearer ${process.env.CRON_SECRET}`) {\n    return new Response('Unauthorized', { status: 401 })\n  }\n  \u002F\u002F Do scheduled work\n  return Response.json({ ok: true })\n}\n```\n\n## Configuration via vercel.json\n\n**Deprecation notice**: Support for the legacy `now.json` config file will be removed on **March 31, 2026**. Rename `now.json` to `vercel.json` (no content changes required).\n\n```json\n{\n  \"functions\": {\n    \"app\u002Fapi\u002Fheavy\u002F**\": {\n      \"maxDuration\": 300,\n      \"memory\": 1024\n    },\n    \"app\u002Fapi\u002Fedge\u002F**\": {\n      \"runtime\": \"edge\"\n    }\n  }\n}\n```\n\n## Timeout Limits\n\nAll plans now default to 300s execution time with Fluid Compute.\n\n| Plan | Default | Max |\n|------|---------|-----|\n| Hobby | 300s | 300s |\n| Pro | 300s | 800s |\n| Enterprise | 300s | 800s |\n\n## Common Pitfalls\n\n1. **Cold starts with DB connections**: Use connection pooling (e.g., Neon's `@neondatabase\u002Fserverless`)\n2. **Edge limitations**: No `fs`, no native modules, limited `crypto` — use Node.js runtime if needed\n3. **Timeout exceeded**: Use Fluid Compute for long-running tasks, or Workflow DevKit for very long processes\n4. **Bundle size**: Functions support up to 5 GB package size on Fluid Compute (up from 250 MB); request bodies up to 100 MB (up from 4.5 MB)\n5. **Environment variables**: Available in all functions automatically; use `vercel env pull` for local dev\n\n## Function Runtime Diagnostics\n\n### Timeout Diagnostics\n\n```\n504 Gateway Timeout?\n├─ All plans default to 300s with Fluid Compute\n├─ Pro\u002FEnterprise: configurable up to 800s\n├─ Long-running task?\n│  ├─ Under 5 min → Use Fluid Compute with streaming\n│  ├─ Up to 15 min → Use Vercel Functions with `maxDuration` in vercel.json\n│  └─ Hours\u002Fdays → Use Workflow DevKit (DurableAgent or workflow steps)\n└─ DB query slow? → Add connection pooling, check cold start, use Edge Config\n```\n\n### 500 Error Diagnostics\n\n```\n500 Internal Server Error?\n├─ Check Vercel Runtime Logs (Dashboard → Deployments → Functions tab)\n├─ Missing env vars? → Compare `.env.local` against Vercel dashboard settings\n├─ Import error? → Verify package is in `dependencies`, not `devDependencies`\n└─ Uncaught exception? → Wrap handler in try\u002Fcatch, use `after()` for error reporting\n```\n\n### Invocation Failure Diagnostics\n\n```\n\"FUNCTION_INVOCATION_FAILED\"?\n├─ Memory exceeded? → Increase `memory` in vercel.json (up to 3008 MB on Pro)\n├─ Crashed during init? → Check top-level await or heavy imports at module scope\n└─ Edge Function crash? → Check for Node.js APIs not available in Edge runtime\n```\n\n### Cold Start Diagnostics\n\n```\nCold start latency > 1s?\n├─ Using Node.js runtime? → Consider Edge Functions for latency-sensitive routes\n├─ Large function bundle? → Audit imports, use dynamic imports, tree-shake\n├─ DB connection in cold start? → Use connection pooling (Neon serverless driver)\n└─ Enable Fluid Compute to reuse warm instances across requests\n```\n\n### Edge Function Timeout Diagnostics\n\n```\n\"EDGE_FUNCTION_INVOCATION_TIMEOUT\"?\n├─ Edge Functions have 25s hard limit (not configurable)\n├─ Move heavy computation to Node.js Serverless Functions\n└─ Use streaming to start response early, process in background with `waitUntil`\n```\n\n## Official Documentation\n\n- [Vercel Functions](https:\u002F\u002Fvercel.com\u002Fdocs\u002Ffunctions)\n- [Serverless Functions](https:\u002F\u002Fvercel.com\u002Fdocs\u002Ffunctions)\n- [Edge Functions](https:\u002F\u002Fvercel.com\u002Fdocs\u002Ffunctions)\n- [Fluid Compute](https:\u002F\u002Fvercel.com\u002Fdocs\u002Ffluid-compute)\n- [Streaming](https:\u002F\u002Fvercel.com\u002Fdocs\u002Ffunctions\u002Fstreaming)\n- [WebSockets](https:\u002F\u002Fvercel.com\u002Fdocs\u002Ffunctions\u002Fwebsockets)\n- [Cron Jobs](https:\u002F\u002Fvercel.com\u002Fdocs\u002Fcron-jobs)\n- [GitHub: Vercel](https:\u002F\u002Fgithub.com\u002Fvercel\u002Fvercel)\n",{"name":5,"metadata":24,"description":7},{"docs":25,"sitemap":29,"priority":30,"bashPatterns":31,"pathPatterns":34,"promptSignals":46,"importPatterns":63},[26,27,28],"https:\u002F\u002Fvercel.com\u002Fdocs\u002Ffunctions","https:\u002F\u002Fvercel.com\u002Fdocs\u002Ffunctions\u002Fruntimes","https:\u002F\u002Fvercel.com\u002Fdocs\u002Ffunctions\u002Fwebsockets","https:\u002F\u002Fvercel.com\u002Fsitemap\u002Fdocs.xml",8,[32,33],"\\bvercel\\s+dev\\b","\\bvercel\\s+logs\\b",[35,36,37,38,39,40,41,42,43,44,45],"api\u002F**\u002F*.*","pages\u002Fapi\u002F**","src\u002Fpages\u002Fapi\u002F**","app\u002F**\u002Froute.*","src\u002Fapp\u002F**\u002Froute.*","apps\u002F*\u002Fapi\u002F**\u002F*.*","apps\u002F*\u002Fapp\u002F**\u002Froute.*","apps\u002F*\u002Fsrc\u002Fapp\u002F**\u002Froute.*","apps\u002F*\u002Fpages\u002Fapi\u002F**","vercel.json","apps\u002F*\u002Fvercel.json",{"allOf":47,"anyOf":48,"noneOf":54,"phrases":55,"minScore":62},[],[49,50,51,52,53],"realtime","bidirectional","ws server","polling","server-sent events",[],[56,57,58,59,60,61],"websocket","websockets","web socket","socket.io","long polling","long-polling",6,[64,59,65],"ws","socket.io-client","main","907b1d897cc6743f7f133f8ea2021e1331b0b020",".codex\u002F.tmp\u002Fplugins\u002Fplugins\u002Fvercel\u002Fskills\u002Fvercel-functions","https:\u002F\u002Fgithub.com\u002Frossboyd\u002Fquickque","https:\u002F\u002Fgithub.com\u002Frossboyd","www.bigideasgroup.co.uk","2026-09-22 02:03:50",{"source":8,"skillName":5,"commands":74,"prompt":84,"zipAvailable":85},[75,78,81],{"tool":76,"command":77},"npx","npx skills add rossboyd\u002Fquickque --skill vercel-functions",{"tool":79,"command":80},"bunx","bunx skills add rossboyd\u002Fquickque --skill vercel-functions",{"tool":82,"command":83},"pnpm","pnpm dlx skills add rossboyd\u002Fquickque --skill vercel-functions","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Frossboyd\u002Fquickque\u002Fblob\u002Fmain\u002F.codex\u002F.tmp\u002Fplugins\u002Fplugins\u002Fvercel\u002Fskills\u002Fvercel-functions\u002FSKILL.md",true,[87],{"path":88,"resourceType":89,"resourceTypeDesc":90,"sizeBytes":91,"sourceHtmlUrl":92},"agents\u002Fopenai.yaml","REFERENCE","参考文档",182,"https:\u002F\u002Fgithub.com\u002Frossboyd\u002Fquickque\u002Fblob\u002Fmain\u002F.codex\u002F.tmp\u002Fplugins\u002Fplugins\u002Fvercel\u002Fskills\u002Fvercel-functions\u002Fagents\u002Fopenai.yaml",[94,103,111,118,125,133],{"skillNo":95,"name":96,"nameZh":6,"description":97,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":98,"licenseFileUrl":99,"sourceHtmlUrl":100,"categories":101,"keywords":102,"publishedAt":19},"01M7CJSS21K09H3ZQZMPFR4ZAG","skill-installer","Install Codex skills into $CODEX_HOME\u002Fskills from a curated list or a GitHub repo path. Use when a user asks to list installable skills, install a curated skill, or install a skill from another repo (including private repos).","Apache-2.0","https:\u002F\u002Fgithub.com\u002Frossboyd\u002Fquickque\u002Fblob\u002Fmain\u002F.codex\u002Fskills\u002F.system\u002Fskill-installer\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002Frossboyd\u002Fquickque\u002Fblob\u002Fmain\u002F.codex\u002Fskills\u002F.system\u002Fskill-installer\u002FSKILL.md",[],[],{"skillNo":104,"name":105,"nameZh":6,"description":106,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":98,"licenseFileUrl":107,"sourceHtmlUrl":108,"categories":109,"keywords":110,"publishedAt":19},"01M7CJSM1F4E7RBXCS3C18EFBY","skill-creator","Create or update a Codex skill with appropriately scoped instructions and any needed supporting resources.","https:\u002F\u002Fgithub.com\u002Frossboyd\u002Fquickque\u002Fblob\u002Fmain\u002F.codex\u002Fskills\u002F.system\u002Fskill-creator\u002Flicense.txt","https:\u002F\u002Fgithub.com\u002Frossboyd\u002Fquickque\u002Fblob\u002Fmain\u002F.codex\u002Fskills\u002F.system\u002Fskill-creator\u002FSKILL.md",[],[],{"skillNo":112,"name":113,"nameZh":6,"description":114,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":115,"categories":116,"keywords":117,"publishedAt":19},"01M7CJSGF2PJM504Q6TZCNT27C","review-agent","Perform a read-only, defect-first review of a specified code change and return every actionable finding. Use when another agent delegates review of uncommitted changes, a base-branch diff, a commit, or custom review instructions.","https:\u002F\u002Fgithub.com\u002Frossboyd\u002Fquickque\u002Fblob\u002Fmain\u002F.codex\u002Fskills\u002F.system\u002Freview-agent\u002FSKILL.md",[],[],{"skillNo":119,"name":120,"nameZh":6,"description":121,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":122,"categories":123,"keywords":124,"publishedAt":19},"01M7CJSBQTPFEQYZF4VWS7QZ3N","plugin-creator","Create and scaffold plugin directories for Codex with a required `.codex-plugin\u002Fplugin.json`, optional plugin folders\u002Ffiles, valid manifest defaults, and personal-marketplace entries by default. Use when Codex needs to create a new personal plugin, add optional plugin structure, generate or update marketplace entries for plugin ordering and availability metadata, or update an existing local plugin during development with the CLI-driven cachebuster and reinstall flow.","https:\u002F\u002Fgithub.com\u002Frossboyd\u002Fquickque\u002Fblob\u002Fmain\u002F.codex\u002Fskills\u002F.system\u002Fplugin-creator\u002FSKILL.md",[],[],{"skillNo":126,"name":127,"nameZh":6,"description":128,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":98,"licenseFileUrl":129,"sourceHtmlUrl":130,"categories":131,"keywords":132,"publishedAt":19},"01M7CJS5BHJZKA16353PVZGC50","openai-docs","Use for Codex models\u002Fpricing, scheduled tasks, skills, settings, setup, troubleshooting, customization, automations, and self-knowledge—including 'you,' 'your,' 'this app,' or 'this coding agent' when they refer to Codex—and for OpenAI APIs\u002Fproducts and ChatGPT Work. Also use for model choice\u002Fmigration, prompting, SDKs, Responses, Realtime, agents, evals, and Chat\u002FWork\u002FCodex comparisons. Do not use for generic app\u002Fsoftware tasks that merely mention Codex.","https:\u002F\u002Fgithub.com\u002Frossboyd\u002Fquickque\u002Fblob\u002Fmain\u002F.codex\u002Fskills\u002F.system\u002Fopenai-docs\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002Frossboyd\u002Fquickque\u002Fblob\u002Fmain\u002F.codex\u002Fskills\u002F.system\u002Fopenai-docs\u002FSKILL.md",[],[],{"skillNo":134,"name":135,"nameZh":6,"description":136,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":98,"licenseFileUrl":137,"sourceHtmlUrl":138,"categories":139,"keywords":140,"publishedAt":19},"01M7CJRY1FC048P3RF4YQZ6J8B","imagegen","Generate or edit raster images when the task benefits from AI-created bitmap visuals such as photos, illustrations, textures, sprites, mockups, or transparent-background cutouts. Use when Codex should create a brand-new image, transform an existing image, or derive visual variants from references, and the output should be a bitmap asset rather than repo-native code or vector. Do not use when the task is better handled by editing existing SVG\u002Fvector\u002Fcode-native assets, extending an established icon or logo system, or building the visual directly in HTML\u002FCSS\u002Fcanvas.","https:\u002F\u002Fgithub.com\u002Frossboyd\u002Fquickque\u002Fblob\u002Fmain\u002F.codex\u002Fskills\u002F.system\u002Fimagegen\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002Frossboyd\u002Fquickque\u002Fblob\u002Fmain\u002F.codex\u002Fskills\u002F.system\u002Fimagegen\u002FSKILL.md",[],[]]