Vercel AI SDK Integration
The Foil SDK integrates with the Vercel AI SDK to automatically trace streaming responses, tool calls, and multi-step interactions.Setup
Basic Usage
Use the callbacks withstreamText:
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:With useChat Hook
The server-side tracing works seamlessly with the clientuseChat hook: