Skip to content

feat(billing): two modes, per-token and free, with subscription accounts priced by their price sheet - #106

Merged
fylorn merged 1 commit into
mainfrom
feat/billing-two-modes
Sep 22, 2026
Merged

fylorn merged 1 commit into
mainfrom
feat/billing-two-modes

Conversation

@fylorn

@fylorn fylorn commented Sep 22, 2026

Copy link
Copy Markdown
Contributor

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:

  • per-token (default): usage × the unit price in the price sheet the upstream selected. A subscription account such as a ChatGPT sign-in is billed this way too, so its amount is its usage converted at API prices.
  • free: a definite $0, for local models.

Whether an upstream is a subscription is said by the quota it reports. That is unchanged and no longer affects billing.

What changed

  • 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.
  • tw-control / tw-api: ProviderView.billing is always present, billing_effective is gone, and a ChatGPT sign-in no longer writes billing: subscription. Control API version 10.

Consequences

  • cheapest no longer ranks a subscription account first by default; setting it to free does, and its cost is then $0.
  • A config that still says 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

…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.
@fylorn
fylorn merged commit be570ea into main Sep 22, 2026
1 check passed
@fylorn
fylorn deleted the feat/billing-two-modes branch September 22, 2026 09:24
@fylorn fylorn mentioned this pull request Sep 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant