Vercel AI SDK Integration
The Foil SDK integrates with the Vercel AI SDK to automatically trace streaming responses, tool calls, and multi-step interactions.Quick Start (Recommended)
The easiest way - just initialize Foil and your Vercel AI SDK calls are automatically traced:Manual Callbacks (Alternative)
For more control over tracing, use the callbacks:What Gets Captured
| Event | Captured Data |
|---|---|
onStart | Model, input, start time |
onToken | Streaming tokens, TTFT |
onToolCall | Tool name, arguments |
onToolResult | Tool output, duration |
onFinish | Full response, tokens, latency |
onError | Error message, stack |
Tool Calls
Automatic tracking of tool executions:Multi-Step Conversations
Track multi-turn interactions:With Next.js Route Handlers
Integrate with Next.js API routes:- Auto-Instrumentation (Recommended)
- Manual Callbacks
With useChat Hook
The server-side tracing works seamlessly with the clientuseChat hook: