fix: account for usage quality and provider-specific costs per event - #253
ramapitecusment wants to merge 11 commits into
Conversation
- require explicit model discovery before saving DeepSeek connections - preserve selected models when refreshing the catalog - mark model lists stale when connection details change - add model refresh support to easy mode - apply built-in DeepSeek reasoning levels consistently
- Separate selected and unselected models with independent search and bulk actions - Fix selection initialization and ignore stale discovery responses - Improve keyboard navigation and responsive layouts - Update translations and add model selection UI regression tests
- Align TPS and token normalization with Keeper - Add Redis usage queue batch pulling with HTTP fallback - Prevent cache and invalid token double counting - Refresh usage details immediately after new records arrive
- Detect Web UI secret and port changes in the usage collector - Drop stale Redis subscriptions authenticated with the old key - Reset queue source selection and reconnect with the latest configuration
|
@lzt404 I have updated this proposal against current dev and retargeted it to dev. The integration preserves the upstream Keeper normalizer, Redis fallback and management-key rotation. Tests caught a double Gemini reasoning fold introduced by combining the two implementations; that is fixed, with new regressions. Current validation: 534 Rust tests, 305 Bun tests, TypeScript check and production frontend build pass. I am keeping this broader proposal in draft while separating review units and clarifying the core delivery contract. The first independent core correction is router-for-me/CLIProxyAPI#5817 (DeepSeek cache hits, existing schema, three production lines). The broader core implementation remains in draft at router-for-me/CLIProxyAPI#5765. For this GUI, I propose separating per-event/provider pricing from durable ingestion and endpoint/transport coverage. Would you prefer reviewing the pricing portion first, with journal/ACK integration held until the core design is agreed? The pin now follows dev at 7.3.1; the description explains exactly which proposed core capabilities are still dependencies. |
d1d1f8d to
7b72d97
Compare
Review status: This is the broader accounting/delivery proposal, pending agreement on the core delivery design in router-for-me/CLIProxyAPI#5765. The first independent core normalization fix is router-for-me/CLIProxyAPI#5817.
Usage costs are currently calculated after SQL grouping with a universal context threshold, losing additivity and provider-specific billing behavior. The desktop also ignores authoritative v2 breakdowns, cache lifetimes and media cost dimensions, and can present incomplete usage as fully priced. For example, Gemini 2.5 Pro with 10k input, 1k visible output and 9k thinking is $0.1125 under the checked tariff, rather than the previous $0.0225.
This change normalizes v2 usage, retains raw measurements and their quality, and values each event before summing. Known valuations are snapshotted at ingestion. Model-specific context/tier rules, Claude 5m/1h cache writes, Gemini thinking/audio, OpenAI text/image/audio/cache splits, exact reported xAI media amounts and cumulative video polling are handled separately. Unsupported or missing dimensions return an explicit unknown amount instead of a zero-cost or falsely complete estimate. Model matching is restricted; unknown media variants cannot inherit text-model rates. Manual tariffs can be scoped to provider and upstream URL, and failed price synchronization preserves the last good cache.
The collector consumes the companion core's durable journal, commits a SQLite inbox before ACK, and deduplicates by event ID while preserving repeated request IDs. Raw credentials are fingerprinted before inbox persistence. The UI uses unique row IDs and exposes endpoint/transport/kind filters, logical generation counts, measurement quality and cost coverage. Desktop health probes now request bounded output and collect final usage for Chat, Responses, Claude and Gemini, including partial failure records.
Validation / TDD
cargo test --manifest-path src-tauri/Cargo.toml, with a real macOSTMPDIR).bun test).bun run build(TypeScript + Vite) passed.Core dependency: router-for-me/CLIProxyAPI#5765. This desktop update works with old cores via legacy fallback, but complete source coverage and durable delivery require the companion core. The current
devpin is 7.3.1. That core already provides the existing canonical token breakdown, but does not contain the proposed journal/ACK endpoints and extended billing metadata from the companion PR. Complete durable delivery still requires a release containing the agreed core changes and a subsequent pin update through the normal release workflow.Limits and corrected assumptions: API-rate estimates are not subscription invoices. Lost historical usage, missing cache lifetimes, opaque WebRTC media, ambiguous hosted-tool tariffs and arbitrary plugin traffic cannot be reconstructed. Existing unsnapshotted records may still use available current prices; the new DeepSeek schedule is not applied retrospectively. See
docs/usage-accounting.mdfor the route/source matrix, valuation statuses, official pricing sources and deployment contract.Independent review follow-up: Fixed missing provider/base-URL IPC fields; actual Claude speed versus Priority commitment pricing; eligible regional processing uplift; terminal/error/NDJSON health parsing and provider-specific cache/tool-input counters; propagation of actual response tiers; interrupted schema migration recovery; and the previously unpopulated event-kind/generation counters. SQLite now uses synchronous FULL so ACK follows a durable WAL commit. New regressions were observed failing before fixes, and the full updated suites pass. These follow-up changes also correct the earlier claim that the event counters were already populated.
Integration with current dev: Preserves upstream Keeper token normalization, Redis queue fallback and management-key rotation. Legacy Gemini normalization runs once; schema-v2 breakdown remains authoritative. A regression reproduced 19,000 output tokens instead of 10,000 before removing the duplicate fold. Added integration coverage for the single fold, unknown producer contracts and v2 precedence. The merged dev pin is core 7.3.1.