图片
Grok Imagine Image
xAI 的 Grok Imagine Image 2.0: 支持以 1K 或 2K 生成八种比例的图片,编辑时最多可合并 3 张图片。
价格
每张图片 1K $0.045, 2K $0.06,使用 xAI 的中等画质生成。编辑与新图生成价格相同;传入的图片不额外收费。
生成图片
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.generate( model="grok-imagine-image-2.0", prompt="A poster for a mountain trail race: a runner on a ridge at sunrise, the words 'SUMMIT 50K' in bold condensed letters across the top", size="2K", extra_body={ "aspect_ratio": "2:3" },)print(result.data[0].url)参数
sizestring1K(默认) 或2K。aspect_ratiostring1:1,2:3,3:2,3:4,4:3,9:16,16:9或21:9。未指定时,新图默认为正方形;编辑时保留传入图片的比例。imagesarray- 最多传入 3 张图片进行编辑或合并,支持链接或 data URL (也可通过
/v1/images/edits上传文件)。 ninteger- 1 到 4 张图片。
尺寸遵循 xAI 的定义: 1K 约为一百万像素 (正方形为 1024 × 1024,16:9 为 1280 × 720),2K 约为四百万像素。如果返回图片的比例或分辨率不符,会自动重试,不会交付该图片。
编辑与合并
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": "grok-imagine-image-2.0", "prompt": "Put the woman from the first image in front of the bakery from the third, holding the bottle from the second.", "images": [ "https://example.com/woman.jpg", "https://example.com/bottle.jpg", "https://example.com/bakery.jpg" ] },)response.raise_for_status()print(response.json())提示词编写
- 用完整的句子描述主体、场景、光线和媒介。
- 把必须出现的文字放在引号中,并说明位置。
- 编辑时,明确要改什么、保留什么: “将毛衣改为深蓝色。其他全部保持不变。”。
使用须知
- 生成图片需要 15 到 75 秒。
- 不支持设置画质:所有图片均以中等画质生成,价格如上。
- 模型拒绝的提示词会返回
image_not_generated,不收费。 - 链接有效期为 24 小时;控制台的素材库会将以链接形式返回的图片保留 30 天。
模型详情和示例:Grok Imagine Image 2.0。关于如何发送图片,请参阅图片编辑与参考图。
有疑问,或发现内容缺失?联系我们的支持团队,我们会通过邮件回复,通常只需一分钟。