How to connect Vercel AI SDK useChat to your Agent Graph
Copy page
Use the Vercel AI SDK's useChat hook to build React chat interfaces that stream responses from your agent graph.
Overview
The Vercel AI SDK v5's useChat
hook provides a React-friendly way to build chat interfaces that stream responses from your agent graph. This guide shows you how to configure useChat
to connect to the agent framework's chat endpoint.
The agent framework's /api/chat
endpoint is compatible with Vercel AI SDK's streaming protocol. See Via API for low-level HTTP details.
Installation
Install the Vercel AI SDK in your React application:
Basic Configuration
Here's a minimal example of using useChat
with your agent graph:
Configuration Options
API Endpoint
The api
parameter should point to your Run API's chat endpoint:
- Local development:
http://localhost:3003/api/chat
- Production:
https://your-run-api-domain.com/api/chat
Authentication
Choose the authentication method:
See Authentication → Run API for more details.
Optional Configuration
Request Context
To pass request context (validated against your Context Config), include it as custom headers:
Request context must be passed via headers, not in the request body. See Request Context for details.
Complete Example
Here's a more complete example with conversation management and styling:
Environment Variables
For production deployments, store configuration in environment variables:
In local development, the Run API runs at http://localhost:3003
. For production, update this to your deployed Run API URL.