revert(proxy): drop the 1-hour cache TTL option and TTL-bucketed write accounting

The forced 1-hour cache_control TTL (schema v14) was a mistake. Injected
breakpoints return to Anthropic's standard 5-minute TTL, caller-owned
markers are preserved verbatim instead of having their TTLs rewritten,
and the 5m/1h cache-write buckets are removed from usage parsing and
pricing (back to the single aggregate cache-creation rate). The cache
TTL selector is removed from the rectifier settings panel along with its
i18n keys in all four locales.

SCHEMA_VERSION returns to 13: the unreleased cache_creation_1h_tokens
column and the v13->v14 migration are removed. The feature never shipped
in a release and the introducing commit was never pushed, so no
databases were stamped v14 outside this machine (local DB verified at
user_version 13).
This commit is contained in:
Jason
2026-07-13 17:55:33 +08:00
parent ac52c851bf
commit 6eb217b242
23 changed files with 56 additions and 416 deletions
+3 -43
View File
@@ -94,20 +94,9 @@ impl CostCalculator {
Decimal::from(usage.output_tokens) * pricing.output_cost_per_million / million;
let cache_read_cost =
Decimal::from(usage.cache_read_tokens) * pricing.cache_read_cost_per_million / million;
let (cache_creation_unspecified, cache_creation_5m, cache_creation_1h) =
usage.normalized_cache_creation_buckets();
let cache_creation_5m_price = pricing.cache_creation_cost_per_million;
// The stored cache-creation price is the existing 5-minute rate. Anthropic
// prices 5m writes at 1.25x input and 1h writes at 2x input, therefore the
// corresponding 1h price is 8/5 of the configured 5m price. Unknown providers
// without TTL details retain the configured legacy rate.
let cache_creation_1h_price =
cache_creation_5m_price * Decimal::from(8u32) / Decimal::from(5u32);
let cache_creation_cost = (Decimal::from(cache_creation_unspecified)
+ Decimal::from(cache_creation_5m))
* cache_creation_5m_price
/ million
+ Decimal::from(cache_creation_1h) * cache_creation_1h_price / million;
let cache_creation_cost = Decimal::from(usage.cache_creation_tokens)
* pricing.cache_creation_cost_per_million
/ million;
// 总成本 = 各项基础成本之和 × 倍率
let base_total = input_cost + output_cost + cache_read_cost + cache_creation_cost;
@@ -170,8 +159,6 @@ mod tests {
output_tokens: 500,
cache_read_tokens: 200,
cache_creation_tokens: 100,
cache_creation_5m_tokens: 0,
cache_creation_1h_tokens: 0,
model: None,
message_id: None,
};
@@ -204,8 +191,6 @@ mod tests {
output_tokens: 500,
cache_read_tokens: 200,
cache_creation_tokens: 100,
cache_creation_5m_tokens: 0,
cache_creation_1h_tokens: 0,
model: None,
message_id: None,
};
@@ -226,25 +211,6 @@ mod tests {
assert_eq!(cost.total_cost, Decimal::from_str("0.010035").unwrap());
}
#[test]
fn test_one_hour_cache_creation_uses_premium_rate() {
let usage = TokenUsage {
cache_creation_tokens: 1_000_000,
cache_creation_5m_tokens: 250_000,
cache_creation_1h_tokens: 750_000,
..TokenUsage::default()
};
let pricing = ModelPricing::from_strings("3", "15", "0.3", "3.75").unwrap();
let cost = CostCalculator::calculate(&usage, &pricing, Decimal::ONE);
// 250k × $3.75/M + 750k × $6/M = $5.4375.
assert_eq!(
cost.cache_creation_cost,
Decimal::from_str("5.4375").unwrap()
);
}
#[test]
fn test_cost_multiplier() {
let usage = TokenUsage {
@@ -252,8 +218,6 @@ mod tests {
output_tokens: 0,
cache_read_tokens: 0,
cache_creation_tokens: 0,
cache_creation_5m_tokens: 0,
cache_creation_1h_tokens: 0,
model: None,
message_id: None,
};
@@ -276,8 +240,6 @@ mod tests {
output_tokens: 500,
cache_read_tokens: 0,
cache_creation_tokens: 0,
cache_creation_5m_tokens: 0,
cache_creation_1h_tokens: 0,
model: None,
message_id: None,
};
@@ -295,8 +257,6 @@ mod tests {
output_tokens: 1,
cache_read_tokens: 1,
cache_creation_tokens: 1,
cache_creation_5m_tokens: 0,
cache_creation_1h_tokens: 0,
model: None,
message_id: None,
};