Observability for OpenAI ChatKit Apps¶
OpenAI's ChatKit SDK (@openai/chatkit-react) lets you embed a fully managed AI chat widget in any React application. The Anosys integration hooks into ChatKit's lifecycle callbacks to automatically capture every conversation turn, measure performance metrics, and correlate sessions — so you can understand how users interact with your AI assistant in production.
Why Monitor Your ChatKit App¶
A ChatKit-powered assistant is a production AI interface. Every conversation is a user experience that generates cost, latency, and potential failure points:
| What Anosys Captures | Why It Matters |
|---|---|
| Prompts & responses | See exactly what users ask and what the model returns |
| Time-to-first-token | Measure perceived responsiveness of the chat widget |
| Response duration | End-to-end latency from user submit to full response |
| Thread & session IDs | Correlate multi-turn conversations across page views |
| Agentic tasks & thoughts | Capture intermediate reasoning steps and tool invocations |
| User actions | Track message actions (copy, retry, feedback) within the widget |
Architecture Overview¶
The integration uses a custom React hook (useChatObservability) that plugs into ChatKit's built-in callbacks:
%%{init: {"flowchart": {"curve": "linear"}}}%%
graph LR
A[User Message] -->B["ChatKit Widget (@openai/chatkit-react)"]
B -->C[OpenAI API]
C -->B
B -->D["useChatObservability Hook"]
D -->E["Anosys Platform (POST)"]
style B stroke:#1e88e5,color:#fff
style D stroke:#c62828,color:#fff
style E stroke:#388e3c,color:#fff
How it works:
- ChatKit fires
onLog,onResponseStart, andonResponseEndcallbacks during each conversation turn. - The observability hook timestamps each phase to compute time-to-first-token and response duration.
- On response end, the hook fetches the full message thread from the OpenAI API and extracts prompts, responses, and agentic task summaries.
- Everything is shipped to Anosys via a single POST request with structured custom fields.
Getting Started¶
Prerequisites¶
- A React application using
@openai/chatkit-react(v1.4+) - An Anosys pixel of type Agentic AI (create one at console.anosys.ai)
Step 1 — Install ChatKit¶
Step 2 — Add the Observability Hook¶
Create a custom hook that resolves your Anosys API key and provides the lifecycle callbacks:
Step 3 — Wire It Into Your ChatKit Widget¶
Pass the callbacks from the hook into useChatKit:
Step 4 — Set Environment Variables¶
Add the following to your .env file:
What Gets Sent to Anosys¶
Each conversation turn produces a structured payload with the following fields:
| Field | Type | Description |
|---|---|---|
event_type |
String | Always "chatkit chat" |
cvs1 |
String | User's prompt text |
cvs2 |
String | Assistant's response text |
cvs3 |
String | App session ID (unique per page load) |
cvs4 |
String | OpenAI thread ID |
cvn1 |
Number | Response duration (ms) |
cvn2 |
Number | Time-to-first-token (ms) |
messages[] |
Array | Full conversation history with item IDs, timestamps, and message types (prompt, response, thought) |
Agentic task groups (intermediate reasoning steps) are captured as thought messages, giving you visibility into the model's chain-of-thought process.
What You'll See in Anosys¶
Once the integration is live, the Anosys Platform surfaces:
- Conversation traces — every prompt/response pair with timing metadata and thread correlation
- Time-to-first-token trends — track perceived responsiveness over time and across users
- Response duration analysis — identify slow responses, outliers, and degradation patterns
- Session-level views — group all conversation turns within a user session for end-to-end context
- Agentic reasoning visibility — inspect intermediate thoughts and task summaries when the model uses tools
- User action tracking — monitor copy, retry, and feedback actions within the chat widget
Full Reference Implementation¶
The complete working implementation is available as an open-source demo:
Anosys-AI/AnoSys-Demo-Customer — a React + Vite application built with @openai/chatkit-react and full Anosys observability.
Key files:
src/components/ChatWidget.jsx— ChatKit widget with observability callbackssrc/hooks/useChatObservability.js— the observability hook (API key resolution, metrics, thread extraction)src/utils/chatHelpers.js— helper functions for message extraction and Anosys payload mapping
Next Steps¶
- OpenAI Agents Observability — instrument the OpenAI Python SDK for backend agents
- Anthropic Agents Observability — zero-code setup for Claude Code
- Data Ingestion Options — all supported integration methods
- FAQ — frequently asked questions