AI SDK by Vercel
useChat Hook Integration (Legacy)
Overview
Integration with the Vercel AI SDK UI's useChat
hook.
It allows integration with OpenAI, Anthropic, Mistral, Perplexity, AWS Bedrock, Azure, Google Gemini, Hugging Face, Fireworks, Cohere, LangChain, Replicate, Ollama, and more.
Getting Started
Setup a backend route under /api/chat
@/app/api/chat/route.ts
Define a MyRuntimeProvider
component
@/app/MyRuntimeProvider.tsx
Wrap your app in MyRuntimeProvider
@/app/layout.tsx
Accessing AI SDK Messages
You can use the getExternalStoreMessages
utility to convert ThreadMessage
s back to Message
s from AI SDK.