From a5023e474ec06026b349bacc55e1db5a9b9fe96b Mon Sep 17 00:00:00 2001 From: Hermes Date: Wed, 18 Nov 2026 14:19:05 +0000 Subject: [PATCH] review: Gesamtkosten auch im allgemeinen Cost-Header MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Eine gestreamte Review-Antwort trägt die Summe im junction-Objekt; eine nicht gestreamte hatte sie nur in X-Junction-Review-Cost-Usd. Jetzt steht dieselbe Summe zusätzlich in X-Junction-Cost-Usd, damit ein Client, der nur den allgemeinen Kosten-Header kennt, nicht den Review-Sonderfall behandeln muss. Test: usage-review mit drei Calls -> X-Junction-Cost-Usd: 0.005400. Tests: 525 OK, 0 FAIL. --- README.md | 4 +++- src/junction.c | 3 +++ tests/review.sh | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1f09847..c7d8408 100644 --- a/README.md +++ b/README.md @@ -561,7 +561,9 @@ row: it describes the subscription (zero token price, budget/requests) rather th the pay-as-you-go list price. A non-streaming response carries `X-Junction-Tokens-In`, `X-Junction-Tokens-Out` -and, when the price is known, `X-Junction-Cost-Usd`. An unpriced model keeps +and, when the price is known, `X-Junction-Cost-Usd`. A reviewed answer puts the +sum over the worker and all rounds in both `X-Junction-Review-Cost-Usd` and the +general `X-Junction-Cost-Usd`, so one header is enough. An unpriced model keeps `unknown`; without any price table the headers are not invented. A cache hit is a call that cost nothing: it reports cost `0.000000` and zero tokens even though the cached body still contains the provider's original usage. The spend log and diff --git a/src/junction.c b/src/junction.c index 4c8e5d3..71f13c3 100644 --- a/src/junction.c +++ b/src/junction.c @@ -3636,6 +3636,9 @@ static int review_serve(j_conn *client, j_endpoint *ep, const j_req *rq, if (rev.cost_known) { snprintf(v, sizeof v, "%.6f", rev.cost); j_hdrs_set(&h, "X-Junction-Review-Cost-Usd", v); + /* The same total in the general per-call header: a client that + * knows one cost header should not have to special-case review. */ + j_hdrs_set(&h, "X-Junction-Cost-Usd", v); } } add_route_meta_headers(&h); diff --git a/tests/review.sh b/tests/review.sh index 4256c82..e208684 100644 --- a/tests/review.sh +++ b/tests/review.sh @@ -301,6 +301,7 @@ UH=$(tr -d '\r' < "$TMP/review_usage_h.txt") contains "$UH" "X-Junction-Review-Tokens-In: 3600" "the header carries the summed input tokens" contains "$UH" "X-Junction-Review-Tokens-Out: 900" "the header carries the summed output tokens" contains "$UH" "X-Junction-Review-Cost-Usd: 0.005400" "the header carries the summed cost" +contains "$UH" "X-Junction-Cost-Usd: 0.005400" "the general cost header carries the review total too" contains "$UH" "X-Junction-Ms: " "the request time covers the whole review" # Streaming: derselbe Block steckt im finalen SSE-Chunk, nicht nur im JSON-Pfad.