Anything you don’t flush before the runtime suspends is lost. The buffer is
volatile by design — it never blocks your model calls.
fog.flush() or by passing a waitUntil hook.
Flushing is identical on both entry points. The examples below use the v7
foglamp() collector, but a wrap() handle exposes the same flush() /
shutdown() methods, the same waitUntil config, and the same serverless
auto-detection — they apply verbatim on AI SDK v4–v6.Long-running (Node, Bun)
Nothing to do. The collector flushes everyflushIntervalMs (default 5s) and on
early batch limits. For clean shutdown, drain the buffer on exit:
Vercel functions
Nothing to do. The collector auto-detects Vercel and readswaitUntil from
the runtime’s request context — the same source @vercel/functions wraps — to
keep the function alive until the flush completes. No extra dependency is
needed. If detection ever doesn’t fire, pass it explicitly:
Cloudflare Workers
Workers don’t expose a globalwaitUntil; it lives on the request ctx. Thread
it through so the flush survives the response:
AWS Lambda
Lambda freezes the execution environment the moment your handler returns, so a background flush may never run. Await the flush before returning — do not rely onprocess.on("beforeExit"), which won’t fire.
Manual flush anywhere
fog.flush() works in every runtime and resolves when the request completes.
It’s safe to call when the collector is disabled (it resolves immediately), so
you can leave it in unconditionally.

