Repository navigation
feat(billing): two modes, per-token and free, with subscription accounts priced by their price sheet - #106
Merged
Conversation
…nts priced by their price sheet An upstream's cost now depends only on its usage and its price sheet. Billing has two modes: per-token (the default, priced by the price sheet the upstream selected) and free (a definite $0, for local models). A subscription account such as a ChatGPT sign-in is billed per token like any other upstream, so what it shows is its usage converted at API prices. Whether an upstream is a subscription is said by the quota it reports, which is unchanged and has nothing to do with billing. Before, billing had four modes plus auto-detection. Subscription and unknown upstreams carried no amount, so the same usage cost money on one upstream and nothing on another, and "today's cost" meant nothing to a subscription user. Auto-detection also billed the first request after each start per token and the rest as subscription. - tw-config: `providers[].billing` is `per-token` or `free`; unset is per-token and is not written back. `subscription` and `unknown` no longer parse. - tw-gateway: no detection from quota headers. `cheapest` treats only free upstreams as zero cost and compares the rest by price sheet; speed-test and replay quotes price every per-token upstream, and the quote total no longer leaves anything out. - tw-store: every per-token row is priced by its upstream's price sheet. The subscription counts are gone from the summary and from sessions. SCHEMA 18: the billing column's values changed, so older databases are rebuilt rather than read. - tw-control / tw-api: `ProviderView.billing` is always present and `billing_effective` is gone; a ChatGPT sign-in no longer writes `billing: subscription`. Control API version 10. A config that still says `billing: subscription` (every ChatGPT sign-in wrote it) fails to load and has to drop that line; there is no migration.
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
An upstream's cost should depend only on its usage and its price sheet. Billing had four modes plus auto-detection: subscription and unknown upstreams carried no amount, so the same usage cost money on one upstream and nothing on another, and "today's cost" meant nothing to a subscription user. Auto-detection also billed the first request after each start per token and the rest as subscription.
Now there are two modes:
Whether an upstream is a subscription is said by the quota it reports. That is unchanged and no longer affects billing.
What changed
providers[].billingisper-tokenorfree; unset is per-token and is not written back.subscriptionandunknownno longer parse.cheapesttreats only free upstreams as zero cost and compares the rest by price sheet. Speed-test and replay quotes price every per-token upstream, and the quote total no longer leaves anything out.ProviderView.billingis always present,billing_effectiveis gone, and a ChatGPT sign-in no longer writesbilling: subscription. Control API version 10.Consequences
cheapestno longer ranks a subscription account first by default; setting it tofreedoes, and its cost is then $0.billing: subscription(every ChatGPT sign-in wrote it) fails to load until that line is removed. There is no migration.Checks
cargo fmt --check,cargo clippy --workspace --all-targets -D warnings,cargo test --workspace(82 test binaries),./scripts/smoke.sh(51 passed, 0 failed; the memory note is the usual one, within the no-regression bound).🤖 Generated with Claude Code