Claude Opus 5.5 已在 SeedRouter 上线

在 Codex、Claude Code 等编程 Agent 中使用 GPT Image 2

让 Codex、Claude Code 或其他编程 Agent 通过你的 API Key 用 GPT Image 2 生成图片,附一段可复用、每次付费请求前都会先征求你同意的提示词。

以 Markdown 阅读

Codex 或 Claude Code 这类编程 Agent 可以直接调用 API 来生成 GPT Image 2 图片。把你的 API Key 放进环境变量,把下面的提示词交给 Agent,它就会构建请求、先给你看、在你批准后提交、轮询任务,并把图片保存到你的项目里。不需要任何插件:能运行 shell 命令或一段简短脚本的 Agent 都能调用这个 API。

SeedRouter 不提供 MCP 服务器或打包好的 skill。本指南里的提示词就是全部的接入方式。你可以在自己使用的任何 Agent 中把它保存为可复用的指令。

Agent 开始之前需要准备什么?

三样东西:

  1. 环境变量里的 API Key。 在 API Key 页面创建一个,并在 Agent 运行的 shell 中导出它。Agent 从那里读取 Key,绝不应该要求你把它粘贴出来。
  2. 网络访问。 Agent 要调用 https://api.seedrouter.ai,所以它的沙箱必须允许这个任务发出外部请求。
  3. 额度。 请求从你的余额中扣费,所以第一次运行前请先充值。
export SEEDROUTER_API_KEY="your-key"

应该给 Agent 什么提示词?

在任务开头粘贴这段提示词,然后填写方括号里的目标。它列出了 API 接受的确切字段,让 Agent 不会自己编造参数,并且让 Agent 在产生任何扣费之前停下来等你批准:

Use the SeedRouter API to generate a gpt-image-2 image for me.

Security: read SEEDROUTER_API_KEY from my local environment. Never ask me to paste it and never expose it in code, prompts, logs, or output.

Goal:
- Use case: [product / social / concept art / UI mockup]
- Subject and style: [subject, composition, lighting, style]
- Size: [auto | 1024x1024 | 1536x1024 | 1024x1536 | WIDTHxHEIGHT]
- Quality: [auto | low | medium | high]
- Number of images: [1-10]
- Acceptance criteria: [e.g. no text in the image, consistent product, clean background]

Request fields this endpoint accepts, and nothing else:
  model (required, "gpt-image-2"), prompt (required, up to 32000 chars),
  n (1-10, default 1), size (default auto; a custom WIDTHxHEIGHT must have
  both sides divisible by 16, neither edge over 3840, total pixels between
  655360 and 8294400, and keep a ratio between
  1:3 and 3:1), quality (auto|low|medium|high, default auto),
  background (auto|opaque|transparent, default auto; transparent requires
  output_format png), output_format (png|jpeg, default png),
  output_compression (0-100, default 100, jpeg only),
  moderation (auto|low, default auto), user (your own identifier).
For editing use /v1/images/generations with images: [{image_url: "https://..."}]
(up to 16) and optional mask: {image_url: "https://..."}. Mask requires images.
Inputs must be URLs, not base64 or multipart files. stream and partial_images
are not supported because delivery is asynchronous.

Before any paid request, show me the model id, the exact request body and the
estimated cost, then wait for my explicit approval.

After approval:
1. POST https://api.seedrouter.ai/v1/images/generations with the body above and
   an Authorization: Bearer $SEEDROUTER_API_KEY header.
2. Save the task id from the response "id" field. The response is
   {"id": "...", "status": "processing"} — the image is not in it.
3. Poll https://api.seedrouter.ai/v1/tasks/{task_id} with the same header every
   5-10 seconds until status is "completed" or "failed". Do not retry forever;
   if you stop waiting, preserve the task id and report that it is still pending.
   A polling timeout is not a failed task. Never submit a duplicate just to check status.
4. On success, download every URL in output.data[].url, return the local paths,
   the task id, and the parameters used. The response carries no cost field.
5. On failure, keep the task id, explain the reason and what to change, and do
   not retry without my approval. A task that ends failed is not charged.

审批这一步最重要。会自行重试的 Agent 可能把同一个付费请求提交好几次。即使你已经信任这套配置,也要保留这条指令。

如何在 Codex 中使用?

在你的项目里打开 Codex,粘贴填好目标的提示词。要复用它,就把提示词加到项目的 AGENTS.md 中(这是 Codex 针对该仓库读取的指令文件),放在「Generating images」之类的标题下。之后只要说一句「为定价页做一张首屏主图」就够了,Codex 会按保存的步骤执行。

如果 Codex 运行在没有网络访问的沙箱里,就无法访问 API。请先为该会话开启网络访问,再让它生成图片。

如何在 Claude Code 中使用?

同样的提示词在 Claude Code 中也能用。要复用,可以把它保存到项目的 CLAUDE.md 中,或者做成一个 skill:一个包含 SKILL.md 文件的文件夹,其中的指令就是这段提示词。之后你要图片时,Claude Code 就会加载它。请确认在启动 Claude Code 的终端里已经导出了 SEEDROUTER_API_KEY。

一次良好的 Agent 运行是什么样的?

  1. 你描述想要的图片以及它要放在哪里。
  2. Agent 给出模型 ID、确切的请求体和预估费用,然后等待。
  3. 你批准。Agent 只提交一次,并报告任务 ID。
  4. 它轮询直到任务完成,把图片下载到项目中,并告诉你文件路径。

如果运行中途停止,任务 ID 依然有效。让 Agent 继续轮询那个 ID,而不是重新生成;第二次提交就是第二次扣费。以失败结束的任务不收费。

常见问题

SeedRouter 有 GPT Image 2 的 MCP 服务器或 skill 吗?

没有。API 本身就是接入方式,上面的提示词已经给了 Agent 调用它所需的一切。如果想复用,就在你自己的 Agent 里把提示词保存为 skill 或指令文件。

Agent 能编辑我项目里已有的图片吗?

能,前提是这些图片可以通过公开的 HTTPS URL 访问。API 以 URL 形式接收参考图和遮罩,不接收本地文件,所以请先上传,或者告诉 Agent 它们托管在哪里。

Agent 应该使用哪个模型?

gpt-image-2 每交付一张图收一个固定价;gpt-image-2-official 按每次出图报告的 token 付费。要切换,就替换提示词里的模型。当前价格见模型页。

让人始终参与决策

通过环境变量把 Key 交给 Agent,通过提示词告诉它字段,通过审批步骤把最终决定权留给你。这样组合起来,Codex 或 Claude Code 就能在你的项目里生成图片,而不会出现意外扣费。如果想扩展这段提示词,GPT Image 2 API 文档列出了每个字段。

相关指南