Cloud & deploymentServerless & edge

Serverless & edge

Understand Bun's runtime boundaries on Lambda, Vercel, Cloud Run, and Workers

Last updated on

Platform matrix

ScenarioSupported routeDo not assume
AWS LambdaBun's guide uses a container plus Lambda Web AdapterA plain Bun.serve image consumes Lambda events without adaptation
Google Cloud RunDeploy a normal Bun container and read PORTLocal disk, one replica, or an always-warm instance persists
Vercel FunctionsSelect the Bun runtime via bunVersion and use a supported frameworkBun.serve, every Bun API, and all native Node packages are compatible
Cloudflare WorkersUse Bun for dependencies and WranglerBun executes the deployed Worker; the runtime is workerd

Vercel

vercel.json
{
  "$schema": "https://openapi.vercel.sh/vercel.json",
  "bunVersion": "1.x"
}

Vercel's Bun runtime left beta in mid-2026 (see the Vercel docs). A Next.js project using ISR must change its dev/build scripts to bun run --bun next ..., but the app still uses the Next.js bundling pipeline. Do not start Bun.serve inside a Vercel Function. Full steps: Deploy to Vercel.

Cloudflare Workers

bun add -d wrangler
bunx wrangler dev
bunx wrangler deploy

These commands use Bun to manage and launch tooling; the deployed Worker runs on workerd. Prefer standard Web APIs in shared code and test the Workers target independently.

AI streaming requests

A serverless AI endpoint is constrained by four timeout layers: model, SDK, Bun HTTP server, and platform.

  1. Propagate an AbortSignal from the client into the model SDK so disconnects stop upstream generation.
  2. Budget the total request, each tool step, and external retrieval separately.
  3. With direct Bun.serve, the 10-second default idle timeout can interrupt slow streams. Adjust only the requests that require it, while keeping a total timeout.
  4. Test time-to-first-byte, maximum execution, streaming, proxy buffering, and client reconnection on the target platform.
  5. Use idempotency keys for retried POSTs; deduplicate tool side effects and billing writes.

Cold start is not the only metric

Measure cold and warm requests, time to first token, total response, peak memory, and error rate. A hello-world startup time does not represent AI workload cost or throughput.

Official references: Bun on Lambda, Bun on Cloud Run, Bun on Vercel, Vercel Bun runtime, and Cloudflare Wrangler.