feat: add selectable routing groups and composite billing

Support per-model provider enablement and compact model editing. Capture request-time billing factors, charge customer costs separately, and preserve historical statistics without backfills.
This commit is contained in:
elky
2026-10-07 14:49:57 +08:00
parent 310098a853
commit 911c7f8875
110 changed files with 6524 additions and 559 deletions
@@ -159,6 +159,12 @@ async fn perform_stats_aggregation_for_day(
.execute(&mut *tx)
.await?;
sqlx::query(UPDATE_STATS_DAILY_BILLING_COST_SQL)
.bind(day_start_utc)
.bind(day_end_utc)
.execute(&mut *tx)
.await?;
let model_rows =
upsert_stats_daily_model_rows(&mut tx, day_start_utc, day_end_utc, now_utc).await?;
let provider_rows =
@@ -2404,6 +2404,18 @@ WHERE created_at >= $1
AND provider_name NOT IN ('unknown', 'pending')
"#;
// Keep customer consumption separate from the upstream procurement-cost rollup.
pub(super) const UPDATE_STATS_DAILY_BILLING_COST_SQL: &str = r#"
UPDATE stats_daily SET billing_cost=(
SELECT round(COALESCE(sum(billable_amount),0),8)
FROM usage_analytics_facts_v1
WHERE created_at >= $1 AND created_at < $2
AND status NOT IN ('pending','streaming')
AND provider_name NOT IN ('unknown','pending')
)
WHERE date=$1
"#;
#[cfg(test)]
mod tests {
use super::{