AI observability: cost, tokens and latency for every model call
Wrap the Vercel AI SDK, the OpenAI client or the Anthropic client once, or send the events yourself, and every generation shows up with its cost, tied to the user and the session behind it.
- 1
- packageWraps the Vercel AI SDK, the OpenAI client and the Anthropic client. Every provider they reach, Azure and OpenRouter included.
- 4
- event kindsgeneration, embedding, span and trace, as ordinary events with flat ai_* properties.
- 30
- days of contentPrompts and completions are kept that long, if you store them at all. Cost and tokens stay.
What a user costs you
Every call carries its model, tokens and cost, and the profile, session and group it belongs to. So the question is not what the API bill was, but which feature, which plan and which customer it went to.
- A price catalog, or your own cost
- Major providers are priced for you. Send cost when a gateway already knows it.
- Per model, feature, user and group
- The AI overview breaks cost down by all four.
- On the profile and the session
- An AI usage widget with lifetime cost, tokens, latency and errors.
Traces for agents
An agent runs the model several times and calls tools in between. Wrap the request once and every step lands in one trace, laid out in time, with the step that failed in red.
- Multi-step chains and tool calls
- withAiContext groups a request; nested contexts merge over it.
- Errors and latency per step
- Time to first token on streams, the finish reason, the error that was rethrown.
- Conversations across requests
- Pass a conversationId and the thread reads as one.
Prompts only if you want them
Tokens, cost, latency and errors are analytics. Prompts and completions are content. OpenPanel keeps the first always and the second only when you say so, and never for more than 30 days.
- Content storage is a switch
- Off for the project, or privacyMode per call.
- 30-day expiry
- Stored content is dropped after a month. The numbers stay with your other events.
- Self-host for full control
- The events land in your own ClickHouse.
In and out
How the events get in, and where else they show up.
- Wrap the SDK you already usewrapLanguageModel for the Vercel AI SDK, wrapOpenAI or wrapAnthropic around the official clients. Sending never blocks the model.
- Or send the events yourselfop.ai() in the Node SDK, or the raw payload from any language.
- A generations listEvery call with its model, tokens, cost, latency and status, and the conversation if you stored it.
- In the session timelineThe model call sits between the page views and clicks around it.
- AI assistants as a traffic sourceSessions referred by ChatGPT, Claude, Perplexity, Gemini, Copilot, Grok, Mistral and Kagi, on the SEO page.
- Ask about itAI events are ordinary events, so the MCP server and the chat can report on them.
Three steps, then it is just events
- 1
Wrap the model
One middleware on wrapLanguageModel, with the OpenPanel client you already have.
import { wrapLanguageModel } from 'ai';import { openai } from '@ai-sdk/openai';import { openpanelAiMiddleware }from '@openpanel/ai/vercel';const model = wrapLanguageModel({model: openai('gpt-5'),middleware:openpanelAiMiddleware({ op }),}); - 2
Say who and what
profileId, a feature name and groups per call, or once per request with withAiContext.
await generateText({model, messages,providerOptions: { openpanel: {profileId: user.id,name: 'inbox-summary',groups: [user.orgId],} },}); - 3
Read cost, traces and the people behind them
The AI section, the profile, the session, and any report you build on ai_* properties.
Frequently asked questions
Common questions about AI observability in OpenPanel.
Start understanding your users today
One script on your site, or one SDK call in your app, and the first events show up within a minute. 30-day free trial, no credit card.
Cloud from $2.50 a month, or self-host for free.