diff --git a/README.md b/README.md index 500f14f..225927b 100644 --- a/README.md +++ b/README.md @@ -130,6 +130,70 @@ The dashboard is protected by an API key set in `.env`. When accessing the dashb To reset the key in your browser: open DevTools (F12) > Application > Local Storage > delete `analyticsApiKey`, then refresh. +## Architecture + +``` + https://your-domain + | + +-------v--------+ + | Nginx Proxy | + | (LibreChat) | + +---+-------+----+ + | | + /api, /chat | | /librechat-analytics/* + | | + +-------v--+ +-v------------------+ + | LibreChat | | Analytics Dashboard | + | :3080 | | :3001 | + +-------+---+ +---------+----------+ + | | + | MongoDB | + | queries | + | | + +---v----------------v---+ + | MongoDB | + | (LibreChat database) | + | | + | collections: | + | - transactions | + | - users | + | - agents | + +------------------------+ +``` + +``` + User sends message in LibreChat + | + v + +------------------+ +------------------+ +-------------------+ + | LibreChat calls |---->| LLM processes |---->| LibreChat records | + | LLM API | | prompt + reply | | transaction | + | (Claude, GPT, | | returns tokens | | in MongoDB | + | Gemini, etc.) | | used | | | + +------------------+ +------------------+ +--------+----------+ + | + Transaction record: | + +----------------------------+ | + | user: ObjectId |<+ + | model: "claude-sonnet-4-6" | + | tokenType: "prompt" | + | rawAmount: -15234 | + | tokenValue: -45.702 | + | (rawAmount x $3/1M) | + | createdAt: Date | + +----------------------------+ + | + v + +----------------------------+ + | Analytics Dashboard reads | + | tokenValue from MongoDB | + | | + | cost = |tokenValue| / 1M | + | = 45.702 / 1000000 | + | = $0.000046 | + +----------------------------+ +``` + ## Cost Calculation ### How it works