Skip to content

[Go][Billing] Preserve stream usage on cross-protocol OpenAI chat conversions #297

Closed

Description

@LIghtJUNction

Trigger

Upstream QuantumNous/new-api merged #7389 on 2026-09-15 (610334dbd760f1c5199a09ae5f860f11451f4c56) after identifying that streaming requests converted from Gemini/Claude/Responses into OpenAI Chat Completions can lose upstream usage because the converted request does not ask for stream_options.include_usage.

Local evidence

Current Go main has the same gap:

  • apps/api-go/relay/channel/advancedcustom/adaptor.go converts Claude, Gemini, and Responses requests to OpenAI Chat but forwards the converted request without forcing StreamOptions.IncludeUsage for streaming requests.
  • apps/api-go/relay/channel/openai/adaptor.go already does this for Claude conversion, but Gemini conversion does not.

When the upstream supports stream options, the downstream protocol cannot carry the OpenAI stream_options request field itself. Missing usage can therefore degrade billing/usage correctness on cross-protocol streaming paths.

Required work

  • For cross-protocol conversions into OpenAI Chat, set stream_options.include_usage=true only when RelayInfo.SupportStreamOptions && RelayInfo.IsStream.
  • Preserve non-stream behavior and channels that do not support stream options.
  • Cover advanced-custom Claude/Gemini/Responses conversion plus the direct OpenAI-channel Gemini conversion with regression tests.
  • Do not alter request/response protocol semantics beyond requesting usage from the upstream.

Acceptance criteria

  • Streaming + supported upstream => converted OpenAI Chat request includes usage.
  • Non-stream or unsupported upstream => stream options remain unset.
  • Existing Go tests/build/static production gate remain green.
  • No performance/memory claim without measurement.

Upstream

QuantumNous/new-api#7389 / commit 610334dbd760f1c5199a09ae5f860f11451f4c56.

Activity

  1. added 2 commits that reference this issue on Sep 15, 2026
    5d0e091
    46e1ae9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions