Serverless & edge

In AWS Lambda, Google Cloud Functions, Vercel Functions, and similar platforms, each invocation may freeze or terminate shortly after your handler returns. The SDK queues events and sends them asynchronously—always await noryen.flush() at the end of the handler when you need traces for that invocation to reach Noryen reliably.

Recommended pattern

  1. Call noryen.init() at the start of the handler (or rely on a module-level init if your runtime reuses the same module instance and that matches your security model).
  2. Perform LLM work via wrap() or track().
  3. await noryen.flush() before returning success to the caller.

Cold starts and reuse

Some platforms reuse containers: a single init() per cold start can be enough. If you are unsure, initializing per invocation is simpler and still cheap compared to model latency; the SDK warns if init() runs multiple times on the same client instance.

Edge runtimes

Confirm your edge runtime supports the SDK's networking (fetch) and that your Noryen API URL is reachable from that environment. Treat edge like serverless regarding flush().

See Next.js for concrete Route Handler examples with flush().