> ## Documentation Index
> Fetch the complete documentation index at: https://docs.hipocap.com/llms.txt
> Use this file to discover all available pages before exploring further.

# LLM Observability for AI SDK by Vercel

[AI SDK](https://sdk.vercel.ai/docs/introduction) is a library that allows you to add LLM features to your JS/TS applications. It supports tracing using [OpenTelemetry](https://opentelemetry.io/).

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.

<Steps>
  <Step title="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.
  </Step>

  <Step title="Initialize Laminar">
    <Tabs>
      <Tab title="Next.js">
        In Next.js, place `Laminar.initialize` in the `instrumentation.ts` file.

        ```typescript {3-4, 6-8} instrumentation.ts theme={null}
        export async function register() {
          // prevent this from running in the edge runtime
          if (process.env.NEXT_RUNTIME === 'nodejs') {
            const { Laminar } = await import('@lmnr-ai/lmnr');

            Laminar.initialize({
              projectApiKey: process.env.LMNR_PROJECT_API_KEY,
            });
          }
        }
        ```

        You will also need to update your `next.config.ts` file to include the `serverExternalPackages` option.

        ```typescript next.config.ts theme={null}
        const nextConfig = {
          serverExternalPackages: ['@lmnr-ai/lmnr'],
        };
        ```

        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](https://nextjs.org/docs/app/api-reference/config/next-config-js/serverExternalPackages).
      </Tab>

      <Tab title="Node.js">
        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.

        ```javascript theme={null}
        import { Laminar } from '@lmnr-ai/lmnr';

        Laminar.initialize({
          projectApiKey: process.env.LMNR_PROJECT_API_KEY,
        });
        ```
      </Tab>
    </Tabs>
  </Step>

  <Step title="Update your AI SDK calls">
    We need to pass the Laminar tracer to the `generateText`, or `streamText`, or any other `generate*` calls.

    ```javascript {3,8-11} theme={null}
    import { openai } from '@ai-sdk/openai';
    import { generateText } from 'ai';
    import { getTracer } from '@lmnr-ai/lmnr';

    const { text } = await generateText({
      model: openai('gpt-4.1-nano'),
      prompt: 'What is Laminar flow?',
      experimental_telemetry: {
        isEnabled: true,
        tracer: getTracer(),
      },
    });
    ```
  </Step>
</Steps>
