Grok Imagine API
Referensi API lengkap untuk model pembuatan gambar Grok Imagine oleh xAI.
Varian Model
API ini mendukung dua varian model:
Perbandingan Cepat
Grok Imagine (Teks ke Gambar)
Endpoint
POST /api/v1/image/task
Parameter Permintaan
Wajib
Contoh Permintaan
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 (Pengeditan Gambar)
Parameter Permintaan
Wajib
Contoh Permintaan
{
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'
}
Respons Awal
{
"code": 0,
"data": {
"task_id": "{task_id}",
"task_status": "submitted",
"response_url": "https://api.flaq.ai/api/v1/image/{task_id}"
},
"message": "success"
}
Respons Polling
Poll GET /api/v1/image/{task_id} untuk memeriksa status:
{
"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"
}
Nilai Status
submitted: Tugas diterima
processing: Pembuatan gambar sedang berlangsung
succeed: Pembuatan gambar selesai
failed: Pembuatan gambar gagal
Waktu Pemrosesan
Waktu pemrosesan tipikal: 15-60 detik.
Praktik Terbaik
- Prompt Kreatif: Grok Imagine merespons dengan baik terhadap deskripsi yang imajinatif dan terperinci
- Spesifisitas Pengeditan: Untuk pengeditan, jelaskan secara jelas apa yang ingin diubah dan apa yang ingin dipertahankan