Serverless & edge
Understand Bun's runtime boundaries on Lambda, Vercel, Cloud Run, and Workers
Last updated on
Platform matrix
| Scenario | Supported route | Do not assume |
|---|---|---|
| AWS Lambda | Bun's guide uses a container plus Lambda Web Adapter | A plain Bun.serve image consumes Lambda events without adaptation |
| Google Cloud Run | Deploy a normal Bun container and read PORT | Local disk, one replica, or an always-warm instance persists |
| Vercel Functions | Select the Bun runtime via bunVersion and use a supported framework | Bun.serve, every Bun API, and all native Node packages are compatible |
| Cloudflare Workers | Use Bun for dependencies and Wrangler | Bun executes the deployed Worker; the runtime is workerd |
Vercel
{
"$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 deployThese 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.
- Propagate an
AbortSignalfrom the client into the model SDK so disconnects stop upstream generation. - Budget the total request, each tool step, and external retrieval separately.
- 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. - Test time-to-first-byte, maximum execution, streaming, proxy buffering, and client reconnection on the target platform.
- 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.