SP-797 · Verified on beta · 11 Oct 2026

Chatbot OpenAI cost now reaches the ledger and PostHog

Every OpenAI call the SkillPixel chatbot makes, for a learner's chat reply or a document upload, is priced by the LMS, written to tenant_llm_usage_events, shown on the admin AI usage page, and sent to PostHog with the same cost.

Working on beta. A real chat and real uploads produced priced rows in the LMS ledger and matching PostHog events. The token and cost totals agree in all three places. Production is not tested yet: it needs the LMS production release.
Chat replies recorded
2 traces
6 OpenAI calls, $0.0015
Upload reports recorded
3
32 tokens each, $0.00000416
Ledger vs PostHog
Match
same tokens, same cost
Routed to
LMS beta
by X-LMS-Environment: beta

What was tested

ScenarioHowExpectedResult
Chat replyA learner asks the chat widget on beta.skillpixel.vnchatbot.reply rows for the learner, one PostHog tracePass
Document uploadUpload a small test file to the chatbot with X-LMS-Environment: beta, then delete itOne chatbot.document_embed row on the beta ledgerPass
Upload while the vector store is downSame upload while Zilliz was stopped; the upload fails with 500The embedding OpenAI already billed is still recordedPass
Environment routingChatbot log for the uploadReport goes to beta, not prodPass

Numbers, ledger against PostHog

Each chat reply makes three OpenAI calls: a query embedding and two gpt-5.6-luna agent steps.

PostHog traceActionCallsInput tokensOutput tokensCost (USD)
5383b147…chatbot.replyembedding + 2 × gpt-5.6-luna1,510620.00037465
b9d81f1b…chatbot.replyembedding + 2 × gpt-5.6-luna3,4602720.00114804
a91daa2d…, 8b0f963f…, 55e3a9a6…chatbot.document_embed3 × text-embedding-3-large9600.00001248
Total (PostHog)5,066334≈ $0.0015
SkillPixel on the admin AI usage page (ledger)5,066334$0.0015

Embeddings are priced at $0.13 per 1M tokens: 32 tokens × $0.13 / 1M = $0.00000416, the same in the ledger and in PostHog.

Screenshots

Chat widget on beta.skillpixel.vn answering how to pay for a course
1. A learner's question on beta.skillpixel.vn. The chatbot answers from the knowledge base (trace b9d81f1b…).
Admin AI usage page with chatbot.reply and chatbot.document_embed rows
2. Admin AI usage page (beta, October 2026). SkillPixel: 5,066 input, 334 output, $0.0015. By feature: chatbot.reply 6 calls and chatbot.document_embed 3 calls; by model: openai/gpt-5.6-luna and openai/text-embedding-3-large. Another tenant's name is blurred.
PostHog LLM trace for chatbot.reply with two generations and one embedding
3. PostHog, Skill Pixel - Beta, LLM analytics trace b9d81f1b…: 3,460 → 272 tokens, $0.0011, as three child calls. Prompt text is not sent, by design.
PostHog LLM trace for chatbot.document_embed
4. PostHog trace for a document upload: chatbot.document_embed, text-embedding-3-large, 32 tokens. Uploads run without a user, so the trace belongs to a system actor.

Environment

Not covered yet

Production. The LMS change ships with the next release-production. Until then, uploads sent with X-LMS-Environment: prod (the default) are not recorded, because the prod LMS does not have the route yet. The chatbot logs each failed report with its body, so it can be replayed. Chat usage on prod starts with the same release.

Links