Skip to content

Commit e1ef794

Browse files
author
jun
committed
fix(usage): mark an assumed OpenRouter priority cost as a lower bound
An assumed Fast attempt reported the standard total with no uncertainty marker, so the UI received a definite price for a request whose served tier the provider never echoed. OpenRouter bills by the tier actually served and documents priority as more expensive, so an unmarked standard total can understate the real charge. The confirmed case was already a lower bound because the premium endpoint price is not bundled here. The assumed case needs the same marker for a stronger reason: the outcome itself was never observed. Same treatment, different justification. Driven red: restricting the predicate back to confirmed-only fails the new regression and nothing else.
1 parent 9cd3c1c commit e1ef794

2 files changed

Lines changed: 45 additions & 1 deletion

File tree

‎src/usage/cost.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,12 @@ function applyPriorityMultiplier(
459459
* branch does not bundle its provider-specific priority endpoint prices. A confirmed canonical
460460
* priority result can therefore use the standard price only as a provable lower bound. Do not
461461
* extend this to flex (cheaper) or to other providers without the same pricing contract.
462+
*
463+
* An ASSUMED priority attempt needs the same marker for a different reason. There the provider
464+
* never echoed a tier at all, so the standard price is not merely a lower bound on a known
465+
* premium — it is a floor under an outcome we did not observe. Returning it unmarked reports a
466+
* definite standard cost for a request that may well have been billed as priority, which is the
467+
* one thing a cost estimate must never do.
462468
*/
463469
function isOpenRouterPriorityLowerBound(
464470
provider: string,
@@ -467,7 +473,7 @@ function isOpenRouterPriorityLowerBound(
467473
return baseProviderLabel(provider) === "openrouter"
468474
&& outcome?.canonical === "priority"
469475
&& outcome.fastOutcome === "applied"
470-
&& outcome.confirmation === "confirmed";
476+
&& (outcome.confirmation === "confirmed" || outcome.confirmation === "assumed");
471477
}
472478

473479
/**

‎tests/fastwire-observability.test.ts‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -689,6 +689,44 @@ describe("FastWire per-attempt cost", () => {
689689
expect(openAi.priorityLowerBound).toBeUndefined();
690690
});
691691

692+
test("an ASSUMED OpenRouter priority attempt is a lower bound, not a definite standard price", () => {
693+
// The provider never echoed a tier, so we do not know which price was billed. Reporting
694+
// the standard total unmarked would tell the UI "this cost 1.6" for a request that may
695+
// have been served -- and billed -- as priority. The confirmed case is a lower bound
696+
// because the premium price is not bundled; the assumed case is a lower bound because
697+
// the OUTCOME itself was never observed. Both must carry the marker.
698+
const usage = { inputTokens: 1_000_000, outputTokens: 0, cachedInputTokens: 0 };
699+
const assumedPriority = {
700+
canonical: "priority" as const,
701+
wireKind: "service-tier" as const,
702+
wireValue: "priority",
703+
fastOutcome: "applied" as const,
704+
confirmation: "assumed" as const,
705+
};
706+
const openRouterOverlays: ExpectedPriceOverlay[] = [{
707+
provider: "openrouter",
708+
modelId: "openai/gpt-5.6-sol",
709+
cost4: { input: 5, output: 30, cacheRead: 0.5, cacheWrite: 6.25 },
710+
source: "test",
711+
verifiedAt: "2026-08-18",
712+
status: "verified",
713+
}];
714+
715+
const assumed = estimateComboCost([{
716+
ordinal: 1,
717+
provider: "openrouter",
718+
model: "openai/gpt-5.6-sol",
719+
usageStatus: "reported",
720+
usage,
721+
tierOutcome: assumedPriority,
722+
}], openRouterOverlays)!;
723+
724+
expect(assumed.priorityLowerBound).toBe(true);
725+
expect(assumed.attempts?.[0]?.priorityLowerBound).toBe(true);
726+
// No premium multiplier is applied — the standard rate IS the floor being reported.
727+
expect(assumed.priorityMultiplier).toBeUndefined();
728+
});
729+
692730
test("management cost metadata exposes the aligned priority_lower_bound reason", () => {
693731
const result = costResult({
694732
provider: "openrouter",

0 commit comments

Comments
 (0)