From 31c6db31da3a7f5bcb12f08ee560ec1a9c885e14 Mon Sep 17 00:00:00 2001 From: Stephen <12349+0xSMW@users.noreply.github.com> Date: Thu, 13 Aug 2026 16:00:26 +0700 Subject: [PATCH 1/4] Add Daybreak model pricing --- .../Generated/CodexParserHash.generated.swift | 2 +- .../Vendored/CostUsage/CostUsagePricing.swift | 92 ++++++++- .../CodexBarTests/CostUsagePricingTests.swift | 184 ++++++++++++++++++ .../ProviderArchitectureGatekeeperTests.swift | 12 +- 4 files changed, 278 insertions(+), 12 deletions(-) diff --git a/Sources/CodexBarCore/Generated/CodexParserHash.generated.swift b/Sources/CodexBarCore/Generated/CodexParserHash.generated.swift index 2510cbdb36..4927311f00 100644 --- a/Sources/CodexBarCore/Generated/CodexParserHash.generated.swift +++ b/Sources/CodexBarCore/Generated/CodexParserHash.generated.swift @@ -1,5 +1,5 @@ // Generated by Scripts/regenerate-codex-parser-hash.sh. Do not edit by hand. enum CodexParserHash { - static let value = "47144baa8daccf52" + static let value = "4834e108485b5c3c" } diff --git a/Sources/CodexBarCore/Vendored/CostUsage/CostUsagePricing.swift b/Sources/CodexBarCore/Vendored/CostUsage/CostUsagePricing.swift index 4c04113d89..8070d02939 100644 --- a/Sources/CodexBarCore/Vendored/CostUsage/CostUsagePricing.swift +++ b/Sources/CodexBarCore/Vendored/CostUsage/CostUsagePricing.swift @@ -18,6 +18,11 @@ enum CostUsagePricing { let outputCostPerTokenAboveThreshold: Double? let cacheReadInputCostPerTokenAboveThreshold: Double? let cacheWriteInputCostPerTokenAboveThreshold: Double? + /// Some models publish only standard rates. Do not infer undocumented cache-write or + /// long-context prices from the standard input rate for those models. + let allowsCacheWriteInputFallback: Bool + let requiresExplicitLongContextPricing: Bool + let hasExplicitLongContextPricing: Bool init( inputCostPerToken: Double, @@ -29,7 +34,10 @@ enum CostUsagePricing { inputCostPerTokenAboveThreshold: Double? = nil, outputCostPerTokenAboveThreshold: Double? = nil, cacheReadInputCostPerTokenAboveThreshold: Double? = nil, - cacheWriteInputCostPerTokenAboveThreshold: Double? = nil) + cacheWriteInputCostPerTokenAboveThreshold: Double? = nil, + allowsCacheWriteInputFallback: Bool = true, + requiresExplicitLongContextPricing: Bool = false, + hasExplicitLongContextPricing: Bool = false) { self.inputCostPerToken = inputCostPerToken self.outputCostPerToken = outputCostPerToken @@ -41,6 +49,9 @@ enum CostUsagePricing { self.outputCostPerTokenAboveThreshold = outputCostPerTokenAboveThreshold self.cacheReadInputCostPerTokenAboveThreshold = cacheReadInputCostPerTokenAboveThreshold self.cacheWriteInputCostPerTokenAboveThreshold = cacheWriteInputCostPerTokenAboveThreshold + self.allowsCacheWriteInputFallback = allowsCacheWriteInputFallback + self.requiresExplicitLongContextPricing = requiresExplicitLongContextPricing + self.hasExplicitLongContextPricing = hasExplicitLongContextPricing } } @@ -189,6 +200,19 @@ enum CostUsagePricing { outputCostPerTokenAboveThreshold: 4.5e-5, cacheReadInputCostPerTokenAboveThreshold: 1e-6, cacheWriteInputCostPerTokenAboveThreshold: 1.25e-5), + // Daybreak aliases may be retargeted. Keep the locally observed canonical Blue model + // separate for analytics while retaining the complete published Sol pricing tuple. + "gpt-daybreak-blue-latest": CodexPricing( + inputCostPerToken: 5e-6, + outputCostPerToken: 3e-5, + cacheReadInputCostPerToken: 5e-7, + displayLabel: nil, + cacheWriteInputCostPerToken: 6.25e-6, + thresholdTokens: 272_000, + inputCostPerTokenAboveThreshold: 1e-5, + outputCostPerTokenAboveThreshold: 4.5e-5, + cacheReadInputCostPerTokenAboveThreshold: 1e-6, + cacheWriteInputCostPerTokenAboveThreshold: 1.25e-5), "gpt-5.6-terra": CodexPricing( inputCostPerToken: 2e-6, outputCostPerToken: 1.2e-5, @@ -211,6 +235,24 @@ enum CostUsagePricing { outputCostPerTokenAboveThreshold: 1.8e-6, cacheReadInputCostPerTokenAboveThreshold: 4e-8, cacheWriteInputCostPerTokenAboveThreshold: 5e-7), + // GPT-5.6 Cyber / Daybreak Red. Public rates only; cache-write, long-context, + // and API Fast are undocumented and stay nil. + "gpt-5.6-cyber": CodexPricing( + inputCostPerToken: 1.25e-5, + outputCostPerToken: 7.5e-5, + cacheReadInputCostPerToken: 1.25e-6, + displayLabel: nil, + allowsCacheWriteInputFallback: false, + requiresExplicitLongContextPricing: true), + // Keep the local canonical Red model distinct for analytics. Public documentation has no + // cache-write, long-context, Priority, or Fast rates for Daybreak Red. + "gpt-daybreak-red-latest": CodexPricing( + inputCostPerToken: 1.25e-5, + outputCostPerToken: 7.5e-5, + cacheReadInputCostPerToken: 1.25e-6, + displayLabel: nil, + allowsCacheWriteInputFallback: false, + requiresExplicitLongContextPricing: true), ] static func codexBuiltInPricingFingerprint() -> String { @@ -232,6 +274,9 @@ enum CostUsagePricing { self.optionalPricingFingerprint(pricing.outputCostPerTokenAboveThreshold), self.optionalPricingFingerprint(pricing.cacheReadInputCostPerTokenAboveThreshold), self.optionalPricingFingerprint(pricing.cacheWriteInputCostPerTokenAboveThreshold), + String(pricing.allowsCacheWriteInputFallback), + String(pricing.requiresExplicitLongContextPricing), + String(pricing.hasExplicitLongContextPricing), self.optionalPricingFingerprint(self.codexAPIFastMultiplier(model: model)), ].joined(separator: "|")) } @@ -434,6 +479,18 @@ enum CostUsagePricing { return "gpt-5.6-sol" } + // Unprefixed API aliases resolve to their documented model. The gpt-prefixed names are + // local Codex canonical identities, retained for separate analytics because aliases may + // be retargeted. + switch trimmed { + case "daybreak-blue-latest": + return "gpt-5.6-sol" + case "daybreak-red-latest": + return "gpt-5.6-cyber" + default: + break + } + if self.codex[trimmed] != nil { return trimmed } @@ -541,11 +598,12 @@ enum CostUsagePricing { { let key = self.normalizeCodexModel(model) guard key != self.codexUnattributedModel else { return nil } - let modelsDevLookup = self.modelsDevLookup( + let exactModelsDevLookup = self.modelsDevLookup( providerID: self.codexModelsDevProviderID, model: model, catalog: modelsDevCatalog, cacheRoot: modelsDevCacheRoot) + let modelsDevLookup = exactModelsDevLookup ?? (model == key ? nil : self.modelsDevLookup( providerID: self.codexModelsDevProviderID, model: key, @@ -569,6 +627,10 @@ enum CostUsagePricing { ?? lookup.pricing.inputCostPerTokenAboveThreshold ?? lookup.pricing.inputCostPerToken : bundledLongContext?.cacheWriteInputCostPerTokenAboveThreshold) + let hasExplicitLongContextPricing = lookup.pricing.inputCostPerTokenAboveThreshold != nil + || lookup.pricing.outputCostPerTokenAboveThreshold != nil + || lookup.pricing.cacheReadInputCostPerTokenAboveThreshold != nil + || lookup.pricing.cacheCreationInputCostPerTokenAboveThreshold != nil return CodexPricing( inputCostPerToken: lookup.pricing.inputCostPerToken, outputCostPerToken: lookup.pricing.outputCostPerToken, @@ -583,7 +645,11 @@ enum CostUsagePricing { outputCostPerTokenAboveThreshold: lookup.pricing.outputCostPerTokenAboveThreshold ?? bundledLongContext?.outputCostPerTokenAboveThreshold, cacheReadInputCostPerTokenAboveThreshold: cacheReadAboveThreshold, - cacheWriteInputCostPerTokenAboveThreshold: cacheWriteAboveThreshold) + cacheWriteInputCostPerTokenAboveThreshold: cacheWriteAboveThreshold, + allowsCacheWriteInputFallback: lookup.pricing.cacheCreationInputCostPerToken != nil + || (bundled?.allowsCacheWriteInputFallback ?? true), + requiresExplicitLongContextPricing: bundled?.requiresExplicitLongContextPricing ?? false, + hasExplicitLongContextPricing: hasExplicitLongContextPricing) } guard let pricing = self.codex[key] else { return nil } @@ -620,7 +686,11 @@ enum CostUsagePricing { /// Current public API Fast rates normalized against Standard API pricing. These are deliberately /// distinct from ChatGPT/Codex Fast credit multipliers, which do not represent a USD charge. static func codexAPIFastMultiplier(model: String) -> Double? { - switch self.normalizeCodexModel(model) { + let trimmed = model.trimmingCharacters(in: .whitespacesAndNewlines) + if trimmed == "gpt-daybreak-blue-latest" { + return nil + } + return switch self.normalizeCodexModel(model) { case "gpt-5.4", "gpt-5.4-mini", "gpt-5.6-sol", "gpt-5.6-terra", "gpt-5.6-luna": 2 case "gpt-5.5": 2.5 default: nil @@ -632,7 +702,7 @@ enum CostUsagePricing { inputTokens: Int, cachedInputTokens: Int, cacheWriteInputTokens: Int = 0, - outputTokens: Int) -> Double + outputTokens: Int) -> Double? { // Codex/OpenAI reports `input_tokens` as the total prompt size, with cached reads as a // SUBSET of it. Cache writes (when tracked separately, e.g. Pi) are also a subset of the @@ -642,6 +712,18 @@ enum CostUsagePricing { let remainingAfterCache = totalInput - cached let cacheWrite = min(max(0, cacheWriteInputTokens), remainingAfterCache) let nonCached = remainingAfterCache - cacheWrite + if max(0, cacheWriteInputTokens) > 0, + pricing.cacheWriteInputCostPerToken == nil, + !pricing.allowsCacheWriteInputFallback + { + return nil + } + if totalInput > self.codexPriorityInputTokenLimit, + pricing.requiresExplicitLongContextPricing, + !pricing.hasExplicitLongContextPricing + { + return nil + } let cachedRate = pricing.cacheReadInputCostPerToken ?? pricing.inputCostPerToken let usesLongContextRates = pricing.thresholdTokens.map { totalInput > $0 } ?? false diff --git a/Tests/CodexBarTests/CostUsagePricingTests.swift b/Tests/CodexBarTests/CostUsagePricingTests.swift index 96ce407a6a..2cb02ce513 100644 --- a/Tests/CodexBarTests/CostUsagePricingTests.swift +++ b/Tests/CodexBarTests/CostUsagePricingTests.swift @@ -2,6 +2,7 @@ import Foundation import Testing @testable import CodexBarCore +// swiftlint:disable:next type_body_length struct CostUsagePricingTests { @Test func `normalizes codex model variants exactly`() { @@ -19,6 +20,10 @@ struct CostUsagePricingTests { #expect(CostUsagePricing.normalizeCodexModel("openai/gpt-5.6-terra") == "gpt-5.6-terra") #expect(CostUsagePricing.normalizeCodexModel("gpt-5.6-luna") == "gpt-5.6-luna") #expect(CostUsagePricing.normalizeCodexModel("gpt-5.6") == "gpt-5.6-sol") + #expect(CostUsagePricing.normalizeCodexModel("gpt-daybreak-blue-latest") == "gpt-daybreak-blue-latest") + #expect(CostUsagePricing.normalizeCodexModel("gpt-daybreak-red-latest") == "gpt-daybreak-red-latest") + #expect(CostUsagePricing.normalizeCodexModel("daybreak-blue-latest") == "gpt-5.6-sol") + #expect(CostUsagePricing.normalizeCodexModel("daybreak-red-latest") == "gpt-5.6-cyber") // Fictitious dated suffixes only exercise normalize stripping (not released snapshot IDs). #expect(CostUsagePricing.normalizeCodexModel("gpt-5.6-sol-2099-01-01") == "gpt-5.6-sol") #expect(CostUsagePricing.normalizeCodexModel("openai/gpt-5.6-terra-2099-01-01") == "gpt-5.6-terra") @@ -142,6 +147,185 @@ struct CostUsagePricingTests { #expect(alias == sol) } + @Test + func `local daybreak blue preserves its analytics identity and has no API Fast price`() throws { + let root = try Self.cacheRoot() + let shortContext = CostUsagePricing.codexCostUSD( + model: "gpt-daybreak-blue-latest", + inputTokens: 100, + cachedInputTokens: 10, + outputTokens: 5, + cacheWriteInputTokens: 20, + modelsDevCacheRoot: root) + let longContext = CostUsagePricing.codexCostUSD( + model: "daybreak-blue-latest", + inputTokens: 272_001, + cachedInputTokens: 10, + outputTokens: 10, + cacheWriteInputTokens: 20, + modelsDevCacheRoot: root) + let fast = CostUsagePricing.codexPriorityCostUSD( + model: "gpt-daybreak-blue-latest", + inputTokens: 100, + cachedInputTokens: 10, + cacheWriteInputTokens: 20, + outputTokens: 5, + modelsDevCacheRoot: root) + + #expect(shortContext == (70.0 * 5e-6) + (10.0 * 5e-7) + (20.0 * 6.25e-6) + (5.0 * 3e-5)) + #expect(longContext == (271_971.0 * 1e-5) + (10.0 * 1e-6) + (20.0 * 1.25e-5) + (10.0 * 4.5e-5)) + #expect(fast == nil) + } + + @Test + func `daybreak red rejects undocumented cache write and long context pricing`() throws { + let root = try Self.cacheRoot() + let shortContext = CostUsagePricing.codexCostUSD( + model: "gpt-daybreak-red-latest", + inputTokens: 100, + cachedInputTokens: 10, + outputTokens: 5, + cacheWriteInputTokens: 20, + modelsDevCacheRoot: root) + let longContext = CostUsagePricing.codexCostUSD( + model: "daybreak-red-latest", + inputTokens: 272_001, + cachedInputTokens: 10, + outputTokens: 10, + cacheWriteInputTokens: 20, + modelsDevCacheRoot: root) + let fast = CostUsagePricing.codexPriorityCostUSD( + model: "gpt-daybreak-red-latest", + inputTokens: 100, + cachedInputTokens: 10, + cacheWriteInputTokens: 20, + outputTokens: 5, + modelsDevCacheRoot: root) + + #expect(shortContext == nil) + #expect(longContext == nil) + #expect(fast == nil) + } + + @Test + func `cyber and local daybreak red share documented-only fallback behavior`() throws { + let root = try Self.cacheRoot() + for model in ["gpt-5.6-cyber", "gpt-daybreak-red-latest"] { + #expect(CostUsagePricing.codexCostUSD( + model: model, + inputTokens: 100, + cachedInputTokens: 10, + outputTokens: 5, + cacheWriteInputTokens: 20, + modelsDevCacheRoot: root) == nil) + #expect(CostUsagePricing.codexCostUSD( + model: model, + inputTokens: 272_001, + cachedInputTokens: 0, + outputTokens: 5, + modelsDevCacheRoot: root) == nil) + } + } + + @Test + func `exact models dev red pricing supplies only documented dimensions`() throws { + let root = try Self.seedModelsDevCache(""" + { + "openai": { + "id": "openai", + "models": { + "gpt-daybreak-red-latest": { + "id": "gpt-daybreak-red-latest", + "cost": { + "input": 12.5, + "output": 75, + "cache_read": 1.25, + "cache_write": 15.625, + "context_over_200k": { + "input": 25, + "output": 112.5, + "cache_read": 2.5, + "cache_write": 31.25 + } + } + } + } + } + } + """) + + let shortContext = CostUsagePricing.codexCostUSD( + model: "gpt-daybreak-red-latest", + inputTokens: 100, + cachedInputTokens: 10, + outputTokens: 5, + cacheWriteInputTokens: 20, + modelsDevCacheRoot: root) + let longContext = CostUsagePricing.codexCostUSD( + model: "gpt-daybreak-red-latest", + inputTokens: 272_001, + cachedInputTokens: 10, + outputTokens: 10, + cacheWriteInputTokens: 20, + modelsDevCacheRoot: root) + + #expect(shortContext == (70.0 * 12.5e-6) + (10.0 * 1.25e-6) + (20.0 * 15.625e-6) + (5.0 * 75e-6)) + #expect(longContext == (271_971.0 * 25e-6) + (10.0 * 2.5e-6) + (20.0 * 31.25e-6) + (10.0 * 112.5e-6)) + } + + @Test + func `daybreak models dev exact aliases override bundled fallback`() throws { + let root = try Self.seedModelsDevCache(""" + { + "openai": { + "id": "openai", + "models": { + "gpt-daybreak-blue-latest": { + "id": "gpt-daybreak-blue-latest", + "cost": { "input": 7, "output": 31, "cache_read": 0.7, "cache_write": 8.75 } + } + } + } + } + """) + + let cost = CostUsagePricing.codexCostUSD( + model: "gpt-daybreak-blue-latest", + inputTokens: 100, + cachedInputTokens: 10, + outputTokens: 5, + cacheWriteInputTokens: 20, + modelsDevCacheRoot: root) + + #expect(cost == (70.0 * 7e-6) + (10.0 * 0.7e-6) + (20.0 * 8.75e-6) + (5.0 * 31e-6)) + } + + @Test + func `provider qualified daybreak blue models dev record takes exact precedence`() throws { + let root = try Self.seedModelsDevCache(""" + { + "openai": { + "id": "openai", + "models": { + "gpt-daybreak-blue-latest": { + "id": "gpt-daybreak-blue-latest", + "cost": { "input": 7, "output": 31 } + } + } + } + } + """) + + let cost = CostUsagePricing.codexCostUSD( + model: "openai/gpt-daybreak-blue-latest", + inputTokens: 100, + cachedInputTokens: 0, + outputTokens: 5, + modelsDevCacheRoot: root) + + #expect(cost == (100.0 * 7e-6) + (5.0 * 31e-6)) + } + @Test func `codex models dev falls back from gpt56 alias to canonical sol pricing`() throws { let canonicalOnlyRoot = try Self.seedModelsDevCache(""" diff --git a/Tests/CodexBarTests/ProviderArchitectureGatekeeperTests.swift b/Tests/CodexBarTests/ProviderArchitectureGatekeeperTests.swift index e43bf62363..968537256b 100644 --- a/Tests/CodexBarTests/ProviderArchitectureGatekeeperTests.swift +++ b/Tests/CodexBarTests/ProviderArchitectureGatekeeperTests.swift @@ -3606,7 +3606,7 @@ struct ProviderArchitectureGatekeeperTests { reason: "This exact shared construct dispatches a provider-owned capability at the generic integration boundary."), AllowedProviderConstruct( path: "Sources/CodexBarCore/Vendored/CostUsage/CostUsagePricing.swift", - line: 222, + line: 264, anchor: "guard let pricing = self.codex[model] else { continue }", expectedProviderIDs: ["codex"], expectedReferenceCount: 1, @@ -3614,7 +3614,7 @@ struct ProviderArchitectureGatekeeperTests { reason: "This exact cost scanner dispatch selects a provider-owned transcript, cache, or pricing format."), AllowedProviderConstruct( path: "Sources/CodexBarCore/Vendored/CostUsage/CostUsagePricing.swift", - line: 423, + line: 468, anchor: "private static let codexModelsDevProviderID = \"openai\"", expectedProviderIDs: ["openai"], expectedReferenceCount: 1, @@ -3622,7 +3622,7 @@ struct ProviderArchitectureGatekeeperTests { reason: "This exact cost scanner dispatch selects a provider-owned transcript, cache, or pricing format."), AllowedProviderConstruct( path: "Sources/CodexBarCore/Vendored/CostUsage/CostUsagePricing.swift", - line: 437, + line: 494, anchor: "if self.codex[trimmed] != nil {", expectedProviderIDs: ["codex"], expectedReferenceCount: 2, @@ -3630,7 +3630,7 @@ struct ProviderArchitectureGatekeeperTests { reason: "This exact cost scanner dispatch selects a provider-owned transcript, cache, or pricing format."), AllowedProviderConstruct( path: "Sources/CodexBarCore/Vendored/CostUsage/CostUsagePricing.swift", - line: 480, + line: 537, anchor: "if self.claude[base] != nil {", expectedProviderIDs: ["claude"], expectedReferenceCount: 1, @@ -3638,7 +3638,7 @@ struct ProviderArchitectureGatekeeperTests { reason: "This exact cost scanner dispatch selects a provider-owned transcript, cache, or pricing format."), AllowedProviderConstruct( path: "Sources/CodexBarCore/Vendored/CostUsage/CostUsagePricing.swift", - line: 589, + line: 655, anchor: "guard let pricing = self.codex[key] else { return nil }", expectedProviderIDs: ["codex"], expectedReferenceCount: 1, @@ -3646,7 +3646,7 @@ struct ProviderArchitectureGatekeeperTests { reason: "This exact cost scanner dispatch selects a provider-owned transcript, cache, or pricing format."), AllowedProviderConstruct( path: "Sources/CodexBarCore/Vendored/CostUsage/CostUsagePricing.swift", - line: 708, + line: 790, anchor: "guard let pricing = self.claude[key] else { return nil }", expectedProviderIDs: ["claude"], expectedReferenceCount: 1, From d7b1d50e08d31c1430c6f4d5eab912d83522b7cd Mon Sep 17 00:00:00 2001 From: Stephen <12349+0xSMW@users.noreply.github.com> Date: Thu, 13 Aug 2026 16:18:31 +0700 Subject: [PATCH 2/4] Fix Daybreak pricing boundaries --- .../Generated/CodexParserHash.generated.swift | 2 +- .../Vendored/CostUsage/CostUsagePricing.swift | 16 ++++---- .../CodexBarTests/CostUsagePricingTests.swift | 40 +++++++++++++++++++ .../ProviderArchitectureGatekeeperTests.swift | 2 +- 4 files changed, 51 insertions(+), 9 deletions(-) diff --git a/Sources/CodexBarCore/Generated/CodexParserHash.generated.swift b/Sources/CodexBarCore/Generated/CodexParserHash.generated.swift index 4927311f00..fbba78f39c 100644 --- a/Sources/CodexBarCore/Generated/CodexParserHash.generated.swift +++ b/Sources/CodexBarCore/Generated/CodexParserHash.generated.swift @@ -1,5 +1,5 @@ // Generated by Scripts/regenerate-codex-parser-hash.sh. Do not edit by hand. enum CodexParserHash { - static let value = "4834e108485b5c3c" + static let value = "58306eeaab1610c3" } diff --git a/Sources/CodexBarCore/Vendored/CostUsage/CostUsagePricing.swift b/Sources/CodexBarCore/Vendored/CostUsage/CostUsagePricing.swift index 8070d02939..cfc4178698 100644 --- a/Sources/CodexBarCore/Vendored/CostUsage/CostUsagePricing.swift +++ b/Sources/CodexBarCore/Vendored/CostUsage/CostUsagePricing.swift @@ -686,8 +686,9 @@ enum CostUsagePricing { /// Current public API Fast rates normalized against Standard API pricing. These are deliberately /// distinct from ChatGPT/Codex Fast credit multipliers, which do not represent a USD charge. static func codexAPIFastMultiplier(model: String) -> Double? { - let trimmed = model.trimmingCharacters(in: .whitespacesAndNewlines) - if trimmed == "gpt-daybreak-blue-latest" { + // Keep the local Blue identity ineligible even when usage qualifies it with `openai/`. + // The public, unprefixed Daybreak alias deliberately normalizes to Sol instead. + if self.normalizeCodexModel(model) == "gpt-daybreak-blue-latest" { return nil } return switch self.normalizeCodexModel(model) { @@ -718,15 +719,16 @@ enum CostUsagePricing { { return nil } - if totalInput > self.codexPriorityInputTokenLimit, - pricing.requiresExplicitLongContextPricing, + let cachedRate = pricing.cacheReadInputCostPerToken ?? pricing.inputCostPerToken + + let usesLongContextRates = pricing.thresholdTokens.map { totalInput > $0 } ?? false + let unsupportedLongContextThreshold = pricing.thresholdTokens ?? self.codexPriorityInputTokenLimit + if pricing.requiresExplicitLongContextPricing, + totalInput > unsupportedLongContextThreshold, !pricing.hasExplicitLongContextPricing { return nil } - let cachedRate = pricing.cacheReadInputCostPerToken ?? pricing.inputCostPerToken - - let usesLongContextRates = pricing.thresholdTokens.map { totalInput > $0 } ?? false let inputRate = usesLongContextRates ? pricing.inputCostPerTokenAboveThreshold ?? pricing.inputCostPerToken : pricing.inputCostPerToken diff --git a/Tests/CodexBarTests/CostUsagePricingTests.swift b/Tests/CodexBarTests/CostUsagePricingTests.swift index 2cb02ce513..a943b399cd 100644 --- a/Tests/CodexBarTests/CostUsagePricingTests.swift +++ b/Tests/CodexBarTests/CostUsagePricingTests.swift @@ -175,6 +175,8 @@ struct CostUsagePricingTests { #expect(shortContext == (70.0 * 5e-6) + (10.0 * 5e-7) + (20.0 * 6.25e-6) + (5.0 * 3e-5)) #expect(longContext == (271_971.0 * 1e-5) + (10.0 * 1e-6) + (20.0 * 1.25e-5) + (10.0 * 4.5e-5)) #expect(fast == nil) + #expect(CostUsagePricing.codexAPIFastMultiplier(model: "openai/gpt-daybreak-blue-latest") == nil) + #expect(CostUsagePricing.codexAPIFastMultiplier(model: "daybreak-blue-latest") == 2) } @Test @@ -273,6 +275,44 @@ struct CostUsagePricingTests { #expect(longContext == (271_971.0 * 25e-6) + (10.0 * 2.5e-6) + (20.0 * 31.25e-6) + (10.0 * 112.5e-6)) } + @Test + func `red models dev empty long context block rejects at its resolved threshold`() throws { + let root = try Self.seedModelsDevCache(""" + { + "openai": { + "id": "openai", + "models": { + "gpt-daybreak-red-latest": { + "id": "gpt-daybreak-red-latest", + "cost": { + "input": 12.5, + "output": 75, + "cache_read": 1.25, + "context_over_200k": {} + } + } + } + } + } + """) + + let belowThreshold = CostUsagePricing.codexCostUSD( + model: "gpt-daybreak-red-latest", + inputTokens: 200_000, + cachedInputTokens: 10, + outputTokens: 5, + modelsDevCacheRoot: root) + let aboveThreshold = CostUsagePricing.codexCostUSD( + model: "gpt-daybreak-red-latest", + inputTokens: 200_001, + cachedInputTokens: 10, + outputTokens: 5, + modelsDevCacheRoot: root) + + #expect(belowThreshold == (199_990.0 * 12.5e-6) + (10.0 * 1.25e-6) + (5.0 * 75e-6)) + #expect(aboveThreshold == nil) + } + @Test func `daybreak models dev exact aliases override bundled fallback`() throws { let root = try Self.seedModelsDevCache(""" diff --git a/Tests/CodexBarTests/ProviderArchitectureGatekeeperTests.swift b/Tests/CodexBarTests/ProviderArchitectureGatekeeperTests.swift index 968537256b..17734d70e3 100644 --- a/Tests/CodexBarTests/ProviderArchitectureGatekeeperTests.swift +++ b/Tests/CodexBarTests/ProviderArchitectureGatekeeperTests.swift @@ -3646,7 +3646,7 @@ struct ProviderArchitectureGatekeeperTests { reason: "This exact cost scanner dispatch selects a provider-owned transcript, cache, or pricing format."), AllowedProviderConstruct( path: "Sources/CodexBarCore/Vendored/CostUsage/CostUsagePricing.swift", - line: 790, + line: 792, anchor: "guard let pricing = self.claude[key] else { return nil }", expectedProviderIDs: ["claude"], expectedReferenceCount: 1, From 088d3aa98fb56b33c8a6b8a4459f8f1467054e9d Mon Sep 17 00:00:00 2001 From: Stephen <12349+0xSMW@users.noreply.github.com> Date: Fri, 14 Aug 2026 14:22:00 +0700 Subject: [PATCH 3/4] Require complete long-context pricing --- .../Generated/CodexParserHash.generated.swift | 2 +- .../Vendored/CostUsage/CostUsagePricing.swift | 8 +++-- .../CodexBarTests/CostUsagePricingTests.swift | 31 +++++++++++++++++++ .../ProviderArchitectureGatekeeperTests.swift | 4 +-- 4 files changed, 39 insertions(+), 6 deletions(-) diff --git a/Sources/CodexBarCore/Generated/CodexParserHash.generated.swift b/Sources/CodexBarCore/Generated/CodexParserHash.generated.swift index 46cfdb023b..1a1d713f65 100644 --- a/Sources/CodexBarCore/Generated/CodexParserHash.generated.swift +++ b/Sources/CodexBarCore/Generated/CodexParserHash.generated.swift @@ -1,5 +1,5 @@ // Generated by Scripts/regenerate-codex-parser-hash.sh. Do not edit by hand. enum CodexParserHash { - static let value = "735d9f18f43eb70f" + static let value = "916e619d665f4f79" } diff --git a/Sources/CodexBarCore/Vendored/CostUsage/CostUsagePricing.swift b/Sources/CodexBarCore/Vendored/CostUsage/CostUsagePricing.swift index cfc4178698..681e7d3c0a 100644 --- a/Sources/CodexBarCore/Vendored/CostUsage/CostUsagePricing.swift +++ b/Sources/CodexBarCore/Vendored/CostUsage/CostUsagePricing.swift @@ -627,10 +627,12 @@ enum CostUsagePricing { ?? lookup.pricing.inputCostPerTokenAboveThreshold ?? lookup.pricing.inputCostPerToken : bundledLongContext?.cacheWriteInputCostPerTokenAboveThreshold) + // Models that require documented long-context pricing must not treat one populated + // dimension as approval to fall back to short-context rates for the remaining buckets. let hasExplicitLongContextPricing = lookup.pricing.inputCostPerTokenAboveThreshold != nil - || lookup.pricing.outputCostPerTokenAboveThreshold != nil - || lookup.pricing.cacheReadInputCostPerTokenAboveThreshold != nil - || lookup.pricing.cacheCreationInputCostPerTokenAboveThreshold != nil + && lookup.pricing.outputCostPerTokenAboveThreshold != nil + && lookup.pricing.cacheReadInputCostPerTokenAboveThreshold != nil + && lookup.pricing.cacheCreationInputCostPerTokenAboveThreshold != nil return CodexPricing( inputCostPerToken: lookup.pricing.inputCostPerToken, outputCostPerToken: lookup.pricing.outputCostPerToken, diff --git a/Tests/CodexBarTests/CostUsagePricingTests.swift b/Tests/CodexBarTests/CostUsagePricingTests.swift index a943b399cd..f781778e1f 100644 --- a/Tests/CodexBarTests/CostUsagePricingTests.swift +++ b/Tests/CodexBarTests/CostUsagePricingTests.swift @@ -313,6 +313,37 @@ struct CostUsagePricingTests { #expect(aboveThreshold == nil) } + @Test + func `red models dev partial long context block rejects at its resolved threshold`() throws { + let root = try Self.seedModelsDevCache(""" + { + "openai": { + "id": "openai", + "models": { + "gpt-daybreak-red-latest": { + "id": "gpt-daybreak-red-latest", + "cost": { + "input": 12.5, + "output": 75, + "cache_read": 1.25, + "context_over_200k": { "input": 25 } + } + } + } + } + } + """) + + let aboveThreshold = CostUsagePricing.codexCostUSD( + model: "gpt-daybreak-red-latest", + inputTokens: 200_001, + cachedInputTokens: 10, + outputTokens: 5, + modelsDevCacheRoot: root) + + #expect(aboveThreshold == nil) + } + @Test func `daybreak models dev exact aliases override bundled fallback`() throws { let root = try Self.seedModelsDevCache(""" diff --git a/Tests/CodexBarTests/ProviderArchitectureGatekeeperTests.swift b/Tests/CodexBarTests/ProviderArchitectureGatekeeperTests.swift index d62c8afe61..5e902222c2 100644 --- a/Tests/CodexBarTests/ProviderArchitectureGatekeeperTests.swift +++ b/Tests/CodexBarTests/ProviderArchitectureGatekeeperTests.swift @@ -3644,7 +3644,7 @@ struct ProviderArchitectureGatekeeperTests { reason: "This exact cost scanner dispatch selects a provider-owned transcript, cache, or pricing format."), AllowedProviderConstruct( path: "Sources/CodexBarCore/Vendored/CostUsage/CostUsagePricing.swift", - line: 655, + line: 657, anchor: "guard let pricing = self.codex[key] else { return nil }", expectedProviderIDs: ["codex"], expectedReferenceCount: 1, @@ -3652,7 +3652,7 @@ struct ProviderArchitectureGatekeeperTests { reason: "This exact cost scanner dispatch selects a provider-owned transcript, cache, or pricing format."), AllowedProviderConstruct( path: "Sources/CodexBarCore/Vendored/CostUsage/CostUsagePricing.swift", - line: 792, + line: 794, anchor: "guard let pricing = self.claude[key] else { return nil }", expectedProviderIDs: ["claude"], expectedReferenceCount: 1, From 7b593f52e8e4ab35080ff2f43dadaa3cc8a59c6f Mon Sep 17 00:00:00 2001 From: Stephen <12349+0xSMW@users.noreply.github.com> Date: Fri, 14 Aug 2026 14:47:51 +0700 Subject: [PATCH 4/4] Honor long-context cache-write pricing --- .../Generated/CodexParserHash.generated.swift | 2 +- .../Vendored/CostUsage/CostUsagePricing.swift | 7 +++- .../CodexBarTests/CostUsagePricingTests.swift | 37 +++++++++++++++++++ .../ProviderArchitectureGatekeeperTests.swift | 2 +- 4 files changed, 44 insertions(+), 4 deletions(-) diff --git a/Sources/CodexBarCore/Generated/CodexParserHash.generated.swift b/Sources/CodexBarCore/Generated/CodexParserHash.generated.swift index 1a1d713f65..7c4d36e266 100644 --- a/Sources/CodexBarCore/Generated/CodexParserHash.generated.swift +++ b/Sources/CodexBarCore/Generated/CodexParserHash.generated.swift @@ -1,5 +1,5 @@ // Generated by Scripts/regenerate-codex-parser-hash.sh. Do not edit by hand. enum CodexParserHash { - static let value = "916e619d665f4f79" + static let value = "82a30cf9847e9635" } diff --git a/Sources/CodexBarCore/Vendored/CostUsage/CostUsagePricing.swift b/Sources/CodexBarCore/Vendored/CostUsage/CostUsagePricing.swift index 681e7d3c0a..11534b5774 100644 --- a/Sources/CodexBarCore/Vendored/CostUsage/CostUsagePricing.swift +++ b/Sources/CodexBarCore/Vendored/CostUsage/CostUsagePricing.swift @@ -715,15 +715,18 @@ enum CostUsagePricing { let remainingAfterCache = totalInput - cached let cacheWrite = min(max(0, cacheWriteInputTokens), remainingAfterCache) let nonCached = remainingAfterCache - cacheWrite + let usesLongContextRates = pricing.thresholdTokens.map { totalInput > $0 } ?? false + let applicableCacheWriteRate = usesLongContextRates + ? pricing.cacheWriteInputCostPerTokenAboveThreshold ?? pricing.cacheWriteInputCostPerToken + : pricing.cacheWriteInputCostPerToken if max(0, cacheWriteInputTokens) > 0, - pricing.cacheWriteInputCostPerToken == nil, + applicableCacheWriteRate == nil, !pricing.allowsCacheWriteInputFallback { return nil } let cachedRate = pricing.cacheReadInputCostPerToken ?? pricing.inputCostPerToken - let usesLongContextRates = pricing.thresholdTokens.map { totalInput > $0 } ?? false let unsupportedLongContextThreshold = pricing.thresholdTokens ?? self.codexPriorityInputTokenLimit if pricing.requiresExplicitLongContextPricing, totalInput > unsupportedLongContextThreshold, diff --git a/Tests/CodexBarTests/CostUsagePricingTests.swift b/Tests/CodexBarTests/CostUsagePricingTests.swift index f781778e1f..9c70b246e9 100644 --- a/Tests/CodexBarTests/CostUsagePricingTests.swift +++ b/Tests/CodexBarTests/CostUsagePricingTests.swift @@ -344,6 +344,43 @@ struct CostUsagePricingTests { #expect(aboveThreshold == nil) } + @Test + func `red models dev long context cache write does not require a short context rate`() throws { + let root = try Self.seedModelsDevCache(""" + { + "openai": { + "id": "openai", + "models": { + "gpt-daybreak-red-latest": { + "id": "gpt-daybreak-red-latest", + "cost": { + "input": 12.5, + "output": 75, + "cache_read": 1.25, + "context_over_200k": { + "input": 25, + "output": 112.5, + "cache_read": 2.5, + "cache_write": 31.25 + } + } + } + } + } + } + """) + + let longContext = CostUsagePricing.codexCostUSD( + model: "gpt-daybreak-red-latest", + inputTokens: 200_001, + cachedInputTokens: 10, + outputTokens: 5, + cacheWriteInputTokens: 20, + modelsDevCacheRoot: root) + + #expect(longContext == (199_971.0 * 25e-6) + (10.0 * 2.5e-6) + (20.0 * 31.25e-6) + (5.0 * 112.5e-6)) + } + @Test func `daybreak models dev exact aliases override bundled fallback`() throws { let root = try Self.seedModelsDevCache(""" diff --git a/Tests/CodexBarTests/ProviderArchitectureGatekeeperTests.swift b/Tests/CodexBarTests/ProviderArchitectureGatekeeperTests.swift index 5e902222c2..141019430a 100644 --- a/Tests/CodexBarTests/ProviderArchitectureGatekeeperTests.swift +++ b/Tests/CodexBarTests/ProviderArchitectureGatekeeperTests.swift @@ -3652,7 +3652,7 @@ struct ProviderArchitectureGatekeeperTests { reason: "This exact cost scanner dispatch selects a provider-owned transcript, cache, or pricing format."), AllowedProviderConstruct( path: "Sources/CodexBarCore/Vendored/CostUsage/CostUsagePricing.swift", - line: 794, + line: 797, anchor: "guard let pricing = self.claude[key] else { return nil }", expectedProviderIDs: ["claude"], expectedReferenceCount: 1,