Repository navigation
Description
Description
Implement a global token usage limiter to allow users to set aggregate consumption caps across all chat sessions. This feature acts as a "guardrail" for digital wellbeing, cost management (for API users), and hardware longevity.
Proposed Behavior
1. Scope & Configuration
- Aggregate Cap: Users can define a custom token limit (e.g., 150,000 tokens) over a user-defined period (daily, weekly, monthly, etc.).
- Usage Toggles: The limiter should offer two modes for calculating usage:
- Combined Mode: Sum of Local, Unsloth served API, and external cloud served token usage.
- Split Mode: Separate, independent caps for Local models and API services.
- Usage Calculation Method: Users should be able to choose whether the limit applies to:
- Total Tokens: Includes reasoning/thinking tokens + response tokens. Includes full attention/context of every conversation including previous tokens.
- ** Incremental (Prompt + Completion Delta):** Sums only the newly introduced prompt and completion tokens for every interaction (including internal "thinking" or reasoning processes), the same method to how Unsloth counts token usage inside of each conversation. This method ignores the attention overhead—meaning it does not re-count historical conversation text that is being fed back into the model's attention mechanism in subsequent turns.
2. Enforcement Logic
- Global Counter: The limiter must utilize a single global counter across all concurrently open sessions and windows to prevent users from bypassing limits by opening new chats or restarting the application. A warning can be shown in the upper section of the chat or API screen when limit is being approached.
- Mid-Generation Handling: To ensure a smooth user experience, if a limit is reached during an active response, the current generation should be allowed to finish. The block should only trigger on the subsequent request.
- Override Mechanism: When a limit is hit, provide a "One-time Override" dialog with explicit friction:
"You have reached your [Period] limit. Would you like to allow one more response to finish your current task? (This action cannot be undone until the next reset)."
3. Security & Accountability
- Automated Resets: Limits should automatically reset at the end of the user-defined period.
- Password-Protected Deactivation: To support accountability, users can set a password to deactivate or bypass the limiter before the period ends. This allows for "external" enforcement, where a third party (e.g., a parent, guardian, or mentor) sets the limit and holds the password to ensure the user adheres to their self-imposed boundaries.
Rationale and Use Cases
- Digital Wellbeing & Neurodiversity: Provides hard boundaries for users prone to hyper-fixation (e.g., ADHD) to prevent excessive AI consumption during deep work.
- Cost Management: Enables hybrid users to strictly control expenditures when using external APIs alongside local models.
- Hardware Longevity: Helps manage GPU/CPU thermal load, battery discharge, and component duty cycles by capping the total amount of compute time/tokens processed locally.
Context
This is Part 2 of a two-part feature request. Part 1 (Token Usage Analytics/Dashboard #7214) has already been implemented in previous updates thanks to Dan. This issue focuses specifically on the enforcement and logic of the limiter.
Future Roadmap: Part 3 (Proposed)
Energy Consumption Guardrails
A proposed extension to this feature would involve locking local LLM access based on energy consumption rather than just token count.
- Concept: The system would calculate "Net Energy Usage" (Total power consumed during inference minus the base idle power of the hardware) and lock local models once a specific energy threshold is reached.
- Prerequisite: Implementation of this feature is contingent upon first implementing a comprehensive Energy Usage Tracker in Unsloth Desktop. I'll write that feature request after Qwen 4 releases.
AI Usage Disclosure: Used Gemma-4-26B-A4B to format and improve wording.
Activity
debojyoti-dev commentedon Nov 2, 2026
Hi @danielhanchen, I'd like to take this one up. Plan: a per-account limiter in Studio settings (cap, period daily/weekly/monthly, combined or split local/API caps, total vs incremental counting), counted from the same studio.db usage the Profile stats already read, so every chat window and API key shares one counter. The check runs before each new request, so a response that crosses the cap still finishes; the next one is blocked with a one-time override, and an optional password guards turning it off early. Does that direction work for you?
TheAlex25 commentedon Nov 2, 2026
Thank you for taking this up with Dan, that works well. And since this is global, it tracks all the tokens used from previous convos. Mid generation handling and the one-time override is also important, same with the Incremental (Prompt + Completion Delta) option, as Unsloth counts tokens in two ways (the method inside a chat is counted less than the method in the "Profile" section under token activity. I am sure that 5% of people will use this, cos some of us get sidetracked by AI. Finally, people such as myself can free themselves from being chained to their PCs chatting with their LLM all day. Wish I knew how to program, would totally help you with this, bro. But I only know how to import numpy as np in Python and do basic math in it.