Skip to content

feat: support sub2api async image tasks#41

Open
Wangnov wants to merge 5 commits into
mainfrom
codex/sub2api-async-images
Open

feat: support sub2api async image tasks#41
Wangnov wants to merge 5 commits into
mainfrom
codex/sub2api-async-images

Conversation

@Wangnov

@Wangnov Wangnov commented Jul 24, 2026

Copy link
Copy Markdown
Owner

结论与兼容边界

这次把“服务品牌预设”和“实际图片传输协议”拆成了两层,避免把产品名误当成兼容保证:

服务 当前兼容方式 本 PR
OpenAI 官方 标准同步 /v1/images/generations/v1/images/edits 保持现状,作为兼容基线
New API 通用 OpenAI-compatible 同步 Images 协议 增加 new-api 预设,但不伪装成专用 runtime adapter
sub2api 可走同步 Images,也可走其异步任务协议 新增显式 sub2api-async transport

sub2api 异步接口已按当前上游 Asynchronous Image Tasks 文档与源码核对:

  • POST /v1/images/generations/async
  • POST /v1/images/edits/async
  • GET /v1/images/tasks/{task_id}

实现

  • Provider 配置新增 presetimage_transport、轮询间隔与超时;旧配置默认继续使用 openai-sync
  • Rust core、Tauri App、Docker Web、静态 Web 均支持 sub2api 异步生成与编辑
  • 异步提交成功后持久化 task ID、poll URL 和状态;桌面 App / Docker Web 可用“继续获取结果”恢复原任务
  • 批量任务按槽位保存远端 task ID,进程退出后也不会因为元数据覆盖而误导用户重复生成
  • 前端新增 OpenAI 官方 / New API / sub2api / 自定义服务预设,以及独立的图片请求模式选择
  • 历史详情展示远端任务状态;停止本地等待时明确提示远端任务可能仍在运行
  • README、Provider reference 与任务恢复设计文档已同步更新

安全与计费语义

  • 异步 POST 不自动重试,避免“服务端已受理、响应丢失”时重复创建和计费
  • 只对轮询 GET 的网络错误、429 与 5xx 做 timeout-bound 重试
  • 服务端 Retry-After 和用户配置共同决定轮询间隔,用户配置始终是频率下限
  • poll URL 必须与 provider api_base 同源,Bearer token 不会发送到跨源地址
  • 远端恢复只轮询已保存的 task ID,不会静默重新提交缺失槽位

验证

  • cargo test --workspace:core 154 passed / 1 ignored(需真实 R2 凭证),App 9、runtime 7、Web 7
  • cargo clippy --workspace --all-targets -- -D warnings
  • cargo fmt --all -- --check
  • git diff --check
  • 前端 npm test:16 files / 101 tests
  • 前端 npm run typecheck
  • 前端 npm run build
  • 浏览器 transport:20 tests
  • 1280×720 与 820×700 实际界面检查
  • 最终 codex review --uncommitted:未发现明确且可操作的正确性问题

截图

sub2api 异步凭证配置

sub2api 异步配置详情

使用限制

  • sub2api 服务端必须正确启用 image_storage
  • 停止 App / 浏览器的本地轮询不等于取消远端任务
  • 静态 Web 会保留 task ID,但刷新后的远端恢复仍应在桌面 App 或 Docker Web 中完成

CI

  • scripts/release/prepare.sh 在 GitHub Actions candidate job 通过
  • PR checks:candidatefrontendrelayplan 全部通过

Closes #40

@Wangnov
Wangnov marked this pull request as ready for review July 24, 2026 12:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: Adapt to sub2api gateway asynchronous image generation

1 participant