Monitor LLM applications
Production AI applications need visibility into model executions and outcomes.
AI Tools · Const
LangSmith adds monitoring and evaluation to AI SDK applications. Initialize tracing with wrapAISDK, and use traceable for custom spans around model or tool work.
LangSmith integrates with the AI SDK by wrapping AI SDK methods before they are called. The wrapped functions send tracing data to LangSmith, while traceable can add spans around broader application logic or tool calls; serverless applications must wait for pending runs to flush before shutting down.
wrapAISDK({ generateText })import { wrapAISDK } from 'langsmith/wrappers/vercel-ai-sdk';
import { generateText } from 'ai';
import { openai } from '@ai-sdk/openai';
const { generateText: tracedGenerateText } = wrapAISDK({ generateText });
const result = await tracedGenerateText({
model: openai('gpt-4o-mini'),
prompt: 'Explain observability in one sentence.',
});
console.log(result.text);Wrap the AI SDK function before calling it so LangSmith can trace the generation.
Production AI applications need visibility into model executions and outcomes.
Teams want to evaluate application behavior while using the AI SDK directly.
Custom application logic or tool execution needs separate trace spans.
Serverless handlers must preserve telemetry during shutdown.
Install a supported LangSmith client SDK and an AI SDK model provider. Then call wrapAISDK at the start of the code and use the wrapped AI SDK methods for traced operations.
Follow-up: How can application-specific work be traced? Use traceable around AI SDK calls or inside AI SDK tool calls to create additional trace spans.
wrapAISDK decorates AI SDK functions so their executions are recorded by LangSmith without requiring LangChain's open-source frameworks. The application continues invoking the returned wrapped methods.
Follow-up: What should a serverless function do before returning? It should wait for all LangSmith runs to flush so traces are not lost during shutdown.
traceable can surround AI SDK calls or be used within AI SDK tool calls. This adds tracing for application-level operations that are not covered by the directly wrapped SDK method.
Follow-up: When is traceable especially useful? Use it to represent custom work or nested tool-related operations as separate traceable units.
wrapAISDKtraceableLangSmith client SDKAI SDK model provider