AI SDK (Vercel)
AI SDK is a library that allows you to add LLM features to your JS/TS applications. It supports tracing using OpenTelemetry.
Laminar tracing is based on OpenTelemetry, so it is fully compatible with Vercel AI SDK tracing and you can start sending Vercel AI SDK traces to Laminar right away.
Get your project API key
To get the project API key, go to the Laminar dashboard, click the project settings, and generate a project API key. This is available both in the cloud and in the self-hosted version of Laminar.
Specify the key at Laminar
initialization. If not specified,
Laminar will look for the key in the LMNR_PROJECT_API_KEY
environment variable.
Initialize Laminar
In Next.js, place Laminar.initialize
in the instrumentation.ts
file.
You will also need to update your next.config.ts
file to include the serverExternalPackages
option.
This is because Laminar depends on OpenTelemetry, which uses some Node.js-specific functionality, and we need to inform Next.js about it. Learn more in the Next.js docs.
In Next.js, place Laminar.initialize
in the instrumentation.ts
file.
You will also need to update your next.config.ts
file to include the serverExternalPackages
option.
This is because Laminar depends on OpenTelemetry, which uses some Node.js-specific functionality, and we need to inform Next.js about it. Learn more in the Next.js docs.
In Node.js, place Laminar.initialize
in the entry point to your application.
This must be done once, in an entry point of your application after any other tracing SDK initialization.
Update your AI SDK calls
We need to pass the Laminar tracer to the generateText
, or streamText
, or any other generate*
calls.