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: betaWhat was tested
| Scenario | How | Expected | Result |
|---|---|---|---|
| Chat reply | A learner asks the chat widget on beta.skillpixel.vn | chatbot.reply rows for the learner, one PostHog trace | Pass |
| Document upload | Upload a small test file to the chatbot with X-LMS-Environment: beta, then delete it | One chatbot.document_embed row on the beta ledger | Pass |
| Upload while the vector store is down | Same upload while Zilliz was stopped; the upload fails with 500 | The embedding OpenAI already billed is still recorded | Pass |
| Environment routing | Chatbot log for the upload | Report goes to beta, not prod | Pass |
Numbers, ledger against PostHog
Each chat reply makes three OpenAI calls: a query embedding and two gpt-5.6-luna agent steps.
| PostHog trace | Action | Calls | Input tokens | Output tokens | Cost (USD) |
|---|---|---|---|---|---|
5383b147… | chatbot.reply | embedding + 2 × gpt-5.6-luna | 1,510 | 62 | 0.00037465 |
b9d81f1b… | chatbot.reply | embedding + 2 × gpt-5.6-luna | 3,460 | 272 | 0.00114804 |
a91daa2d…, 8b0f963f…, 55e3a9a6… | chatbot.document_embed | 3 × text-embedding-3-large | 96 | 0 | 0.00001248 |
| Total (PostHog) | 5,066 | 334 | ≈ $0.0015 | ||
| SkillPixel on the admin AI usage page (ledger) | 5,066 | 334 | $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
b9d81f1b…).
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.
b9d81f1b…: 3,460 → 272 tokens, $0.0011, as three child calls. Prompt text is not sent, by design.
chatbot.document_embed, text-embedding-3-large, 32 tokens. Uploads run without a user, so the trace belongs to a system actor.Environment
- LMS beta deployed from
mainatbf92e2c(merge of lms-platform#554), 04:37 UTC. - Chatbot on Railway production auto-deployed from
mainat5563b57(merge of lms-ragflow#6), 04:20 UTC. Beta and prod share this chatbot; an upload names its LMS withX-LMS-Environment. - PostHog project: Skill Pixel - Beta.
- The test document was deleted from the SkillPixel knowledge base right after each upload.
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
- SP-797
- lms-platform#554: ledger rows, internal usage route, PostHog events
- lms-ragflow#6: chatbot usage reporting