Ratio Settings
How Code Router uses model, completion, and group ratios to convert API usage into quota consumption.
Ratio settings are a core part of Code Router's internal cost-accounting system. By configuring different ratios you can flexibly control how usage of various models and user groups is converted into quota consumption — useful for internal cost allocation, budget control, or differentiated billing tiers.
The concrete ratio values, prices, currency amounts, and quota-unit conversions shown below are illustrative placeholders only. Code Router is an early demo and none of these numbers are finalized. Treat every value marked (TBD / 待补) as a placeholder to be replaced with your own configuration. Do not rely on any figure here as a real price.
Ratio System Overview
Code Router uses a three-tier ratio system to calculate quota consumption:
- Model Ratio — the base billing multiplier for a given model.
- Completion Ratio — an additional adjustment applied to output tokens.
- Group Ratio — a differentiated multiplier for different user groups.
Relationship between Quota and Ratios
In Code Router, ratios are the parameters used to compute quota consumption. Quota is the internal accounting unit of the system: all API calls are ultimately converted into quota points and deducted from a user's balance.
Quota unit conversion:
- 1 USD ≈ (conversion rate TBD / 待补) quota points
- Quota points are the basic unit for all internal accounting.
- User balances and consumption records are tracked in quota points.
The USD-to-quota conversion rate is an operational decision and is not yet finalized for this demo. Configure it to a value that suits your deployment before exposing billing to end users.
Quota Calculation Formulas
Pay-as-you-go models (token-based)
quota = (input_tokens + output_tokens × completion_ratio) × model_ratio × group_ratioPer-call billing models (fixed price)
quota = model_fixed_price × group_ratio × quota_unitAudio models (handled automatically by Code Router)
quota = (text_input_tokens
+ text_output_tokens × completion_ratio
+ audio_input_tokens × audio_ratio
+ audio_output_tokens × audio_ratio × audio_completion_ratio)
× model_ratio × group_ratioPre-consumption and post-consumption
Code Router uses a two-phase billing mechanism:
- Pre-consumption — before the call, an estimated quota amount is pre-deducted based on the estimated token count.
- Post-consumption — after the call completes, quota is recalculated from the actual token count.
- Difference adjustment — if the actual consumption differs from the pre-consumption, the system automatically corrects the user's balance.
pre_consumed = estimated_tokens × model_ratio × group_ratio
actual = actual_tokens × model_ratio × group_ratio
adjustment = actual - pre_consumedModel Ratio Settings
Model ratios define the base billing multiplier for each model. A higher ratio means more quota is consumed per token; a lower ratio means less.
Illustrative model ratios
The table below uses placeholder values for layout illustration only — the model names, ratios, and any prices are not real Code Router rates (pricing TBD / 价格待补).
| Model Name | Model Ratio | Completion Ratio | Reference Price (Input) | Reference Price (Output) |
|---|---|---|---|---|
| example-model-a | (TBD) | (TBD) | (pricing TBD) | (pricing TBD) |
| example-model-b | (TBD) | (TBD) | (pricing TBD) | (pricing TBD) |
| example-model-c | (TBD) | (TBD) | (pricing TBD) | (pricing TBD) |
Meaning of each value:
- Model Ratio — multiplier relative to the base accounting unit, reflecting cost differences between models.
- Completion Ratio — the billing multiplier for output tokens relative to input tokens.
Setup methods
- JSON configuration — edit the model-ratio JSON directly.
- Visual editor — set ratios through a graphical interface.
(Screenshot placeholder — console ratio editor; image TBD.)
Completion Ratio Settings
The completion ratio applies extra billing to output tokens, mainly to balance the cost difference between input and output for models where output is more expensive than input.
Setup instructions
- The completion ratio affects only output-token billing.
- A value of 1 means output tokens are billed the same as input tokens.
- Greater than 1 → output tokens cost more; less than 1 → output tokens cost less.
Per-model completion-ratio defaults depend on each upstream model's published input/output pricing, which is not finalized in this demo (待补). Set conservative values and adjust based on the upstream provider's actual rates.
Group Ratio Settings
Group ratios let you assign differentiated multipliers to different user groups — enabling internal cost allocation, budget control, or tiered billing.
Group ratio configuration
{
"internal-test": "(TBD)",
"standard": "(TBD)",
"enterprise": "(TBD)",
"trial": "(TBD)"
}Group ratio priority
- User-specific ratio — an individual override set for a particular user.
- Group ratio — the ratio of the group the user belongs to.
- Default ratio — the system default (typically 1.0).
(Screenshot placeholder — group ratio settings; image TBD.)
Visual Ratio Editor
The visual editor provides an intuitive interface for managing ratios, including:
- Batch editing of model ratios.
- Real-time preview of the resulting configuration.
- Conflict detection and alerts.
- Optional synchronization of metadata from upstream channels.
(Screenshot placeholder — visual ratio editor; image TBD.)
Models Without Ratio Settings
For models that have no ratio configured, Code Router can:
- Self-use mode — fall back to a default ratio (default value TBD / 待补).
- Billing mode — return a "ratio or price not configured" error rather than guessing a price.
- Detection — surface unconfigured models in the management interface so they can be filled in.
Upstream Ratio Synchronization
Code Router can help keep local ratios aligned with upstream channels:
- Sync only legally authorized, publicly available price/model metadata from upstream.
- Batch-update local ratio configurations.
- Keep local entries roughly aligned with upstream rates.
- Allow manual adjustment and override at any time.
Quota Calculation Examples
The numbers in these examples are made-up inputs to demonstrate the formulas. They are not real Code Router prices or ratios (价格/费率待补).
Example 1 — token-based, standard group
Scenario inputs (illustrative):
- Input tokens: 1,000
- Output tokens: 500
- Model ratio:
M - Completion ratio:
C - Group ratio:
G
Plug into the pay-as-you-go formula:
quota = (1,000 + 500 × C) × M × GEquivalent USD cost = quota ÷ quota_unit (where quota_unit is the TBD conversion rate).
Example 2 — token-based, discounted group
Scenario inputs (illustrative):
- Input tokens: 2,000
- Output tokens: 1,000
- Model ratio:
M - Completion ratio:
C - Group ratio:
G(a discounted group, e.g. < 1.0)
quota = (2,000 + 1,000 × C) × M × GExample 3 — per-call (fixed price) model
Scenario inputs (illustrative):
- Model fixed price:
P(per-call price, value TBD) - Group ratio:
G - Quota unit:
quota_unit(conversion rate TBD)
quota = P × G × quota_unitFrequently Asked Questions
Found an issue or want to suggest a default ratio scheme? Feedback is welcome via the project's GitHub issues. For more billing rules, see the FAQ.
How is this guide?
Last updated on