feat: add billing expression system documentation and enhance tiered billing logic

- Introduced a new rule for the Billing Expression System, emphasizing the importance of reading `pkg/billingexpr/expr.md` for dynamic billing.
- Updated the billing expression logic to support new variables and improved handling of image and audio tokens.
- Enhanced the tiered billing functionality with versioning support for expressions and refined quota calculations.
- Added tests to validate the new billing expression features and ensure correctness in pricing calculations.
This commit is contained in:
CaIon
2026-03-17 15:29:43 +08:00
parent 5b03b39db2
commit c5405b2a12
27 changed files with 894 additions and 578 deletions
+9 -16
View File
@@ -52,22 +52,15 @@ func runProgram(prog *vm.Program, params TokenParams, request RequestInput) (flo
headers := normalizeHeaders(request.Headers)
env := map[string]interface{}{
"p": params.P,
"c": params.C,
"cr": params.CR,
"cc": params.CC,
"cc1h": params.CC1h,
"prompt_tokens": params.P,
"completion_tokens": params.C,
"cache_read_tokens": params.CR,
"cache_create_tokens": params.CC,
"cache_create_1h_tokens": params.CC1h,
"img": params.Img,
"ai": params.AI,
"ao": params.AO,
"image_tokens": params.Img,
"audio_input_tokens": params.AI,
"audio_output_tokens": params.AO,
"p": params.P,
"c": params.C,
"cr": params.CR,
"cc": params.CC,
"cc1h": params.CC1h,
"img": params.Img,
"img_o": params.ImgO,
"ai": params.AI,
"ao": params.AO,
"tier": func(name string, value float64) float64 {
trace.MatchedTier = name
trace.Cost = value