Categories: Licensing
Rate Limits: Implementing AI-Style Token Models with CodeMeter
Generative AI has brought token-based business models into the spotlight. Instead of unlimited usage, customers receive defined quotas that can be used within specified periods. These rate limits are not limited to AI services, however. With CodeMeter, software vendors can combine time-based usage limits, automatically replenished quotas, and additional capacity, even without a permanent Internet connection.
When Tokens Are Replenished Regularly
In conventional consumption-based licensing models, a customer purchases a fixed number of tokens. Each use permanently reduces the available balance. Once it is depleted, the customer must purchase more tokens.
Many AI providers use different models. For example, customers receive a certain number of tokens per hour, day, or month. They can use the available tokens within that time window. Once the period ends, the quota is automatically replenished.
This principle is known as rate limiting. It limits the use of software or a service within defined time intervals.
For example, a customer might be allowed to use a maximum of 100,000 tokens within four hours and no more than one million tokens per month. Both limits apply simultaneously. Even if the short-term quota has already been replenished, the monthly limit remains in effect.
This allows software vendors to offer different usage tiers. A basic subscription might include lower limits, while higher-tier plans offer larger quotas or shorter waiting times.
Unit Counter and Universal Data
In CodeMeter, these models can be implemented with Unit Counter and Universal Data (UvD).
The Unit Counter provides a protected counter that can be used to track or control token consumption. The data fields complement this mechanism with information about time-based usage limits.
Universal Data are protected data fields that can be associated with a license. They can store the number of tokens permitted per period, current consumption, and the time of the next replenishment.
The implementation distinguishes between information that cannot be changed and information that can. Limit definitions are typically stored in read-only data fields. They are set by the software vendor during license activation and cannot be changed by the application.
Other data fields are configured with write permissions for use during operation. The software stores the current status of each quota and its next reset time in these fields.
This separation distinguishes the contractually defined terms of use from consumption data that changes at runtime.
Enforcing Multiple Limits Simultaneously
A key feature of modern AI token models is the combination of different time windows.
Instead of setting a single limit, software vendors can define several independent limits. For example, a maximum of 10,000 tokens could be used within one hour and a maximum of one million within one month.
Every use must be checked against all relevant limits.
If enough tokens remain in the hourly quota but the monthly quota has already been exhausted, further usage is denied. Conversely, a customer may be well below their monthly quota but have to wait temporarily because the hourly limit has been reached.
The requested number of tokens can only be used if all applicable limits permit it.
In practice, combining two or three limits is often sufficient. A short-term session limit can restrict intensive usage over a few hours, while an additional monthly limit defines the subscription’s total usage allowance.
This allows both short-term usage spikes and longer-term quotas to be managed.
Rolling Windows and Fixed Reset Times
Not all rate limits have to follow the same timing rules. The CodeMeter reference implementation distinguishes between rolling time windows and fixed, calendar-based intervals.
With a Rolling Window, the time window begins when usage starts or according to a predefined time interval. One example is 100 tokens within 60 seconds. Once the window ends, the quota is replenished. Longer intervals, such as one or four hours, are often more appropriate for real-world applications. Short windows, by contrast, can be useful for demonstrations and testing.
With fixed intervals, replenishment takes place at defined times. A five-minute limit can, for example, reset at 00:00, 00:05, 00:10, and 00:15. An hourly limit resets on the hour.
Daily, weekly, and monthly quotas are also possible. By default, these follow Coordinated Universal Time (UTC): A daily limit resets at midnight, a weekly limit on Monday, and a monthly limit on the first day of the month.
The distinction matters: A rolling window has its own individual time window, while fixed intervals follow a shared schedule.
Time Zones and Configurable Offsets
Internally, the reference implementation uses UTC as its time basis. This ensures consistent calculations regardless of where the software is used.
However, quotas do not always need to reset according to UTC. A customer in Germany may expect their daily quota to reset at midnight German time. Another customer may want replenishment to align with local business hours.
The implementation therefore supports configurable time shifts, known as offsets. These offsets adjust the reset times relative to UTC. For example, hourly limits can be aligned with a different hourly schedule, or daily limits can be set to reset at local midnight.
Weekly quotas do not necessarily have to begin on Monday, either. A configurable offset can adjust the start to a Tuesday, for example. Alternative reset times can also be configured for monthly limits, such as times relative to the beginning or end of the month.
Overflow Tokens for Additional Capacity
What happens when a customer has exhausted their regular quota but urgently needs more tokens?
This is where Overflow Tokens come in. They allow additional usage beyond the limits that normally apply. The CodeMeter reference implementation described here supports different strategies.
In the first option, the customer purchases additional units of consumption. These are permanently deducted when used and are no longer available afterward. This follows the principle of conventional consumption-based tokens.
A second option provides additional capacity for a limited time. For example, a customer could receive a higher usage limit for a specified period to accommodate short-term demand spikes.
This additional capacity can have its own reset cycle, such as weekly, monthly, or annually. This supports business models in which customers occasionally need more capacity without having to move permanently to a higher-tier plan.
For software vendors, this also creates an additional revenue opportunity by supplementing regular subscriptions with on-demand extensions.
Controlling the Use of Overflow Tokens
The licensing system does not necessarily need to determine whether additional tokens are used automatically. The application can decide how to handle an exhausted regular quota.
One option is to use overflow tokens automatically as soon as the normal limits are insufficient. Alternatively, the application can first try to perform an action using only the regular quota. If this fails, it can ask the user whether additional tokens should be used.
This distinction is particularly relevant when overflow units incur a charge. Customers can make an informed decision about whether a particular action may incur additional costs or whether they would prefer to wait until the next reset.
The licensing system provides the technical capabilities for this. The software vendor remains responsible for the user experience and for deciding how additional capacity is used.
A Reference Implementation for Software Developers
To simplify the integration of time-based token models, CodeMeter provides a reference implementation with two core functions.
With GetLimits, the application can retrieve the usage limits defined for a license. This includes the configured quotas, their current status, and the next reset times.
The second function, ConsumeCredits, is used to consume a specified number of tokens.
The reference implementation checks the defined time windows and determines whether the requested usage is permitted. Software vendors therefore do not have to develop all the calculations for different time intervals and their combinations themselves.
The actual integration remains part of the application, however. It determines how many tokens each action requires and how to respond when quotas are exhausted.
Subscriptions Without a Permanent Cloud Connection
Although rate-limit models have become widely known through cloud-based AI services, they do not have to rely on a continuously available billing service.
With CodeMeter, the required license information and current consumption data can be managed securely within a license container. The mechanisms described here can therefore be used in both online and offline environments.
This opens up additional possibilities for software vendors, including locally running AI models, industrial analytics applications, and other software products whose usage needs to be controlled through time-based quotas. Subscription-based licenses can also include time-based usage limits.
The software is thus granted not only permission to run, but also a defined set of rules governing how intensively it may be used within specified periods.
The Key Advantage: AI Business Models Independent of the Cloud
Rate limits turn a simple software license into a usage quota that can be flexibly managed. Combining the Unit Counter, data fields such as Universal Data, and configurable time windows makes it possible to implement AI-style billing models with automatic quota replenishment and additional overflow tokens. CodeMeter’s particular advantage is that these models are not limited to cloud services. They can also be used for software running locally and fully isolated environments. This enables modern, usage-based business models even where a permanent Internet connection is unavailable.
KEYnote 52 - Edition Fall/Winter 2026
