# Grok Imagine API Complete API reference for Grok Imagine image generation models by xAI. ## Model Variants This API supports two model variants: | Model | ID | Description | |-------|-----|-------------| | **Grok Imagine** | `grok-imagine` | Text-to-image generation | | **Grok Imagine Edit** | `grok-imagine-edit` | Instruction-based image editing | ## Quick Comparison | Feature | Grok Imagine | Grok Imagine Edit | |---------|--------------|-------------------| | Input | Text prompt | Image + Text prompt | | Image Input | No | Required (`image_url_list`, 1-5 images) | ## Grok Imagine (Text-to-Image) ### Endpoint ``` POST /api/v1/image/task ``` ### Request Parameters #### Required | Parameter | Type | Description | |-----------|------|-------------| | `model_name` | string | Must be `"grok-imagine"` | | `prompt` | string | Image generation prompt | | `width` | number | Width ratio value (e.g., 16 for 16:9) | | `height` | number | Height ratio value (e.g., 9 for 16:9) | ### Example Request ```javascript 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; // Poll for results 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 (Image Editing) ### Request Parameters #### Required | Parameter | Type | Description | |-----------|------|-------------| | `model_name` | string | Must be `"grok-imagine-edit"` | | `prompt` | string | Description of desired edits | | `width` | number | Width ratio value (defaults to `1` when using the default `1:1` ratio) | | `height` | number | Height ratio value (defaults to `1` when using the default `1:1` ratio) | | `image_url_list` | string[] | Array of input image URLs to edit (1-5 images) | ### Example Request ```javascript { 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' } ``` ## Response Format ### Initial Response ```json { "code": 0, "data": { "task_id": "{task_id}", "task_status": "submitted", "response_url": "https://api.flaq.ai/api/v1/image/{task_id}" }, "message": "success" } ``` ### Polling Response Poll `GET /api/v1/image/{task_id}` to check status: ```json { "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" } ``` ### Status Values - `submitted`: Task accepted - `processing`: Image generation in progress - `succeed`: Image generation completed - `failed`: Image generation failed ## Processing Time Typical processing time: 15-60 seconds. ## Best Practices 1. **Creative Prompts**: Grok Imagine responds well to imaginative, detailed descriptions 2. **Edit Specificity**: For editing, clearly describe what to change and what to preserve