1
Import
Install the package and import the necessary functions from our React export:
2
Initialize lunary
Initialize the SDK with your application’s tracking ID:
3
Use the useChatMonitor hook
The Here’s an example of how you would it into your Chat component.
useChatMonitor hook exposes the following functions:4
Reconcile calls on your backend
Make sure to pass the message IDs to your backend to reconcile with the backend calls and agents.
Vercel AI SDK Integration
Effortlessly integrate the Vercel AI SDK into your Next.js app using lunary We’ve built a custom hook that makes tracking your AI-driven chats a breeze.1
Import and Initialize
Import lunary and the AI SDK helper hook, then initialize the monitor with your app ID.
2
Wrap the useChat hook
3
Setup the monitor on the backend
We’ll need to reconcile the OpenAI calls made in the backend, with messages sent from the frontend. To do this, we’ll need to use the backend version of the lunary.