图片
图像编辑和参考图
为图片模型提供参考图片:编辑照片、将产品放入新场景、让角色在不同镜头中保持一致,或将多张图片合成为一张。
两种图片传入方式
两种方式支持的模型、尺寸和价格均与图片生成相同。编辑图片与生成同尺寸新图片的费用相同。
各模型支持的参考图片数量
使用 OpenAI SDK
main.py
import osfrom openai import OpenAIclient = OpenAI(base_url="https://api.zurelay.com/v1", api_key=os.environ["ZURELAY_API_KEY"])result = client.images.edit( model="gpt-image-2", image=[open("product.png", "rb"), open("background.jpg", "rb")], prompt="Put the bottle from the first image on the marble counter in the second. Keep its label exactly.",)print(result.data[0].url)使用 JSON
无论使用哪个端点,都可以在 images 中以链接或 data URL 的形式列出图片(只有一张图片时,也可以用 image):
main.py
import osimport requestsresponse = requests.post( "https://api.zurelay.com/v1/images/generations", headers={"Authorization": f"Bearer {os.environ['ZURELAY_API_KEY']}"}, json={ "model": "nano-banana-pro", "prompt": "Make the jacket in the first image deep green, and give the model the pose from the second.", "images": [ "https://example.com/model.jpg", "data:image/png;base64,iVBORw0KGgo..." ], "size": "2K", "aspect_ratio": "4:5" },)response.raise_for_status()print(response.json())输入图片规则
- PNG、JPEG 或 WebP,每张最大 20 MB。
- 链接必须是可公开访问的
httpsURL;我们会自行下载图片。如果下载失败,会在生成任何内容之前返回invalid_image并拒绝请求。 - 在提示词中按顺序引用图片:“第一张图片”、“第二张图片”。
- 不支持蒙版。请直接描述要做的修改(“只替换天空”);这些模型只会修改你指定的内容。
- 超出模型限制时,请求会被拒绝,并返回明确说明限制的错误。
试试这些用法
有疑问,或发现内容缺失?联系我们的支持团队,我们会通过邮件回复,通常只需一分钟。