Skip to main content

Vercel AI SDK Integration

The Foil SDK integrates with the Vercel AI SDK to automatically trace streaming responses, tool calls, and multi-step interactions. 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

Tool Calls

Automatic tracking of tool executions:
Creates a trace like:

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 client useChat hook:

Object Generation

Track structured output generation:

Configuration Options

Error Handling

Errors are automatically captured:

Next Steps

OpenAI Integration

OpenAI-specific features

Signals & Feedback

Record user feedback

Alerting

Set up alerts for issues