正在加载…

编辑图片

图生图

POST /v1/images/edits

本节不适用于 MidJourney(MJ),MJ 使用原生任务接口。文件上传使用 multipart/form-data;Grok / xAI 的 JSON 编辑方式见Grok 图像接口。至少提供一张图片;只有模型目录标记为支持图生图的模型才可调用。

参数类型必填说明
thinkingboolean / form string否是否开启思考,默认 false。仅 thinking_supported=true 的 ChatGPT 原生图片模型支持;开启后每张加收模型配置的 thinking_price 积分,不支持时返回 400。思考模式按模型公布的附加价格计费,不重复扣费。 JSON 传布尔值;multipart 表单传 thinking=true 或 thinking=false。
image / image[]file是multipart 文件;至少一张,多张图片可重复 image 或 image[] 字段。
modelstring是必须是模型目录标记为支持图生图的图片模型。
promptstring是描述编辑目标或参考关系。
ninteger否当前每次生成 1 张图片,n 默认 1;JSON 请求不接受其他数量。
sizestring否WIDTHxHEIGHT;以模型目录中的能力为准。
resolutionstring否可选分辨率档位;未声明时不要自行套用其他模型的尺寸表。
qualitystring否与文生图接口相同。
backgroundstring否与文生图相同;透明背景使用表单字段 background=transparent,JSON 编辑使用 "background": "transparent"。
response_formatstring否url 或 b64_json;URL 无需再次携带 API Key。
图生图POST /v1/images/edits · multipart
curl https://y.junlistudio.com/v1/images/edits \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -F model="gemini-nano-banana-2.1" \
  -F prompt="把这张图改成电影感光影" \
  -F image=@input.png \
  -F response_format=b64_json
# 多张参考图:重复 -F image=@reference.png
import base64
from openai import OpenAI

client = OpenAI(api_key="YOUR_API_KEY", base_url="https://y.junlistudio.com/v1")
result = client.images.edit(
    model="gemini-nano-banana-2.1",
    image=open("input.png", "rb"),
    prompt="把这张图改成电影感光影",
    response_format="b64_json",
)
with open("output.png", "wb") as output:
    output.write(base64.b64decode(result.data[0].b64_json))