Grok Imagine API
xAI 提供的 Grok Imagine 图像生成模型的完整 API 参考文档。
模型变体
此 API 支持两种模型变体:
快速对比
Grok Imagine(文本生成图像)
端点
POST /api/v1/image/task
请求参数
必需参数
请求示例
const response = await fetch('https://api.flaq.ai/api/v1/image/task', {
method: 'POST',
headers: {
'Authorization': 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({
model_name: 'grok-imagine',
prompt: 'A surreal landscape with floating islands and waterfalls',
width: 16,
height: 9
})
});
const { data } = await response.json();
const taskId = data.task_id;
const pollResponse = await fetch(
`https://api.flaq.ai/api/v1/image/${taskId}`,
{
headers: { 'Authorization': 'Bearer YOUR_API_KEY' }
}
);
const result = await pollResponse.json();
console.log(result.data.task_result.images[0].url);
Grok Imagine Edit(图像编辑)
请求参数
必需参数
请求示例
{
model_name: 'grok-imagine-edit',
width: 1,
height: 1,
image_url_list: ['https://example.com/photo.jpg'],
prompt: 'Change the sky to a dramatic sunset with orange and purple hues'
}
响应格式
初始响应
{
"code": 0,
"data": {
"task_id": "{task_id}",
"task_status": "submitted",
"response_url": "https://api.flaq.ai/api/v1/image/{task_id}"
},
"message": "success"
}
轮询响应
轮询 GET /api/v1/image/{task_id} 以检查状态:
{
"code": 0,
"data": {
"task_id": "{task_id}",
"task_status": "succeed",
"task_status_msg": null,
"response_url": "https://api.flaq.ai/api/v1/image/{task_id}",
"task_result": {
"credit": 0.0997,
"images": [
{
"url": "https://example.com/generated-image.jpeg"
}
]
}
},
"message": "success"
}
状态值
submitted:任务已接受
processing:图像生成进行中
succeed:图像生成完成
failed:图像生成失败
处理时间
典型处理时间:15-60 秒。
最佳实践
- 创意提示词:Grok Imagine 对富有想象力、详细的描述响应良好
- 编辑特异性:对于编辑,清楚地描述要更改的内容和要保留的内容