feat: improve Codex compatibility and OpenAI usage display#2979
Open
andywongz wants to merge 1 commit into
Open
feat: improve Codex compatibility and OpenAI usage display#2979andywongz wants to merge 1 commit into
andywongz wants to merge 1 commit into
Conversation
Contributor
|
Thank you for your contribution! Before we can merge this PR, we need you to sign our Contributor License Agreement (CLA). To sign, please reply with the following comment:
You only need to sign once — it will be valid for all your future contributions to this project. I have read the CLA Document and I hereby sign the CLA You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot. |
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.
English Description
This PR fixes two issues that can affect real user workflows.
The first issue is that some OpenAI-compatible Responses streaming outputs, such as Xiaomi MiMo and DeepSeek, cannot be consumed correctly by the latest Codex clients. The concrete symptom is that the client can send the request successfully, and the server does not return an error, but the client cannot receive the response message from the server.
Affected clients include Codex CLI, the VSCode Codex extension, and the Codex Windows client.
In this situation, the upstream model may have already returned a valid result, but the Codex client cannot correctly receive or display the assistant message.
The second issue is that the OpenAI OAuth usage display can mislead users. The 5h and 7d usage windows use different value semantics, but the current UI can easily make them look like they are interpreted in the same way. This can make users think that a large amount of quota has already been consumed, while in reality a large amount of quota may still be remaining.
Changes
Codex Responses stream compatibility
This PR adds an optional API-key-level compatibility switch:
codex_responses_stream_compatIt is located in the API key edit UI. When enabled, Sub2API normalizes OpenAI Responses SSE streams for Codex client compatibility.
This feature is disabled by default. In other words, unless an API key explicitly enables this option, existing users and existing OpenAI-compatible clients will not be affected.
OpenAI usage display
This PR updates the OpenAI OAuth usage windows so they are displayed consistently as remaining quota.
The 5h window value is displayed directly as the remaining percentage.
The 7d window value is treated as the used percentage and converted to remaining quota.
The color semantics are also updated: green means plenty of quota remains, amber means the remaining quota is low, and red means it is nearly exhausted.
Tests
Added frontend component tests covering both remaining-quota display modes.
Verified the production Docker build during deployment testing.
中文说明
这个 PR 修复了两个会实际影响用户使用的问题。
第一个问题是,当使用模型映射时,部分 OpenAI 兼容的 Responses (例如小米mimo、Deepseek)的流式输出无法被最新版的 Codex 客户端正确消费,具体的现象是能顺利发出消息,服务器也没有返回错误,但是无法收到服务器返回的消息。
受影响的客户端包括 Codex CLI、VSCode Codex 插件,以及 Codex Windows 客户端。
在这种情况下,上游模型可能已经正常返回了结果,但 Codex 客户端无法正确接收或展示助手消息。
第二个问题是,OpenAI OAuth 用量显示会误导用户。5h 和 7d 两个用量窗口的返回值语义并不一样,但当前界面容易把它们按同一种方式理解,从而让用户误以为额度已经大量消耗,实际情况却可能是额度仍然大量剩余。
修改内容
Codex Responses 流兼容
这个 PR 增加了一个 API Key 级别的可选兼容开关:
codex_responses_stream_compat它位于“API key”的编辑界面。开启后,Sub2API 会对 OpenAI Responses SSE 流做 Codex 客户端兼容标准化。
这个功能默认关闭。也就是说,除非某个 API Key 主动开启该选项,否则现有用户和现有 OpenAI 兼容客户端的行为不会改变。
OpenAI 用量显示
这个 PR 将 OpenAI OAuth 的用量窗口统一显示为剩余额度。
5h 窗口的返回值会直接作为剩余百分比显示。
7d 窗口的返回值会按已用百分比处理,并换算为剩余额度。
颜色语义也同步调整为:剩余额度多时显示绿色,剩余额度较低时显示黄色,接近耗尽时显示红色。
测试
增加了前端组件测试,覆盖两种剩余额度显示模式。
在部署测试中验证过生产 Docker 构建。