mirror of
https://github.com/LibreChat-AI/librechat.ai.git
synced 2026-03-27 02:38:32 +07:00
* chore: update GitHub Actions workflow to use latest action version for improved stability * chore: update roadmap references and enhance documentation for AWS Bedrock inference profiles - Updated footer menu and card icons to reflect the 2026 roadmap. - Adjusted default values in changelog and configuration documentation for `maxRecursionLimit`. - Added comprehensive documentation for AWS Bedrock inference profiles, including setup, configuration, and examples. - Introduced Agents API documentation for programmatic access to LibreChat agents. - Enhanced existing documentation for clarity and consistency across various sections. * feat: release Config v1.3.4 with new features and updates - Introduced `create` field in `interface.prompts` and `interface.agents` for enhanced user control. - Added `interface.remoteAgents` configuration for managing remote agent permissions. - Updated `endpoints.bedrock` with `models` and `inferenceProfiles` for better customization. - Included Moonshot as a known endpoint for AI integration. - Introduced new agent capabilities: `deferred_tools` and `programmatic_tools`. - Removed deprecated `forcePrompt` setting from configurations. - Updated default model lists and added support for new models. - Enhanced `modelSpecs` with `artifacts` field and `effort` parameter for Anthropic models. * refactor: update BlogHeader to use usePathname for route handling - Replaced useRouter with usePathname for improved routing in BlogHeader component. - Simplified page retrieval logic by directly using pathname for matching routes. * feat: add changelog for v0.8.3-rc1 release with new features and fixes - Introduced several enhancements including event-driven lazy tool loading, token usage tracking, and programmatic tool calling UI. - Added support for new models and providers, including Claude Opus 4.6 and Moonshot. - Implemented various bug fixes and improvements for better user experience and performance. * chore: nextjs artifact * first draft roadmap * feat: enhance BlogPage with Open Graph image support and layout improvements - Added support for Open Graph images in blog entries to improve visual presentation. - Refactored article layout for better structure and readability, including adjustments to the display of metadata and content. - Updated styles for improved user experience during hover interactions. * feat: enhance BlogPage with date formatting and layout adjustments - Added a new dateFormatted field to entries for improved date display. - Implemented a date formatter for consistent date presentation. - Refactored article layout to use a grid system for better responsiveness. - Updated styles for article links and metadata for enhanced user experience. * feat: add responsive image sizes to BlogPage for improved layout - Included sizes attribute for Open Graph images to enhance responsiveness on different screen sizes. * feat: update feature titles and descriptions for clarity - Changed titles for "Forking Messages and Conversations" to "Forking Chats" and "Memory" to "User Memory" for better alignment with functionality. - Updated descriptions for "Message Search" and "Upload as Text" to enhance understanding of features. * chore: update configuration version to 1.3.4 across multiple documentation files - Updated the version number in `librechat.yaml` examples to reflect the latest release (1.3.4) in various configuration and feature documentation files. * feat: enhance User Memory documentation for clarity and detail - Updated the description to clarify that User Memory is a key/value store that operates on every chat request. - Added a callout to distinguish between key/value storage and conversation memory. - Expanded on the functionality of the memory agent, including its execution process and user control features. - Introduced a section on future improvements for the memory agent's efficiency and relevance. * feat: update title and description for NGINX documentation - Changed the title from "Secure Deployment with Nginx" to "NGINX" for brevity. - Updated the description to provide a clearer overview of the guide's purpose in securing LibreChat deployment with Nginx as a reverse proxy and HTTPS. * feat: update 2026 roadmap with key accomplishments and future plans - Celebrated LibreChat's 3rd anniversary with a summary of achievements from 2025, including growth in GitHub stars and community engagement. - Clarified the timeline for open-sourcing the Code Interpreter API by the end of Q1. - Revised notes on the v1 Admin Panel's core capabilities and community-driven items for better clarity and detail. * feat: enhance blog and author components with Open Graph image support - Added optional `ogImagePosition` field to blog entries for better image placement control. - Updated BlogPage and individual post pages to utilize the new `ogImagePosition` for responsive image styling. - Improved Author component to conditionally render author images based on availability. - Updated 2026 roadmap blog post with a new Open Graph image and position for enhanced visual appeal. * feat: enhance CardComponent with icon support and layout improvements - Added optional `icon` prop to CardComponent for better visual representation. - Updated CardComponent layout to include icon alongside title and children. - Improved styling for CardComponent and CardsBase for enhanced responsiveness and user experience. * feat: update 2026 roadmap with detailed focus areas and community-driven items - Added sections for Q1 and Q2 focus areas, outlining major initiatives like Dynamic Context and Admin Panel. - Enhanced clarity on community-driven items and their prioritization based on GitHub reactions. - Included hiring information to attract full-stack developers for ongoing project support. - Improved overall structure and readability of the roadmap content. * fix: improve icon styling in CardCompat component for better responsiveness - Updated icon container styling to ensure consistent height and width for SVG icons. - Enhanced layout of CardCompat to maintain visual integrity across different screen sizes. * chore: update .gitignore to include next-env.d.ts for TypeScript support * fix: correct import statement formatting in next-env.d.ts for consistency * fix: refine wording in 2026 roadmap for clarity - Updated the description of agentic workflows to emphasize a lean approach to context pulling. - Enhanced overall readability of the section on Dynamic Context. * feat: expand Admin Panel section in 2026 roadmap with detailed capabilities - Added comprehensive descriptions of the Admin Panel's core functionalities, including GUI for configuration, configuration profiles, group and role management, and access controls. - Clarified the development approach for the Admin Panel, emphasizing ongoing iteration and community involvement. - Updated note on the Admin Panel's prioritization and requirements following the ClickHouse acquisition. * feat: add TrackedLink component for enhanced analytics tracking - Introduced a new TrackedLink component that integrates Vercel analytics to track user interactions with links. - The component allows for customizable link properties while ensuring tracking of clicks with relevant metadata. - Updated CardCompat to utilize the new TrackedLink for improved user engagement tracking. * feat: enhance blog post layout and introduce TrackedAnchor component for link tracking - Wrapped the InlineTOC component in a div for improved spacing in blog posts. - Added a new TrackedAnchor component to facilitate link tracking with Vercel analytics, allowing for customizable anchor elements. - Updated mdx-components to utilize TrackedAnchor for enhanced link interaction tracking. * feat: update TrackedLink and TrackedAnchor components for external link handling - Enhanced the TrackedLink component to differentiate between internal and external links, using Next.js Link for internal navigation. - Introduced a utility function to determine if a link is external, improving tracking accuracy. - Updated TrackedAnchor to utilize the same external link handling logic for consistency in link tracking. * feat: add uncaught exception handling section to dotenv configuration documentation - Introduced a new section on uncaught exception handling, explaining how to override the default behavior to keep the app running after exceptions. - Added an option table detailing the `CONTINUE_ON_UNCAUGHT_EXCEPTION` configuration. - Included a warning callout advising against using this feature in production environments. * feat: add ESLint rule for unused variables in TypeScript - Introduced a new ESLint rule to enforce the handling of unused variables, allowing for specific patterns to be ignored. - This enhancement aims to improve code quality by ensuring that developers are alerted to potentially unnecessary variables while maintaining flexibility in naming conventions. * fix: update copyright year in LICENSE file to 2026 * feat: update footer menu link and add 2026 roadmap blog post - Changed the roadmap link in the FooterMenu component to point to the new blog post. - Introduced a new blog post detailing the 2026 roadmap for LibreChat, outlining key features and focus areas for the upcoming year. - Updated the import statement in next-env.d.ts for consistency with the new types directory. * fix: update import path in next-env.d.ts and add comment block in agents.mdx - Changed the import statement in next-env.d.ts to reference the new development types directory. - Added a comment block in agents.mdx to indicate that the Programmatic Tool Calling feature is in private beta. * fix: remove unused ESLint disable comment in context.tsx * chore: update blog
250 lines
11 KiB
Plaintext
250 lines
11 KiB
Plaintext
---
|
|
title: Token Usage
|
|
icon: Coins
|
|
description: This covers how to track and control your token usage for the OpenAI/Plugins endpoints in LibreChat. You will learn how to view your transactions, enable user balances, and add credits to your account.
|
|
---
|
|
|
|
## Intro
|
|
|
|
As of `v0.6.0`, LibreChat accurately tracks token usage for the OpenAI/Plugins endpoints. All token transactions are stored in the "Transactions" collection in your database. In future releases, you'll be able to toggle viewing how much a conversation costs.
|
|
|
|
Currently, you can limit user token usage by enabling user balances. Instead of configuring token credit limits via environment variables, you now set these options in your `librechat.yaml` file under the **balance** section.
|
|
|
|
## Transaction Configuration
|
|
|
|
The transaction system controls whether token usage records are saved to the database. This can be configured separately from the balance system.
|
|
|
|
### Transaction Settings
|
|
|
|
```yaml filename="librechat.yaml"
|
|
version: 1.2.9
|
|
|
|
# Transaction settings
|
|
# Controls whether to save transaction records to the database
|
|
# Default is true (enabled)
|
|
transactions:
|
|
enabled: false
|
|
```
|
|
|
|
**Important:** When `balance.enabled` is set to `true`, transaction recording is automatically enabled regardless of the `transactions.enabled` setting. This ensures that balance tracking functions correctly by maintaining a complete record of all token usage.
|
|
|
|
Check out the [Transactions Configuration](/docs/configuration/librechat_yaml/object_structure/transactions) page for more details.
|
|
|
|
## Balance Configuration
|
|
|
|
The balance system in LibreChat allows administrators to configure how token credit balances are managed for users. All balance settings are now managed in your YAML configuration under the `balance` object.
|
|
|
|
**Note:** This replaces the previous environment variables (`CHECK_BALANCE` and `START_BALANCE`) and provides a more structured way to manage user balances.
|
|
|
|
### Complete Balance Settings
|
|
|
|
```yaml filename="librechat.yaml"
|
|
version: 1.3.4
|
|
|
|
# Balance settings
|
|
balance:
|
|
enabled: true # Enable token credit balances for users
|
|
startBalance: 20000 # Initial tokens credited upon registration
|
|
autoRefillEnabled: false # Enable automatic token refills
|
|
refillIntervalValue: 30 # Numerical value for refill interval
|
|
refillIntervalUnit: "days" # Time unit for refill interval (days, hours, etc.)
|
|
refillAmount: 10000 # Tokens added during each refill
|
|
```
|
|
|
|
### Balance Settings Explained
|
|
|
|
- **enabled**: Activates token credit tracking and balance management for users. When set to `true`, the system will track token usage and enforce balance limits.
|
|
|
|
- **startBalance**: Specifies the initial number of tokens credited to a user upon registration. This is the starting balance for all new users.
|
|
|
|
- **autoRefillEnabled**: Determines whether automatic refilling of token credits is enabled. When set to `true`, the system will automatically add credits to user balances based on the refill interval.
|
|
|
|
- **refillIntervalValue**: Specifies the numerical value for the interval at which token credits are automatically refilled. Works in conjunction with `refillIntervalUnit`.
|
|
|
|
- **refillIntervalUnit**: Specifies the time unit for the refill interval. Supported values include "seconds", "minutes", "hours", "days", "weeks", and "months".
|
|
|
|
- **refillAmount**: Specifies the number of tokens to be added to the user's balance during each automatic refill.
|
|
|
|
Check out the [Balance Configuration](/docs/configuration/librechat_yaml/object_structure/balance) page for more details.
|
|
|
|
## How Auto-Refill Works
|
|
|
|
When a user's balance is tracked and **autoRefill** is enabled, the system will automatically add credits to the balance only when the specified time interval has passed since the last refill. This is achieved by comparing the current date with the `lastRefill` date plus the specified interval.
|
|
|
|
### Auto-Refill Process
|
|
|
|
1. When a user attempts to spend tokens, the system checks if the current balance is sufficient
|
|
2. If the balance would drop to zero or below after the transaction, the system checks if auto-refill is enabled
|
|
3. If auto-refill is enabled, the system checks if the time interval since the last refill has passed:
|
|
- The system compares the current date with `lastRefill + refillInterval`
|
|
- If the interval has passed, tokens are added to the user's balance
|
|
- The `lastRefill` date is updated to the current date
|
|
4. The transaction proceeds if the balance is sufficient (either originally or after refill)
|
|
|
|
### Supported Time Units
|
|
|
|
The `refillIntervalUnit` can be set to any of the following values:
|
|
- "seconds"
|
|
- "minutes"
|
|
- "hours"
|
|
- "days"
|
|
- "weeks"
|
|
- "months"
|
|
|
|
For example, if `refillIntervalValue` is set to 30 and `refillIntervalUnit` is `days`, the system will add `refillAmount` tokens to the user's balance only if 30 days have passed since the last refill.
|
|
|
|
### Balance Synchronization
|
|
|
|
When a user logs in, the system automatically synchronizes their balance settings with the current global balance configuration. This ensures that any changes to the balance configuration are applied to all users.
|
|
|
|
The synchronization process:
|
|
1. Checks if the user has a balance record
|
|
2. If no record exists, creates one with the current `startBalance`
|
|
3. Updates the user's auto-refill settings to match the global configuration
|
|
4. Ensures the user's refill interval and amount match the global settings
|
|
|
|
## Managing Token Balances
|
|
|
|
You can manually add or set user balances. This is especially useful during development or if you plan to build out a full balance-accruing system in the future (for example, via an admin dashboard).
|
|
|
|
### Adding Balances
|
|
|
|
```bash filename="To manually add balances, run the following command:"
|
|
# Local Development
|
|
npm run add-balance
|
|
|
|
# Docker (default setup)
|
|
docker-compose exec api npm run add-balance
|
|
|
|
# Docker (deployment setup)
|
|
docker exec -it LibreChat-API /bin/sh -c "cd .. && npm run add-balance"
|
|
```
|
|
|
|
```bash filename="You can also specify the email and token credit amount to add, e.g.:"
|
|
# Local Development
|
|
npm run add-balance danny@librechat.ai 1000
|
|
|
|
# Docker (default setup)
|
|
docker-compose exec api npm run add-balance danny@librechat.ai 1000
|
|
|
|
# Docker (deployment setup)
|
|
docker exec -it LibreChat-API /bin/sh -c "cd .. && npm run add-balance danny@librechat.ai 1000"
|
|
```
|
|
|
|
### Setting Balances
|
|
|
|
Additionally, you can set a balance for a user. An existing balance will be overwritten by the new balance.
|
|
|
|
```bash filename="To manually set balances, run the following command:"
|
|
# Local Development
|
|
npm run set-balance
|
|
|
|
# Docker (default setup)
|
|
docker-compose exec api npm run set-balance
|
|
|
|
# Docker (deployment setup)
|
|
docker exec -it LibreChat-API /bin/sh -c "cd .. && npm run set-balance"
|
|
```
|
|
|
|
```bash filename="You can also specify the email and token credit amount to set, e.g.:"
|
|
# Local Development
|
|
npm run set-balance danny@librechat.ai 1000
|
|
|
|
# Docker (default setup)
|
|
docker-compose exec api npm run set-balance danny@librechat.ai 1000
|
|
|
|
# Docker (deployment setup)
|
|
docker exec -it LibreChat-API /bin/sh -c "cd .. && npm run set-balance danny@librechat.ai 1000"
|
|
```
|
|
|
|
### Listing of balances
|
|
|
|
```bash filename="To see the balances of your users, you can run:"
|
|
# Local Development
|
|
npm run list-balances
|
|
|
|
# Docker (default setup)
|
|
docker-compose exec api npm run list-balances
|
|
|
|
# Docker (deployment setup)
|
|
docker exec -it LibreChat-API /bin/sh -c "cd .. && npm run list-balances"
|
|
```
|
|
|
|
This works well to track your own usage for personal use; 1000 credits = $0.001 (1 mill USD)
|
|
|
|
## Notes on Token Usage and Balance
|
|
|
|
- With summarization enabled, you will be blocked from making an API request if the cost of the content that you need to summarize + your messages payload exceeds the current balance
|
|
- Counting Prompt tokens is really accurate for OpenAI calls, but not 100% for plugins (due to function calling). It is really close and conservative, meaning its count may be higher by 2-5 tokens.
|
|
- The system allows deficits incurred by the completion tokens. It only checks if you have enough for the prompt Tokens, and is pretty lenient with the completion. The graph below details the logic
|
|
- The above said, plugins are checked at each generation step, since the process works with multiple API calls. Anything the LLM has generated since the initial user prompt is shared to the user in the error message as seen below.
|
|
- There is a 150 token buffer for titling since this is a 2 step process, that averages around 200 total tokens. In the case of insufficient funds, the titling is cancelled before any spend happens and no error is thrown.
|
|
|
|

|
|
|
|
## More details
|
|
source: [LibreChat/discussions/1640](https://github.com/danny-avila/LibreChat/discussions/1640#discussioncomment-8251970)
|
|
|
|
> "rawAmount": -000, // what's this?
|
|
|
|
Raw amount of tokens as counted per the tokenizer algorithm.
|
|
|
|
> "tokenValue": -00000, // what's this?
|
|
|
|
Token credits value. 1000 credits = $0.001 (1 mill USD)
|
|
|
|
> "rate": 00, // what's this?
|
|
|
|
The rate at which tokens are charged as credits.
|
|
|
|
For example, gpt-3.5-turbo-1106 has a rate of 1 for user prompt (input) and 2 for completion (output)
|
|
|
|
| Model | Input | Output |
|
|
|-----------------------|----------------------|----------------------|
|
|
| gpt-3.5-turbo-1106 | $0.0010 / 1K tokens | $0.0020 / 1K tokens |
|
|
|
|
|
|
Given the provided example:
|
|
```sh
|
|
"rawAmount": -137
|
|
"tokenValue": -205.5
|
|
"rate": 1.5
|
|
```
|
|
|
|
```math
|
|
\text{Token Value} = (\text{Raw Amount of Tokens}) \times (\text{Rate})
|
|
```
|
|
|
|
```math
|
|
137 \times 1.5 = 205.5
|
|
```
|
|
|
|
And to get the real amount of USD spend based on **Token Value**:
|
|
|
|
```math
|
|
\frac{\text{Token Value}}{1,000,000} = \left(\frac{\text{Raw Amount of Tokens} \times \text{Rate}}{1,000,000}\right)
|
|
```
|
|
|
|
```math
|
|
\frac{205.5}{1,000,000} = \$0.0002055 \text{ USD}
|
|
```
|
|
|
|
The relevant file for editing rates is found in `api/models/tx.js`
|
|
|
|
There will be more customization for this soon from the `librechat.yaml` file.
|
|
|
|
## Preview
|
|
|
|

|
|
|
|

|
|
|
|
## Additional Notes
|
|
|
|
- With summarization enabled, API requests are blocked if the cost of the content plus the messages payload exceeds the current balance.
|
|
- The system is lenient with completion tokens, focusing primarily on prompt tokens for balance checks.
|
|
- A buffer is added for titling (approximately 150 tokens) to account for the two-step process.
|
|
- Token credits translate to monetary value (e.g., 1000 credits = $0.001 USD).
|
|
|
|
For more details and customizations, please refer to the [LibreChat Documentation](https://www.librechat.ai/docs/configuration/librechat_yaml).
|