Skip to main content
This page explains how to set up instrumentation in your TypeScript generative AI app using Axiom AI SDK.
Axiom AI SDK is an open-source project and welcomes your contributions. For more information, see the GitHub repository.
Alternatively, instrument your app manually. For more information on instrumentation approaches, see LLM observability.

Prerequisite

Install the Axiom AI SDK by running the following:
Set the AXIOM_TOKEN and AXIOM_DATASET environment variables using an API token and the name of a dataset you want to send telemetry to.

Instrument AI SDK calls

Axiom AI SDK provides helper functions for Vercel AI SDK to wrap your existing AI model client. The wrapAISDKModel function takes an existing AI model object and returns an instrumented version that automatically generates trace data for every call. Choose one of the following common Vercel AI SDK providers. For the full list of providers, see the Vercel documentation.
  1. Run the following in your terminal to install the Vercel AI SDK and the OpenAI provider.
  2. Create the file src/shared/openai.ts with the following content:
    /src/shared/openai.ts
To instrument calls without a Vercel AI SDK provider, use the generic Vercel AI Gateway provider.
To instrument calls without a Vercel AI SDK provider, use the generic Vercel AI Gateway provider. For more information, see the Vercel documentation.
  1. Run the following in your terminal to install the Vercel AI SDK:
  2. Create the file src/shared/openai.ts with the following content:
    /src/shared/openai.ts
The rest of the page explains how to work with OpenAI. The process is similar for other LLMs.

Add context

The withSpan function allows you to add crucial business context to your traces. It creates a parent span around your LLM call and attaches metadata about the capability and step that you execute.
/src/app/page.tsx

Instrument tool calls

For many AI capabilities, the LLM call is only part of the story. If your capability uses tools to interact with external data or services, observing the performance and outcome of those tools is critical. Axiom AI SDK provides the wrapTool and wrapTools functions to automatically instrument your Vercel AI SDK tool definitions. The wrapTool helper takes your tool’s name and its definition and returns an instrumented version. This wrapper creates a dedicated child span for every tool execution, capturing its arguments, output, and any errors.
/src/app/generate-text/page.tsx

Complete example

Example of how all three instrumentation functions work together in a single, real-world example:
/src/app/page.tsx
This demonstrates the three key steps to rich observability:
  1. wrapAISDKModel: Automatically captures telemetry for the LLM provider call
  2. wrapTool: Instruments the tool execution with detailed spans
  3. withSpan: Creates a parent span that ties everything together under a business capability

What’s next?

After sending traces to Axiom: