Skip to content

fix(usage): align cache accounting and GPT-5.6 billing#338

Merged
seakee merged 5 commits into
mainfrom
fix/gpt-5-6-cache-metrics
Jul 13, 2026
Merged

fix(usage): align cache accounting and GPT-5.6 billing#338
seakee merged 5 commits into
mainfrom
fix/gpt-5-6-cache-metrics

Conversation

@seakee

@seakee seakee commented Jul 13, 2026

Copy link
Copy Markdown
Owner

Summary

Normalize cache accounting and pricing across current CPA payloads without requiring unreleased upstream metadata.
The change fixes GPT-5.6 cache read/write visibility, cache-hit denominators, long-context billing, and actual response-tier pricing.

Scope

  • Frontend panel
  • Manager Server
  • CPA panel mode
  • Full Docker mode
  • Native packages / release
  • Docs / Wiki
  • CI / build / tooling

Changes

  • Normalize included-input and separate-input cache accounting from provider, executor, and model information already emitted by released CPA versions.
  • Persist canonical input and cache buckets, transactionally backfill legacy rows, and rebuild usage rollups.
  • Price uncached input, legacy cache, CR, and CW independently, including GPT-5.6 cache creation at 1.25x input pricing.
  • Apply GPT-5.4, GPT-5.5, and GPT-5.6 long-context rates only above 272K input tokens.
  • Prefer the response service tier for billing, support Flex and Batch pricing, and avoid stacking Priority with long-context rates.
  • Keep the realtime C, CR, and CW display and align frontend analytics with backend cache-hit semantics.

User Impact

Cache reads and writes now appear consistently in monitoring and analytics. Cost estimates no longer double-count or omit cache tokens, and GPT-5.6 requests use the documented cache, long-context, and service-tier rules.

Compatibility / Runtime Notes

  • CPA panel mode: Works with current CPA queue payloads. cache_input_mode is optional and provider/model inference is used when it is absent.
  • Manager Server mode: An additive SQLite migration backfills normalized cache accounting and rebuilds rollups automatically.
  • Full Docker / native packages: No configuration change or minimum unreleased CPA version is required.

Data / Security Notes

The migration adds nullable accounting and service-tier columns to usage_events, backfills them transactionally, and resets rollup checkpoints for recalculation. Raw usage fields, authentication data, key handling, log sanitization, and exports remain unchanged.

Risk / Rollback

Risk level: Medium

Rollback notes:

  • Revert the five commits added by this PR. Older binaries ignore the additive SQLite columns.
  • Recalculated rollups can be rebuilt from the unchanged raw usage events.

Verification

  • Type check
  • Lint
  • Tests
  • Build
  • Manual UI check
  • Docs/link check
  • Not applicable, docs-only

Commands / evidence:

npm run type-check
npm run lint
npm run test
npm run build
cd apps/manager-server && go test ./...
cd apps/manager-server && go test -race ./...
git diff --check

Frontend result: 86 test files, 740 tests passed.
Manager Server full and race suites passed.

Screenshots / Recordings

N/A. The existing realtime cache-label change is covered by frontend regression tests; no additional visual layout was introduced in the follow-up commits.

Docs

  • README updated
  • Wiki updated
  • Release notes needed
  • Not needed

Related

Closes #333
Closes #336
Refs #326
Refs router-for-me/CLIProxyAPI#4193

seakee added 5 commits July 13, 2026 09:59
Compute cache-hit numerator and denominator using resolved billing models before aggregating aliases.

Expose normalized cache metrics across summaries, timelines, and model breakdown responses.

Clamp malformed ratios without changing raw usage storage or requiring a migration.
Consume normalized cache metrics across model, provider, account, credential, and API-key analytics.

Render legacy C and fine-grained CR/CW on a dedicated line while hiding zero values.

Preserve compatibility fallbacks and add accessible labels and regression coverage.
Add persisted cache-accounting mode and normalized token buckets for existing and new usage events.

Backfill legacy rows transactionally and rebuild rollups so pricing and cache-hit analytics use one canonical input total.

Migration rollback coverage ensures partial failures can be retried without leaving inconsistent checkpoints.
Normalize included and separate cache token accounting from current CPA payloads without requiring new upstream metadata.

Apply response-tier precedence, GPT-5.4 through GPT-5.6 long-context pricing, and distinct cache read and creation rates.

Update repositories, rollups, hit-rate calculations, and regression coverage while preserving compatibility with older CPA versions.
Mirror backend cache normalization and service-tier pricing in frontend usage calculations.

Keep CR and CW distinct, use normalized total input for cache-hit rates, and handle GPT-5.6 cache creation pricing.

Regression coverage includes legacy CPA payloads, long-context boundaries, Flex pricing, and explicit zero prices.
@seakee seakee changed the title fix(monitoring): normalize GPT-5.6 cache metrics fix(usage): align cache accounting and GPT-5.6 billing Jul 13, 2026
@seakee
seakee merged commit 864cba4 into main Jul 13, 2026
9 checks passed
@seakee
seakee deleted the fix/gpt-5-6-cache-metrics branch July 13, 2026 03:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant