Repository navigation
Conversation
Preserve the last upstream usage object when emitting the synthesized completion chunk. OpenAI clients that price a turn from provider fields (for example cost/credits) otherwise lose them. Forward the trailing usage-only frame to clients that set stream_options.include_usage, including text-only rounds, and reset the remembered usage per stream round so a later round cannot inherit a previous cost. Adds five regression tests in tests/openai-usage-frame-forward.test.ts.
[bot] 🏷 Duplicate check: not a duplicate — same-family as #7084 (both edit the openai-adapter usage lines, but #7084 fixes usage-event all-zeros/loss; this PR fixes provider-field preservation) and as #4074 (same mechanism, different wire — #4074 is the anthropic side, already merged). This PR is the OpenAI increment of provider-field preservation. CI: 12 Headline finding — conflicts with open owner PR #7084. Both PRs edit the same two spots in What the PR does (verified against the diff):
Minor findings (non-blocking):
Code quality (external-strict ⑤b): passes — clear names ( Verdict: correct, well-scoped increment — but do not merge as-is: rebase onto master-with-#7084 first (the two changes combine cleanly), then re-review. Labels applied: 八问(中文, 供人工 reviewer):
收工判定: 代码正确、范围清晰、测试有牙, 但不可直接合并 —— 先 rebase 到含 #7084 的 master(两处改动可干净合并), rebase 后复审再合。 |
[bot] 🏷 CI update: all 30 checks now complete — 13 passed, 17 skipped (gated e2e lanes), 0 failed. The PR is mergeable (no conflict with master). The headline finding stands: it will conflict with open owner PR #7084 on the same two lines (finishReason usage branch + emitCompletion), so rebase onto master-with-#7084 before merge. |
|
merged by #7445 |
Preserve the last upstream usage object when emitting the synthesized completion chunk. OpenAI clients that price a turn from provider fields (for example cost/credits) otherwise lose them.
Forward the trailing usage-only frame to clients that set stream_options.include_usage, including text-only rounds, and reset the remembered usage per stream round so a later round cannot inherit a previous cost.
Adds five regression tests in tests/openai-usage-frame-forward.test.ts.
A shared rawUsage on the usage event and EmitCompletionOpts, accumulated like terminalExtra (#1766), would give all four wires the same guarantee. This PR is the OpenAI increment.
Thanks for your consideration.
M