15. Complete statistics and consumption mechanism
Members only · Non-members can read 30% of the article.
- Published
- August 10, 2025
- Reading Time
- 2 min read
- Author
- Felix
- Access
- Members only
Non-members can read 30% of the article.
Because we are making AI applications, we need to collect statistics on user consumption in order to limit unlimited brushes. There are currently two most mainstream methods for limiting user consumption on the market:
- Token-based calculation:
- This method is mainly used for billing of large language model (LLM) APIs, such as OpenAI’s GPT series models - Token is the basic unit of text, usually a word is about 1.3 tokens and a Chinese character is about 2 tokens - Advantages: Accurately reflects the actual calculation amount of model processing, which is directly related to the calculation cost of the model. - Disadvantages: It is difficult for users to understand, and the number of tokens in different languages varies greatly. - Implementation method: consumption of tokens returned by the model, cumulative billing
- Count based calculation: - This method is billed based on the number of requests made by the user - Advantages: simple and intuitive, easy for users to understand their usage - Disadvantages: It is difficult to calculate costs and consumption by yourself, and it is too transparent - Implementation method: Record the number of API calls, which can be counted separately according to different functions or models
I prefer the Token calculation consumption mechanism. For example: you let users use a certain function 5 times at first, but then we found that the consumption cost was too high and found that you wanted to reduce the number of times. Users complained as soon as you reduced the number of times. If you use the Token mechanism, you can adjust the consumption rate yourself. It is originally a doubled consumption. If you want to increase the profit rate at this time, it can be increased to 2 times the consumption. This is relatively invisible (most users will not calculate it), and using the Token mechanism will better count costs.
Complete the table structure
It's very simple. You just need to add a correlation table related to user consumption, and run pnpm db:generate and pnpm db:migrate-local.
Subscribe to unlock the full article
Support the writing, unlock every paragraph, and receive future updates instantly.
Comments
Join the conversation
No comments yet. Be the first to add one.