sub2api icon indicating copy to clipboard operation
sub2api copied to clipboard

OpenAI OAuth/Codex image_generation ignores explicit gpt-image-2 size/quality and returns gpt-image-2-codex auto/auto low-resolution output

Open jzhao20230918 opened this issue 5 months ago • 13 comments

Summary

When using OpenAI OAuth/Codex accounts through sub2api, explicit gpt-image-2 image generation requests with quality=high and a custom 4K-compatible size are accepted with HTTP 200, but the upstream lifecycle metadata changes the image tool to:

{
  "model": "gpt-image-2-codex",
  "quality": "auto",
  "size": "auto"
}

The actual returned PNG is low-resolution instead of the requested size.

This happens on both:

  • /v1/responses with an explicit image_generation tool
  • /v1/images/generations, which is bridged through Codex Responses for OAuth accounts

The main concern is silent downgrade: requests that clearly express native image intent can still route through OAuth/Codex and return downgraded images instead of preserving size/quality or failing fast.

Request Example

/v1/responses request shape:

{
  "model": "gpt-5.5",
  "instructions": "Generate the requested image.",
  "input": [
    {
      "role": "user",
      "content": "Create a simple vertical poster."
    }
  ],
  "tools": [
    {
      "type": "image_generation",
      "action": "generate",
      "model": "gpt-image-2",
      "quality": "high",
      "size": "2160x3040",
      "partial_images": 1
    }
  ],
  "tool_choice": {
    "type": "image_generation"
  },
  "stream": true,
  "store": false
}

Expected output: a 2160x3040 PNG, or a clear error saying the selected OAuth/Codex account cannot satisfy explicit high/custom-size image generation.

Observed lifecycle metadata:

{
  "type": "image_generation",
  "model": "gpt-image-2-codex",
  "quality": "auto",
  "size": "auto",
  "output_format": "png"
}

Observed actual PNG dimensions across repeated tests include:

  • 1024x1536
  • 1054x1492
  • 1058x1487
  • 1073x1466
  • 1254x1254
  • 1693x929

None matched the requested 2160x3040.

Images API Also Affected

/v1/images/generations request shape:

{
  "model": "gpt-image-2",
  "prompt": "Create a simple vertical poster.",
  "n": 1,
  "quality": "high",
  "size": "2160x3040",
  "response_format": "b64_json"
}

Observed response top-level metadata can also be:

{
  "model": "gpt-image-2-codex",
  "quality": "auto",
  "size": "auto"
}

The returned PNG is again not 2160x3040.

Why This Looks Like a Routing / Capability Issue

From the current source, the following seems relevant:

  • classifyOpenAIImagesCapability() marks explicit model/size/native options as OpenAIImagesCapabilityNative.
  • SupportsOpenAIImageCapability(OpenAIImagesCapabilityNative) currently returns true for both OAuth and APIKey accounts.
  • SelectAccountWithSchedulerForImages() falls back from native to basic if native selection fails.
  • ForwardImages() sends APIKey accounts to native OpenAI Images, but OAuth accounts to the Codex/Responses bridge.
  • OAuth /v1/images/generations is converted to a Codex Responses request with an explicit image_generation tool.

This means an explicit native-style image request like:

model=gpt-image-2
quality=high
size=2160x3040

can still be served by an OAuth/Codex account and silently downgraded by the Codex upstream.

Why This Is Risky

For production image workflows, HTTP 200 plus a base64 PNG is not enough.

The client may receive a valid PNG, but the actual image can be much smaller than requested. Billing/usage/request metadata can also be misleading unless the client parses lifecycle metadata and validates the real PNG dimensions.

In practice, clients must now verify all of these separately:

  • requested model/quality/size
  • upstream lifecycle model/quality/size
  • selected account type / source / executor
  • actual PNG dimensions

Related Issues / PRs

These look related, but do not appear to fully cover this silent size/quality downgrade case:

  • #3044 discusses OpenAI OAuth/Codex image generation organization/poid context and gpt-image-2-codex limits.
  • #3052 handles image 429 cooldown/failover, but does not appear to address explicit size/quality downgrades or org-context propagation.
  • #3158 / #3160 are about WS v2 passthrough skipping Codex image bridge injection. This seems related to tool availability, but the issue here happens even when the explicit image tool is already present and forwarded.
  • #3299 is about APIKey /responses tool-call probing, not OAuth/Codex image size/quality preservation.

Expected Behavior / Possible Fixes

Any of these would be safer than silent downgrade:

  1. For explicit images-native requests, require an APIKey/native-capable OpenAI account and do not treat OAuth/Codex as native-capable unless Codex can actually preserve requested size/quality.

  2. If OAuth/Codex is selected for explicit high/custom-size requests, fail fast when upstream lifecycle metadata comes back as gpt-image-2-codex + auto/auto.

  3. Add account capability probing for Codex image size/quality support, not just generic image-generation availability.

  4. Add an admin/group option such as strict_native_image_generation or require_exact_image_size to prevent production clients from receiving downgraded images with HTTP 200.

  5. Improve usage/admin logs to store:

  • requested size/quality
  • upstream lifecycle model/quality/size
  • account type
  • source/executor
  • actual PNG dimensions when available

Environment

  • sub2api version tested: v0.1.136
  • Account type: OpenAI OAuth/Codex only
  • No OpenAI APIKey/native account in the group
  • Endpoints affected:
    • /v1/responses
    • /v1/images/generations
  • Requested image model: gpt-image-2
  • Requested quality: high
  • Requested size: 2160x3040

2160x3040 should be valid under documented GPT Image 2 constraints:

  • each edge <= 3840
  • aspect ratio <= 3:1
  • total pixels < 8,294,400

Notes

The upstream gpt-image-2-codex string appears to come from Codex lifecycle metadata rather than from sub2api hardcoding.

The requested payload still contains gpt-image-2; sub2api then exposes or aggregates the upstream lifecycle response.tools[0].model/quality/size.

So the issue is not that the client sent gpt-image-2-codex. The client requested gpt-image-2, but the OAuth/Codex upstream returned gpt-image-2-codex / auto / auto.

jzhao20230918 avatar Jun 16 '26 08:06 jzhao20230918

问题概述

使用 sub2api 的 OpenAI OAuth/Codex 账号进行生图时,即使请求里已经显式指定:

model = gpt-image-2
quality = high
size = 2160x3040

请求仍会 HTTP 200 成功返回,但上游 lifecycle metadata 会把 image tool 改成:

{
  "model": "gpt-image-2-codex",
  "quality": "auto",
  "size": "auto"
}

最终返回的 PNG 实际分辨率也不是请求的 2160x3040,而是明显低分辨率图片。

这个现象同时发生在:

  • /v1/responses,显式传 image_generation tool
  • /v1/images/generations,OAuth 账号路径下会被桥接到 Codex Responses

核心问题是:一个明确表达了 native image intent 的请求,会静默落到 OAuth/Codex 路径并被上游降级,而不是保留 size/quality,或者在当前账号无法满足 high/custom-size 时 fail fast。

复现请求

/v1/responses 请求形态如下:

{
  "model": "gpt-5.5",
  "instructions": "Generate the requested image.",
  "input": [
    {
      "role": "user",
      "content": "Create a simple vertical poster."
    }
  ],
  "tools": [
    {
      "type": "image_generation",
      "action": "generate",
      "model": "gpt-image-2",
      "quality": "high",
      "size": "2160x3040",
      "partial_images": 1
    }
  ],
  "tool_choice": {
    "type": "image_generation"
  },
  "stream": true,
  "store": false
}

期望结果:

  • 返回真实 2160x3040 PNG
  • 或者明确报错:当前选中的 OAuth/Codex 账号无法满足显式 high/custom-size 生图请求

实际观察到的 lifecycle metadata:

{
  "type": "image_generation",
  "model": "gpt-image-2-codex",
  "quality": "auto",
  "size": "auto",
  "output_format": "png"
}

多次测试中实际 PNG 尺寸包括:

  • 1024x1536
  • 1054x1492
  • 1058x1487
  • 1073x1466
  • 1254x1254
  • 1693x929

都不是请求的 2160x3040。

Images API 也受影响

/v1/images/generations 请求形态如下:

{
  "model": "gpt-image-2",
  "prompt": "Create a simple vertical poster.",
  "n": 1,
  "quality": "high",
  "size": "2160x3040",
  "response_format": "b64_json"
}

观察到的 response 顶层 metadata 也可能变成:

{
  "model": "gpt-image-2-codex",
  "quality": "auto",
  "size": "auto"
}

返回的 PNG 同样不是 2160x3040。

为什么看起来像路由 / 账号能力判断问题

从当前源码看,下面几处逻辑可能相关:

  • classifyOpenAIImagesCapability() 会把显式 model/size/native options 标记为 OpenAIImagesCapabilityNative。
  • SupportsOpenAIImageCapability(OpenAIImagesCapabilityNative) 当前对 OAuth 和 APIKey 账号都会返回 true。
  • SelectAccountWithSchedulerForImages() 在 native selection 失败时还会 fallback 到 basic。
  • ForwardImages() 中,APIKey 账号会走 native OpenAI Images API,但 OAuth 账号会走 Codex/Responses bridge。
  • OAuth 账号下的 /v1/images/generations 会被转换成 Codex Responses 请求,并显式带 image_generation tool。

这意味着一个显式 native 风格的生图请求,例如:

model=gpt-image-2
quality=high
size=2160x3040

仍然可能被 OAuth/Codex 账号处理,并被 Codex upstream 静默降级。

风险

对于生产生图场景来说,HTTP 200 + base64 PNG 并不代表请求被正确满足。

客户端可能拿到一个合法 PNG,但实际图片尺寸远小于请求尺寸。仅看 usage、请求参数或是否返回 200,都可能误判成功。

目前客户端必须额外校验:

  • 请求里的 model/quality/size
  • 上游 lifecycle 里的 model/quality/size
  • 实际选中的 account type / source / executor
  • 实际 PNG dimensions

否则很容易把低分辨率图当成 high/custom-size 图使用。

相关 issue / PR

以下 issue/PR 看起来相关,但似乎没有完全覆盖这个“静默降级 size/quality”的问题:

  • #3044 讨论 OpenAI OAuth/Codex 生图的 organization/poid context,以及 gpt-image-2-codex limit 问题。
  • #3052 处理 image 429 cooldown/failover,但看起来没有解决显式 size/quality 降级,也没有解决 org-context 传递问题。
  • #3158 / #3160 讨论 WS v2 passthrough 跳过 Codex image bridge injection。这个更像 tool availability 问题;但这里的问题是在显式 image tool 已经存在并被转发时,仍然发生 size/quality 降级。
  • #3299 是 APIKey /responses tool-call probing 问题,不是 OAuth/Codex image size/quality 保留问题。

期望行为 / 可能修复方向

以下任意一种都比静默降级更安全:

  1. 对显式 images-native 请求,只允许 APIKey/native-capable OpenAI 账号处理;除非能确认 Codex 账号确实可以保留 requested size/quality,否则不要把 OAuth/Codex 视为 native-capable。

  2. 如果 OAuth/Codex 被选中处理显式 high/custom-size 请求,但 upstream lifecycle metadata 返回 gpt-image-2-codex + auto/auto,则 fail fast,而不是继续返回低分辨率 PNG。

  3. 增加 Codex image size/quality capability probing,不只探测“能不能生图”,还要探测是否能保留显式 size/quality。

  4. 增加 admin/group 级别配置,例如:

strict_native_image_generation
require_exact_image_size

用于防止生产客户端收到 HTTP 200 但实际被降级的图片。

  1. usage/admin logs 增加更多排查字段,例如:
  • requested size/quality
  • upstream lifecycle model/quality/size
  • account type
  • source/executor
  • actual PNG dimensions,如果可获得

环境

  • sub2api version: v0.1.136
  • Account type: OpenAI OAuth/Codex only
  • group 内没有 OpenAI APIKey/native account
  • 受影响 endpoint:
    • /v1/responses
    • /v1/images/generations
  • 请求 image model: gpt-image-2
  • 请求 quality: high
  • 请求 size: 2160x3040

2160x3040 符合 GPT Image 2 文档里的尺寸约束:

  • each edge <= 3840
  • aspect ratio <= 3:1
  • total pixels < 8,294,400

备注

gpt-image-2-codex 这个字符串看起来不是 client 传入的,也不是 sub2api 硬编码生成的,而是 Codex upstream lifecycle metadata 返回的。

client 请求里传的是 gpt-image-2。sub2api 后续只是暴露或聚合了上游 lifecycle 里的 response.tools[0].model/quality/size。

也就是说,问题不是 client 请求了 gpt-image-2-codex。client 请求的是 gpt-image-2,但 OAuth/Codex upstream 返回了 gpt-image-2-codex / auto / auto。

jzhao20230918 avatar Jun 16 '26 08:06 jzhao20230918

指定size没有起作用,生成的图片尺寸不稳定。

zhaozhenxiang avatar Jun 16 '26 09:06 zhaozhenxiang

这个现象不是一开始就有的。我们这边在 2026-06-15 及之前,同样的请求参数可以正常返回真实 2160x3040 PNG。

从 2026-06-16 开始,同样的请求参数没有变化,但返回结果发生了变化:

  • 请求仍然是 model=gpt-image-2
  • 请求仍然是 quality=high
  • 请求仍然是 size=2160x3040
  • 返回的 lifecycle metadata 变成了 gpt-image-2-codex / quality=auto / size=auto
  • 实际 PNG dimensions 也不再是 2160x3040,而是低分辨率结果,例如 1024x1536、1054x1492、1058x1487

所以补充这个信息主要是想说明:同样的请求在 2026-06-15 及之前是可以正常返回目标尺寸的,异常是从 2026-06-16 开始出现的。

jzhao20230918 avatar Jun 16 '26 09:06 jzhao20230918

这个现象不是一开始就有的。我们这边在 2026-06-15 及之前,同样的请求参数可以正常返回真实 2160x3040 PNG。

从 2026-06-16 开始,同样的请求参数没有变化,但返回结果发生了变化:

  • 请求仍然是 model=gpt-image-2
  • 请求仍然是 quality=high
  • 请求仍然是 size=2160x3040
  • 返回的 lifecycle metadata 变成了 gpt-image-2-codex / quality=auto / size=auto
  • 实际 PNG dimensions 也不再是 2160x3040,而是低分辨率结果,例如 1024x1536、1054x1492、1058x1487

所以补充这个信息主要是想说明:同样的请求在 2026-06-15 及之前是可以正常返回目标尺寸的,异常是从 2026-06-16 开始出现的。

现在已经拉闸了,都是1k了,指定size无效

linzeliang1222 avatar Jun 16 '26 10:06 linzeliang1222

我也有这个问题,末端会自动把quality,size设置为auto,导致传入的参数失效

cm2954275-creator avatar Jun 16 '26 10:06 cm2954275-creator

这个现象不是一开始就存在的。我们草莓在2026-06-15及之前,同样的请求参数可以正常返回真实的2160x3040PNG。

从 2026-06-16 开始,同样的请求参数没有变化,但返回结果发生了变化:

  • 请求仍然是model=gpt-image-2
  • 请求仍然是quality=high
  • 请求仍然是size=2160x3040
  • 返回的生命周期元数据变成了gpt-image-2-codex / quality=auto / size=auto
  • 实际上PNG尺寸也不再是2160x3040,而是低分辨率结果,例如1024x1536、1054x1492、1058x1487

所以补充这个信息主要是想说明:同样的请求在2026-06-15及之前是可以正常返回目标大小的,异常是从2026-06-16开始出现的。

我也是有同样的问题,15号及之前都是正常的返回目标大小,06-16开始出现返回 auto

JackGH88 avatar Jun 17 '26 04:06 JackGH88

这个现象不是一开始就有的。我们这边在 2026-06-15 及之前,同样的请求参数可以正常返回真实 2160x3040 PNG。 从 2026-06-16 开始,同样的请求参数没有变化,但返回结果发生了变化:

  • 请求仍然是 model=gpt-image-2
  • 请求仍然是 quality=high
  • 请求仍然是 size=2160x3040
  • 返回的 lifecycle metadata 变成了 gpt-image-2-codex / quality=auto / size=auto
  • 实际 PNG dimensions 也不再是 2160x3040,而是低分辨率结果,例如 1024x1536、1054x1492、1058x1487

所以补充这个信息主要是想说明:同样的请求在 2026-06-15 及之前是可以正常返回目标尺寸的,异常是从 2026-06-16 开始出现的。

现在已经拉闸了,都是1k了,指定size无效

那还能恢复么?有没有消息

kenstone2026 avatar Jun 24 '26 10:06 kenstone2026

现在有办法恢复么?

d1studio avatar Jun 29 '26 11:06 d1studio

什么原因,解决没有

Li13 avatar Jul 01 '26 08:07 Li13

在使用第三方中转站的时候 遇到了同样的问题,就猜到是sub2处理问题

mchudie avatar Jul 17 '26 09:07 mchudie

不是有一个提交解决了这个问题吗,支持4k生图,但是官方没有合并这个提交

fofiwo avatar Aug 21 '26 01:08 fofiwo

不是有一个提交解决了这个问题吗,支持4k生图,但是官方没有合并这个提交

哪个提交

kenstone2026 avatar Aug 24 '26 08:08 kenstone2026

在 HEAD (b8dece9, v0.2.13) 上核对,确认这是设计层面的问题,不是偶发:

  • Account.SupportsOpenAIImageCapability(internal/service/account.go)对 OAuth / SetupToken / APIKey 都返回 true,包含 OpenAIImagesCapabilityNative,并有测试 TestAccountSupportsOpenAIImageCapability_OAuthSupportsNative 明确断言该行为。
  • classifyOpenAIImagesCapability(internal/service/openai_images.go)在 ExplicitModel || ExplicitSize 等条件下返回 Native。
  • SelectAccountWithSchedulerForImages(internal/service/openai_account_scheduler.go)在 native 选不到时回退到 basic,于是 OAuth 账号会接管一个显式 native intent 的请求。
  • OAuth 路径最终走 Codex Responses 桥接。buildOpenAIImagesResponsesRequest 虽然把 size/quality/model 写进了 image_generation tool,但上游 lifecycle metadata 会把它改成 gpt-image-2-codex / auto / auto,本地无法据此纠正。

结论:OAuth/Codex 路径无法保证显式 size/quality。两个可能的修法方向:

  1. 让 OAuth/SetupToken 不再声称支持 Native(只保留 Basic),显式 native 请求只路由到 APIKey 账号,选不到就 fail fast;
  2. 或者在回退到 basic 时给出明确告警/错误,而不是静默降级。

这取决于产品意图("保证参数"还是"尽力而为"),需要维护者定夺,因此先把核实结果贴在这里。

hzh6767 avatar Oct 05 '26 03:10 hzh6767