Repository navigation
fix(api): semantic-cache HIT bills incremental cost 0 + X-OmniRoute-Cost-Saved (PRD-2026-06-19) - #4308
Merged
Conversation
…ost-Saved (PRD-2026-06-19) On a semantic-cache HIT no upstream call is made, so the incremental cost of serving the hit is 0. X-OmniRoute-Response-Cost was reporting the original call's full cost (recomputed from the cached usage), making billing consumers that sum response-cost charge for hits that cost ~$0 to serve. Cache hits now emit X-OmniRoute-Response-Cost: 0.0000000000 and surface the avoided cost in a new X-OmniRoute-Cost-Saved header (mirrors the existing tokens_saved concept) for cache analytics. The MISS path is unchanged. - headers.ts: add costSaved constant - omnirouteResponseMeta.ts: builder/attach emit Cost-Saved when costSavedUsd passed - semanticCache.ts: HIT passes costUsd:0 + costSavedUsd:cachedCost - TDD: builder + checkSemanticCache regression (RED->GREEN) + per-key isolation guard - docs: API_REFERENCE + openapi document the header and cache-hit semantics
Contributor
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
diegosouzapw
added a commit
that referenced
this pull request
Jun 20, 2026
…s in pre-commit (#4318) * fix(quality): complexity gate varre bin/ + electron (6A.11, fake-green fix) ESLINT_ARGS passava só 'src open-sse', mas o config eslint.complexity.config.mjs e o complexity-baseline.json já documentavam o escopo src+open-sse+electron+bin. A edição do scan nunca tinha sido aplicada: o gate alegava cobrir bin/electron e nunca os varria (fake-green — uma god-function nova em bin/ passava verde). - exporta ESLINT_ARGS + adiciona 'electron' e 'bin' (casa o config) - teste de build trava o escopo do scan - baseline 1887->1888: electron+bin medem 0 (widening 0-custo); o +1 é drift pré-existente de src/open-sse da base a23d0d6 (#4308 et al.), não do widening * fix(quality): check:tracked-artifacts no pre-commit (6A.12) O gate estava no CI + pre-push, mas faltava no pre-commit — e o incidente do symlink (artefato de build trackeado) acontece no 'git add'. Fecha o buraco no ponto mais cedo.
tkgo11
pushed a commit
to tkgo11/OmniRoute
that referenced
this pull request
Sep 23, 2026
…ost-Saved (PRD-2026-06-19) (cheaper-inference#4308) Cache HITs now report Response-Cost 0 (incremental) and surface the avoided cost in X-OmniRoute-Cost-Saved. MISS path unchanged. TDD + per-key isolation guard.
tkgo11
pushed a commit
to tkgo11/OmniRoute
that referenced
this pull request
Sep 23, 2026
…s in pre-commit (cheaper-inference#4318) * fix(quality): complexity gate varre bin/ + electron (6A.11, fake-green fix) ESLINT_ARGS passava só 'src open-sse', mas o config eslint.complexity.config.mjs e o complexity-baseline.json já documentavam o escopo src+open-sse+electron+bin. A edição do scan nunca tinha sido aplicada: o gate alegava cobrir bin/electron e nunca os varria (fake-green — uma god-function nova em bin/ passava verde). - exporta ESLINT_ARGS + adiciona 'electron' e 'bin' (casa o config) - teste de build trava o escopo do scan - baseline 1887->1888: electron+bin medem 0 (widening 0-custo); o +1 é drift pré-existente de src/open-sse da base ecbbff1 (cheaper-inference#4308 et al.), não do widening * fix(quality): check:tracked-artifacts no pre-commit (6A.12) O gate estava no CI + pre-push, mas faltava no pre-commit — e o incidente do symlink (artefato de build trackeado) acontece no 'git add'. Fecha o buraco no ponto mais cedo.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements PRD-2026-06-19-cache-hit-cost-reporting (Option A).
Problem
On a semantic-cache HIT the gateway serves the stored response without an upstream call (incremental cost ≈ $0), but
X-OmniRoute-Response-Costreported the original call's full cost (recomputed from the cachedusage). A consumer summingresponse-costfor billing was charging for hits that cost ≈$0 to serve (and stale entries inflated it).Fix (Option A — separate incremental vs. saved cost)
X-OmniRoute-Response-Cost: 0.0000000000(real incremental cost).X-OmniRoute-Cost-Saved= the original/would-have-been cost (mirrors the existingtokens_savedconcept) for cache analytics. Emitted only on cache hits.Changes
src/shared/constants/headers.ts— addcostSaved→X-OmniRoute-Cost-Saved.src/domain/omnirouteResponseMeta.ts— builder/attachOmniRouteMetaHeadersemitCost-Savedonly whencostSavedUsdis passed (additive; non-cache responses unchanged).open-sse/handlers/chatCore/semanticCache.ts— HIT passescostUsd: 0+costSavedUsd: cachedCost.API_REFERENCE.md+openapi.yamldocument the header + cache-hit cost semantics.Tests (Hard Rule #18 — TDD, RED→GREEN)
tests/unit/omniroute-response-meta.test.ts— builder emitsCost-SavedwhencostSavedUsdprovided, omits otherwise; HITResponse-Cost= 0.tests/unit/chatcore-semantic-cache.test.ts—checkSemanticCacheHIT ⇒Response-Cost: 0.0000000000+Cost-Saved= original cost (computed via the samecalculateCost, gpt-4o, deterministic). RED on the unfixed code.#3740edge from the PRD): key A's cached entry is not visible to key B.Acceptance criteria
temperature:0prompt → 1st (MISS) real cost; 2nd (HIT)Response-Cost: 0+Cost-Saved= original.Cost-Savedavailable for cache analytics.Closes the PRD (no GitHub issue).