e30e75b5d4
Changesets / Create Version PR (push) Has been cancelled
Deploy Shadcn Registry / Deploy Production (push) Has been cancelled
Template Metrics / LOC + Bundle Size (push) Has been cancelled
Code Quality / Oxlint + Oxfmt (push) Has been cancelled
Code Quality / Template Sync (push) Has been cancelled
Code Quality / Build Changed Packages (push) Has been cancelled
Code Quality / Test Changed Packages (push) Has been cancelled
Deploy Expo Example / Deploy Production (push) Has been cancelled
Deploy Ink Example / Deploy Production (push) Has been cancelled
Python Tests / pytest (assistant-stream, 3.10) (push) Has been cancelled
Python Tests / pytest (assistant-stream, 3.12) (push) Has been cancelled
Python Tests / pytest (assistant-ui-sync-server-api, 3.10) (push) Has been cancelled
Python Tests / pytest (assistant-ui-sync-server-api, 3.12) (push) Has been cancelled
AI SDK v7 Example
This example demonstrates how to use @assistant-ui/react-ai-sdk with the Vercel AI SDK v7.
Quick Start
Using CLI (Recommended)
npx assistant-ui@latest create my-app --example with-ai-sdk-v7
cd my-app
Environment Variables
Create .env.local:
OPENAI_API_KEY=your-api-key-here
Run
pnpm install
pnpm dev
Open http://localhost:3000 to see the result.
Key Features
- Uses the new AI SDK v7 with
@ai-sdk/openai - Integrates with
@assistant-ui/reactusing the newuseChatRuntimehook - No RSC support (client-side only)
- Simplified integration with the
useChatRuntimehook that wraps AI SDK v7'suseChat - Uses
AssistantChatTransportto pass system messages and frontend tools to the backend
Custom Transport Configuration
By default, useChatRuntime uses AssistantChatTransport which automatically forwards system messages and frontend tools to the backend.
Custom API URL with Forwarding
When customizing the API URL, you must explicitly use AssistantChatTransport to keep system/tools forwarding:
import { AssistantChatTransport } from "@assistant-ui/react-ai-sdk";
const runtime = useChatRuntime({
transport: new AssistantChatTransport({
api: "/my-custom-api/chat", // Custom URL with system/tools forwarding
}),
});
Disable System/Tools Forwarding
To use the standard AI SDK transport without forwarding:
import { DefaultChatTransport } from "ai";
const runtime = useChatRuntime({
transport: new DefaultChatTransport(), // No system/tools forwarding
});
API Route
The API route at /api/chat uses AI SDK v7 streamText, forwards system and frontend tools, and merges them with a server-defined weather tool.