BobSong-dev opened a new issue, #7955:
URL: https://github.com/apache/shenyu/issues/7955

   ## Background
   P1-11 metering integration gap in the mentor-approved OSPP plan; parent 
#7949. A shared per-attempt usage contract is needed for auditing, the existing 
cost-ledger proposal and subsequent budgets. This issue does not own a second 
cost ledger.
   
   ## Existing ownership and reuse
   - #7934 owns the usage ledger, versioned prices/currency/effective time, 
historical estimated costs and export. Reuse its event contract; do not 
duplicate storage/pricing/export here.
   - #7911 and open PR #7937 own the concrete OpenAI Responses output-token 
bug. Consume that fix rather than implementing it again.
   - #7702 / open PR #7848 own reservation/reconciliation; metering must not 
introduce another debit/settlement chain.
   - Reuse AI Proxy protocol adapters, bounded response observers/parsers and 
terminal events. Master `87c22dde7` still reads completion_tokens in 
AiTokenLimiterPlugin. Coordinate client-vs-target protocol attribution with 
#7871; retain existing native AI Proxy and applicable Spring AI paths, not a 
new provider stack.
   
   ## Implementation scope
   - Inventory actual routed provider/protocol combinations first. Define one 
shared normalized per-upstream-attempt observation, identifying logical 
request/attempt, trusted identity, actual provider/model where known, protocol, 
outcome and usage source.
   - Cover existing OpenAI Chat/Responses traffic first; verify 
Anthropic/Gemini only through actually supported routes, adding extraction 
adapters rather than inventing protocol support. Publish an explicit 
supported/unsupported coverage matrix.
   - Observe before lossy protocol conversion when needed; handle JSON and 
fragmented SSE, cumulative versus incremental usage, input/output and supported 
cached-token categories without double counting.
   - Keep reported zero, unavailable, estimated and provider-reported values 
distinct. Aggregate attempts into logical totals without losing retry/fallback 
costs. Feed the same authoritative measurements to audit, #7934 and budgeting.
   
   ## Non-goals
   Reimplementing #7911, a second ledger/pricing engine, new AI providers or 
retry/fallback policy, or treating estimates as provider invoices. Cost 
acceptance remains jointly tracked through #7934.
   
   ## Acceptance criteria
   - [ ] One documented usage contract/collection path is shared by consumers; 
repeated terminal events cannot double count an attempt.
   - [ ] Supported provider/protocol fixtures cover input/output/cache 
categories and cumulative/incremental semantics; unsupported/missing usage is 
explicit, never fabricated zero.
   - [ ] Native and converted output, streaming and buffered paths preserve 
response bytes and backpressure with bounded capture.
   - [ ] Retry/fallback logical totals reconcile with independent attempt 
records and #7934 price inputs; no extra budget debit occurs.
   - [ ] P1-11 is only complete when both this metering coverage and #7934 
versioned estimated-cost acceptance are satisfied.
   
   ## Tests
   Actual AI Proxy conversion output (including #7937 regressions), 
chunk/flush-boundary and malformed/oversized stream fixtures; provider-specific 
JSON/SSE cases; failure/cancel/unknown/zero usage; concurrent tenant isolation 
and repeated observation; cross-consumer reconciliation fixture. Reuse the 
existing parser regression suite.
   
   ## Dependencies
   P0-03, P1-05 and P1-06. Coordinate #7934 schema before implementation; 
incorporate #7911/#7937 and account for #7848 integration. No duplicate 
ownership of those tasks is implied.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to