fix(api-service): make image-generation tools account-capability aware - #1964
Open
MartyAlien wants to merge 1 commit into
Open
fix(api-service): make image-generation tools account-capability aware#1964MartyAlien wants to merge 1 commit into
MartyAlien wants to merge 1 commit into
Conversation
Codex API 服务的账号池加入不支持图片生成的上游(如 Sub2api 等中转站)后,
网关默认会把 hosted image_generation 工具注入到普通文本请求中,导致上游对
整个请求返回 403 {"message":"Image generation is not enabled for this group"},
纯文本对话(/v1/responses、/v1/chat/completions 与内置对话测试)全部不可用
(fixes jlcodes99#1940,源自 jlcodes99#1176)。此前的错误提示还引导用户修改一个在 v1.3.4
已移除的设置项。
1. 精确认定:以 400/403/422 状态门 + 整包短语匹配(image_generation /
image generation + not enabled / not available / not allowed /
not supported / disabled)识别"上游无图片生成权限"错误,配额、鉴权、
模型等无关 403 不会被误分类。
2. 乐观学习:账号初始未知,首次文本请求仍注入生图工具;命中上述错误即把
该账号标记为不可生图(runtime-only、不落盘、不挂起模型,文本流量不受
影响),成功生图后自动清除标记。
3. 按账号注入:对已标记账号,文本请求不再注入 hosted 工具,并把客户端
声明 的生图工具与对应 tool_choice 一并剥除,纯文本正常转发(自动降级)。
4. 能力优先选号:显式生图请求(/v1/images/* 或 payload 声明生图工具)优先
路由到未标记不可生图的账号;全池不可生图时保持原顺序、由降级路径兜底。
5. 换号重试:生图权限 403 允许恰好一次立即重发以更换账号(sidecar 请求
无 previous_response_id 依赖;Rust legacy 在轮转前剥离
previous_response_id 防止上下文不匹配 404)。
6. 明确错误:显式图片接口命中不可生图账号时,本地直接返回 403
image_generation_not_enabled,不再透传中转站晦涩错误。
7. 降级可见:自动降级时响应头 x-agtools-image-degraded: 1
(HTTP / SSE / WebSocket 全覆盖)。
8. 文案修正:相关错误提示改为描述自动降级行为,不再指向已删除的设置。
- 混合"能生图 / 不能生图"的账号池零配置可用:纯文本对话不再因生图工具
声明被 403(重启后仅首次请求学习一次,之后全自动);
- 能生图账号完整保留"对话内模型自主生图"能力;
- 客户端显式生图请求自动流向有能力账号,全池不可用时体面降级;
- 显式图片接口对无能力账号返回本地明确错误。
改动范围:Go sidecar(executor / auth / helps / main)与 Rust legacy
(codex_local_access.rs),共 12 个文件,含双侧聚焦测试;无新增配置项、
无 UI 变更;手动请求头 x-agtools-disable-image-generation 语义保持不变
且始终优先。
MartyAlien
force-pushed
the
fix/image-generation-403-for-text-requests
branch
from
August 18, 2026 11:18
d352dc5 to
be3ef6c
Compare
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.
问题
账号池加入不支持图片生成的中转站账号(如 Sub2api)后,本地网关默认会把
image_generation工具注入到普通文本请求里。上游因为账号组没有生图权限,直接拒绝了整个请求:结果是
/v1/responses、/v1/chat/completions和内置对话测试全部不可用——哪怕消息只是纯文本。v1.3.4 已经移除了image_generation的禁用开关,但错误提示还在引导用户去改一个界面里不存在的设置(#1176 也提过这一点,本次一并修正了文案)。思路
与其像全局开关那样"一刀切"关掉生图(能生图的账号也会失去对话内生图的能力),不如让网关记住每个账号的生图能力,按账号下菜:
变更
x-agtools-image-degraded: 1告诉客户端;/v1/images/*或携带生图工具声明的请求,优先路由到能生图的账号;403 image_generation_not_enabled,不再透传中转站晦涩错误;覆盖 Go sidecar(executor / auth / helps / main)与 Rust legacy 网关两条链路,双侧对称,均带单元测试。无新增配置项、无 UI 变更;手动请求头
x-agtools-disable-image-generation的语义保持不变且始终优先。验证
go test ./internal/runtime/executor/... ./sdk/cliproxy/auth/... .:全部通过;cargo test --lib codex_local_access::tests(MSVC):237 通过 / 1 失败——失败项builds_upstream_websocket_url_from_custom_base_url读取本机全局代理配置,属环境性既有失败,与本改动无关;/v1/images/generations返回本地明确的 403。Fixes #1940