1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
const axios = require('axios');
const fs = require('fs');
const path = require('path');
async function toB64(imgPath) {
const data = fs.readFileSync(path.resolve(imgPath));
return Buffer.from(data).toString('base64');
}
const api_key = "YOUR API-KEY";
const url = "https://api.segmind.com/v1/grok-imagine-image-2";
const data = {
"prompt": "A cozy ramen shop on a narrow Tokyo alley at night in the rain, glowing red and blue neon signs reflecting on the wet pavement, steam rising from a fresh bowl of ramen on a wooden counter, warm lantern light spilling from the doorway, a lone customer seated inside, cinematic street photography, ultra-detailed, sharp focus, shallow depth of field, 35mm",
"quality": "medium",
"image_urls": "toB64('undefined')",
"aspect_ratio": "16:9",
"resolution": "1k",
"n": 1,
"output_format": "png"
};
(async function() {
try {
const response = await axios.post(url, data, { headers: { 'x-api-key': api_key } });
console.log(response.data);
} catch (error) {
console.error('Error:', error.response.data);
}
})();Text prompt for the image or edit to apply. Write like a design brief with exact quoted text.
Rendering effort: low is faster, medium maximizes fidelity and in-image text. Use medium for final renders.
Allowed values:
Optional source images to edit, up to 3 (extras ignored); switches to editing mode. Omit for text-to-image.
Output aspect ratio, ignored when an input image sets size. Use 16:9 landscape, 9:16 social, 1:1 square.
Allowed values:
Output resolution, 1k or 2k. Use 1k for fast drafts, 2k for detailed final renders.
Allowed values:
Number of images per request, 1 to 4. Use 2-3 to compare variations, 1 when dialed in.
min : 1,
max : 4
Output file format. Use jpeg for small files, png for lossless, webp for a balance.
Allowed values:
To keep track of your credit usage, you can inspect the response headers of each API call. The x-remaining-credits property will indicate the number of remaining credits in your account. Ensure you monitor this value to avoid any disruptions in your API usage.
Grok Imagine Image 2 is xAI's second-generation image model for text-to-image generation and instruction-based image editing. Built around the goal of making images you can use in real work, it follows prompts closely, plans typography and layout the way a designer would, and preserves the elements you supply across generations and edits. It powers the Quality Mode experience in Grok and is available on Segmind through a single synchronous endpoint that returns your image directly — no polling.
The model was tuned for fidelity across photography, design, and illustration, with editing treated as a first-class capability rather than an add-on. At launch it ranked second in the world on both the text-to-image and image-editing Arena leaderboards, a clear jump over xAI's previous image model.
Grok Imagine Image 2 shines on production-oriented visuals: marketing posters, e-commerce product shots, editorial graphics, infographics, menus, packaging concepts, app icons, game assets, and professional headshots. Because editing is first-class, it fits iterative workflows where you generate a hero image, then refine a region, swap a color, or lift a subject onto a clean background without touching the rest of the frame. Multi-reference input makes it a strong pick for consistent characters, locations, and props across a visual set.
Write prompts like a design brief: name the subject, the layout, the exact on-image words in quotes, the style, and the lighting, in that order. Put text you want rendered inside quotation marks and say where it sits. Use medium quality and 2k resolution for final assets, and 1k for fast drafts. For edits, describe one scoped change at a time and name what each reference image contributes.
Is Grok Imagine Image 2 good at rendering text? Yes. Text is one of its strongest suits — it plans typography and layout so posters, infographics, and small labels come out legible when you spell words in quotes.
Can it edit an existing image? Yes. Supply source images and describe the change in natural language; the model applies scoped edits while preserving what you provide. It accepts up to 3 reference images per request.
How does it compare to GPT Image 2? On the August 2026 Arena leaderboards, Grok Imagine Image 2 ranks second in both text-to-image and image editing, behind OpenAI's gpt-image-2.
What resolutions and formats are supported? Output is available at 1k or 2k resolution in jpeg, png, or webp, with low or medium quality tiers and up to 4 images per request.
Does it support multiple reference images? Yes. You can combine several reference images in one generation to control subject, style, and scene simultaneously.
Is it a video model? No. Grok Imagine Image 2 is an image generation and editing model, distinct from xAI's Grok Imagine video models.