Vercel AI SDK
Trace the Vercel AI SDK with Neatlogs (TypeScript).
Wrap the ai module with wrapAISDK to capture generateText, streamText, generateObject, streamObject, embed, embedMany, and rerank — including tool calls, token counts, and model names.
Prerequisites
npm install neatlogs@latest ai @ai-sdk/openaiUsage
import { init, shutdown } from 'neatlogs';
import { wrapAISDK } from 'neatlogs/ai';
import * as ai from 'ai';
import { openai } from '@ai-sdk/openai';
async function main() {
await init({ apiKey: process.env.NEATLOGS_API_KEY, workflowName: 'ai-sdk-demo' });
const { generateText } = wrapAISDK(ai);
const { text } = await generateText({
model: openai('gpt-4o-mini'),
prompt: 'In one sentence, what is the Vercel AI SDK?',
});
console.log(text);
await shutdown();
}
main().catch(console.error);wrapAISDK returns the same module shape, so you destructure and call the functions exactly as before. generateText / generateObject / streamText / streamObject get a parent WORKFLOW span with LLM and TOOL spans nested under it; embed / embedMany / rerank are captured as CHAIN spans.
wrapAISDK works regardless of which provider you plug into the AI SDK (OpenAI, Azure, Anthropic, Google, …) — it instruments the SDK functions, not the provider.