GPT Image 2.6 图片生成与编辑 API

Posted April 25, 2026 by XSI 技术团队 ‐ 5 min read

gpt 5 5 gpt image 2 cover

GPT Image 2.6 提供 gpt-image-2.6-sunburst 和 gpt-image-2.6-flare:前者适合细节要求高的画面与精细编辑,后者适合快速迭代。本文使用非流式 Images API。

用途端点模型
生成图片POST /v1/images/generationsgpt-image-2.6-sunburst 或 gpt-image-2.6-flare
编辑图片、参考图生成POST /v1/images/edits两款 2.6 模型均可

SDK 的 Base URL 使用 https://api.xsirouter.com/v1,并设置你的 XSI API Key:

export XAI_API_KEY="你的 XSI API Key"

本次已通过本地模型映射、新参数透传、multipart 标注和实际 token 计费回归测试。2026 年 4–7 月的历史线上实测针对 GPT Image 2,不能作为 2.6 可用性或输出尺寸的证明;首次使用 2.6 时,请用小图确认账户权限和输出结果。

Images API:生成图片

这是最接近 OpenAI 官方 Images API 的写法。请求地址是 https://api.xsirouter.com/v1/images/generations,返回值包含 data[0].b64_json。

如果请求没有显式设置图片输出参数,请以响应中的 quality 和 output_format 元数据为准;为了避免不同部署的默认值差异,示例会显式传入 quality 和 output_format。只有在你选择 jpeg 或 webp 时,才建议按需传 output_compression。

cURL

curl -sS "https://api.xsirouter.com/v1/images/generations" \
  -H "Authorization: Bearer $XAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-image-2.6-sunburst",
    "prompt": "Generate a polished square portrait of a professional XSI female AI assistant in a bright futuristic control room. No text, no logos, no watermark.",
    "size": "1024x1024",
    "quality": "high",
    "output_format": "png"
  }' | jq -r '.data[0].b64_json' | base64 -d > xai-assistant.png

file xai-assistant.png

响应结构示意如下(token 数字仅为示例):

{
  "created": 1777573692,
  "data": [
    {
      "b64_json": "...",
      "revised_prompt": "..."
    }
  ],
  "output_format": "png",
  "quality": "high",
  "size": "1024x1024",
  "usage": {
    "input_tokens": 123,
    "output_tokens": 456,
    "total_tokens": 579,
    "input_tokens_details": {"text_tokens": 80, "image_tokens": 43},
    "output_tokens_details": {"image_tokens": 456}
  }
}

GPT Image 2.6 的 Images API 会直接在 data[].b64_json 中返回 base64 图片,因此不需要再传旧的 response_format。如果需要 URL,推荐在你的后端解码 base64 后上传到对象存储或 CDN,再把自有 URL 返回给前端。不同上游可能返回不同的附加元数据,客户端应把 data[].b64_json 作为稳定的图片字段。

Node.js

import fs from "node:fs";
import OpenAI from "openai";

const client = new OpenAI({
  apiKey: process.env.XAI_API_KEY,
  baseURL: "https://api.xsirouter.com/v1",
});

const result = await client.images.generate({
  model: "gpt-image-2.6-sunburst",
  prompt:
    "Generate a polished square portrait of a professional XSI female AI assistant in a bright futuristic control room. No text, no logos, no watermark.",
  size: "1024x1024",
  quality: "high",
  output_format: "png",
});

const imageBase64 = result.data[0].b64_json;
fs.writeFileSync("xai-assistant.png", Buffer.from(imageBase64, "base64"));

Python

import base64
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["XAI_API_KEY"],
    base_url="https://api.xsirouter.com/v1",
)

result = client.images.generate(
    model="gpt-image-2.6-sunburst",
    prompt="Generate a polished square portrait of a professional XSI female AI assistant in a bright futuristic control room. No text, no logos, no watermark.",
    size="1024x1024",
    quality="high",
    output_format="png",
)

with open("xai-assistant.png", "wb") as f:
    f.write(base64.b64decode(result.data[0].b64_json))

Images API:编辑图片

编辑接口使用 /v1/images/edits。OpenAI 官方 SDK 和 cURL 通常会发送 multipart/form-data,适合上传本地文件;XSI Router 会把输入图片交给 gpt-image-2.6-sunburst 做编辑或参考图生成。

使用 GPT Image 2.6 编辑图片时,省略 input_fidelity。

multipart 编辑发送一个 image 或重复的 image[],以及 prompt。输入使用 PNG、JPEG 或 WebP,可附加 mask 或 markup。让 SDK 或 curl 自动设置 multipart boundary;本文示例使用非流式响应,并省略旧的 response_format。

cURL 单图编辑

curl -sS "https://api.xsirouter.com/v1/images/edits" \
  -H "Authorization: Bearer $XAI_API_KEY" \
  -F "model=gpt-image-2.6-sunburst" \
  -F "[email protected]" \
  -F "prompt=Keep the same assistant identity and pose, but make the lighting brighter and add subtle floating interface panels. No text, no logos, no watermark." \
  -F "size=1024x1024" \
  -F "quality=high" \
  -F "output_format=png" \
  | jq -r '.data[0].b64_json' | base64 -d > xai-assistant-edited.png

cURL 多参考图

curl -sS "https://api.xsirouter.com/v1/images/edits" \
  -H "Authorization: Bearer $XAI_API_KEY" \
  -F "model=gpt-image-2.6-sunburst" \
  -F "image[][email protected]" \
  -F "image[][email protected]" \
  -F "prompt=Create a new XSI assistant portrait using the first image as identity reference and the second image as lighting and color reference. No text, no logos, no watermark." \
  -F "size=1024x1024" \
  -F "quality=high" \
  -F "output_format=png" \
  | jq -r '.data[0].b64_json' | base64 -d > xai-assistant-reference-edit.png

Node.js 编辑

import fs from "node:fs";
import OpenAI, { toFile } from "openai";

const client = new OpenAI({
  apiKey: process.env.XAI_API_KEY,
  baseURL: "https://api.xsirouter.com/v1",
});

const source = await toFile(fs.createReadStream("source.png"), "source.png", {
  type: "image/png",
});

const result = await client.images.edit({
  model: "gpt-image-2.6-sunburst",
  image: source,
  prompt:
    "Keep the same assistant identity and pose, but make the lighting brighter and add subtle floating interface panels. No text, no logos, no watermark.",
  size: "1024x1024",
  quality: "high",
  output_format: "png",
});

fs.writeFileSync(
  "xai-assistant-edited.png",
  Buffer.from(result.data[0].b64_json, "base64"),
);

Python 编辑

import base64
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["XAI_API_KEY"],
    base_url="https://api.xsirouter.com/v1",
)

with open("source.png", "rb") as image:
    result = client.images.edit(
        model="gpt-image-2.6-sunburst",
        image=image,
        prompt="Keep the same assistant identity and pose, but make the lighting brighter and add subtle floating interface panels. No text, no logos, no watermark.",
        size="1024x1024",
        quality="high",
        output_format="png",
    )

with open("xai-assistant-edited.png", "wb") as f:
    f.write(base64.b64decode(result.data[0].b64_json))

如果需要局部编辑,可以额外传 -F "[email protected]"。mask 应与第一张输入图尺寸一致并包含 alpha 通道,因此推荐使用 PNG;当前每次请求只允许一个 mask。提示词仍应明确说明要替换或保留的区域。

新参数与计费

quality 设置渲染质量,complexity 设置规划复杂度;后者支持 low、medium、high,默认 high。标注编辑可添加 -F "[email protected];type=image/png",标注图应与第一张输入图尺寸一致,提示词说明标注的含义。

生成接口还支持 SVG 与动画 GIF,格式限制、帧参数和计费范围见图片 API 参数指南。SVG 包含编写模型的额外费用,XSI 尚未单独适配和实测这部分费用。

默认价格表采用官方 token 单价,通过 Rates:7 换算为人民币。计费读取上游实际 usage,不会用 GPT Image 2 的旧尺寸表估算 2.6 token。单价相同不代表每张图的成本相同。

Responses API 状态

截至 2026-11-05,官方 Responses image_generation 模型列表尚未明确列出 2.6。将该工具切换为 2.6 前,需要先确认上游支持;本文示例直接调用 Images API。若需要文本模型理解需求或整理提示词,可以先完成文本调用,再由应用调用 Images API。

参考资料