codex-gpt-image

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Codex GPT Image

Codex GPT 图像工具

Use this skill to generate or edit images through Codex OAuth instead of the OpenAI API-key path. The bundled CLI reads the local Codex auth file and calls the Codex Images backend endpoints.
使用本Skill可通过Codex OAuth认证而非OpenAI API密钥路径生成或编辑图片。内置CLI会读取本地Codex认证文件并调用Codex Images后端接口。

When To Use

使用场景

  • The user asks to use
    gpt-image-2
    or GPT Image through Codex auth/subscription.
  • The current agent supports
    SKILL.md
    but does not have a native image tool.
  • The user explicitly does not want to use
    OPENAI_API_KEY
    .
  • The user wants the same local image workflow across Codex, Claude Code, OpenClaw, Hermes Agent, or similar agents.
Do not use this skill when the user wants the official OpenAI Images API, an OpenAI-compatible gateway, or API-key billing. This skill is deliberately Codex-OAuth-only.
  • 用户要求通过Codex认证/订阅使用
    gpt-image-2
    或GPT图像工具时
  • 当前Agent支持
    SKILL.md
    但无原生图像工具时
  • 用户明确表示不想使用
    OPENAI_API_KEY
  • 用户希望在Codex、Claude Code、OpenClaw、Hermes Agent或同类Agent中使用统一的本地图像工作流时
当用户需要官方OpenAI Images API、兼容OpenAI的网关或API密钥计费服务时,请勿使用本Skill。本Skill仅支持Codex OAuth认证。

Core Workflow

核心工作流

All CLI commands below assume the working directory is this skill folder. Otherwise, resolve the absolute path to
scripts/codex_gpt_image.py
from this
SKILL.md
.
  1. Check local Codex auth:
    bash
    python3 scripts/codex_gpt_image.py auth-status
  2. If Codex auth is missing, run the device-code login flow:
    bash
    python3 scripts/codex_gpt_image.py login --open-browser
    The CLI prints a browser URL and a short user code. The user must complete this step; never ask them to paste tokens.
  3. Generate an image with the user's actual prompt. Choose only the CLI flags required by the request, and do not reuse prompt wording from this skill.
  4. Edit or use reference images by passing one or more
    --image
    inputs. For edits, build the prompt from the user's requested changes and the invariants that must stay unchanged.
  5. Report the saved path(s), model, size, and whether Codex OAuth was used.
以下所有CLI命令均假设工作目录为当前Skill文件夹。否则,请从本
SKILL.md
所在路径解析
scripts/codex_gpt_image.py
的绝对路径。
  1. 检查本地Codex认证状态:
    bash
    python3 scripts/codex_gpt_image.py auth-status
  2. 若缺少Codex认证,请运行设备码登录流程:
    bash
    python3 scripts/codex_gpt_image.py login --open-browser
    CLI会打印浏览器URL和短用户码。用户必须完成此步骤;切勿要求用户粘贴令牌。
  3. 使用用户提供的实际提示词生成图片。仅选择请求所需的CLI参数,请勿复用本Skill中的提示词表述。
  4. 通过传入一个或多个
    --image
    参数来编辑或使用参考图片。编辑时,需结合用户要求的修改内容和必须保留的不变内容构建提示词。
  5. 报告图片保存路径、使用的模型、尺寸以及是否采用了Codex OAuth认证。

Defaults

默认配置

  • Auth file:
    ~/.codex/auth.json
  • Override auth file:
    CODEX_AUTH_FILE=/path/to/auth.json
  • Login fallback:
    login
    uses OpenAI Codex device-code auth and writes the same auth file
  • Login client id:
    --client-id
    ,
    CODEX_APP_SERVER_LOGIN_CLIENT_ID
    , then the public Codex default
  • Images base URL:
    https://chatgpt.com/backend-api/codex
  • Image model:
    gpt-image-2
  • Size:
    auto
  • Quality:
    auto
  • Background:
    auto
  • Moderation:
    auto
  • Output format:
    png
  • Output compression:
    100
    for
    jpeg
    and
    webp
For detailed parameter values, defaults, model-specific constraints, and CLI mapping, read
references/openai-images-api-parameters.md
.
  • 认证文件:
    ~/.codex/auth.json
  • 自定义认证文件:
    CODEX_AUTH_FILE=/path/to/auth.json
  • 登录备选方案:
    login
    命令使用OpenAI Codex设备码认证并写入相同的认证文件
  • 登录客户端ID:优先使用
    --client-id
    参数、
    CODEX_APP_SERVER_LOGIN_CLIENT_ID
    环境变量,其次为公开的Codex默认值
  • 图像基础URL:
    https://chatgpt.com/backend-api/codex
  • 图像模型:
    gpt-image-2
  • 尺寸:
    auto
  • 画质:
    auto
  • 背景:
    auto
  • 内容审核:
    auto
  • 输出格式:
    png
  • 输出压缩率:
    jpeg
    webp
    格式为
    100
如需了解详细参数值、默认配置、模型专属限制及CLI参数映射,请阅读
references/openai-images-api-parameters.md

Parameter Selection

参数选择

Prefer the official API defaults unless the user request requires a specific option. Read the reference before choosing explicit
model
,
size
,
quality
,
background
,
moderation
, or
output_format
values.
除非用户请求明确要求特定选项,否则优先使用官方API默认值。在选择
model
size
quality
background
moderation
output_format
的明确值前,请先查阅参考文档。

Prompting

提示词撰写

Keep prompts explicit and production-oriented:
  • State the intended asset type.
  • Quote any exact visible text.
  • Specify composition, background, style, and constraints.
  • For edits, repeat invariants: what must stay unchanged.
  • Avoid adding logos, watermarks, or extra text unless requested.
提示词需清晰明确、符合生产需求:
  • 说明目标素材类型
  • 引用所有需显示的精确文本
  • 指定构图、背景、风格及约束条件
  • 编辑时需重复强调必须保留的不变内容
  • 除非用户要求,否则请勿添加标识、水印或额外文本

Failure Handling

故障处理

  • Missing auth file: run
    codex_gpt_image.py login --open-browser
    , or ask the user to run
    codex login
    , then retry.
  • 401/403: the Codex OAuth token may be expired, the account may not have access, or the endpoint may reject the session. Ask the user to refresh Codex auth.
  • Network failures: retry once if the request is idempotent and the user accepts possible duplicate image generation.
  • Never print or paste tokens from
    ~/.codex/auth.json
    .
  • 缺少认证文件:运行
    codex_gpt_image.py login --open-browser
    ,或要求用户运行
    codex login
    后重试
  • 401/403错误:Codex OAuth令牌可能已过期、账户无访问权限或接口拒绝会话。请要求用户刷新Codex认证
  • 网络故障:若请求具备幂等性且用户接受可能重复生成图片,则重试一次
  • 切勿打印或粘贴
    ~/.codex/auth.json
    中的令牌

Implementation Notes

实现说明

The CLI sends Codex Images requests with:
  • generation endpoint:
    POST https://chatgpt.com/backend-api/codex/images/generations
  • edit endpoint:
    POST https://chatgpt.com/backend-api/codex/images/edits
  • auth:
    Authorization: Bearer <access token from ~/.codex/auth.json>
  • model:
    gpt-image-2
It parses the JSON Images response and writes returned base64 image payloads to local files.
CLI发送Codex Images请求的细节:
  • 生成接口:
    POST https://chatgpt.com/backend-api/codex/images/generations
  • 编辑接口:
    POST https://chatgpt.com/backend-api/codex/images/edits
  • 认证方式:
    Authorization: Bearer <从~/.codex/auth.json获取的访问令牌>
  • 使用模型:
    gpt-image-2
CLI会解析Images接口返回的JSON响应,并将返回的base64图像数据写入本地文件。