Model Capabilities
Image Editing
Edit an existing image by providing a source image along with your prompt. The model understands the image content and applies your requested changes.
With the xAI SDK, use the same sample() method; just add the image_url parameter:
import { xai } from "@ai-sdk/xai";
import { generateImage } from "ai";
import fs from "fs";
// Load image and encode as base64
const imageBuffer = fs.readFileSync("photo.png");
const base64Image = imageBuffer.toString("base64");
const { image } = await generateImage({
model: xai.image("grok-imagine-image-2.0"),
prompt: {
text: "Render this as a pencil sketch with detailed shading",
images: [`data:image/png;base64,${base64Image}`],
},
});
console.log(image.base64);You can provide the source image as:
A public URL pointing to an image
A base64-encoded data URI (e.g.,
data:image/jpeg;base64,...)A
file_idfrom the Files API — see Imagine → Files API Integration
Multi-turn editing
Chain multiple edits together by using each output as the input for the next. This enables iterative refinement; start with a base image and progressively add details, adjust styles, or make corrections.



import xai_sdk
client = xai_sdk.Client()
response = client.image.sample(
prompt="A modern living room with large windows overlooking the city",
model="grok-imagine-image-2.0",
)
print(response.url)Style transfer
The grok-imagine-image-2.0 model supports a wide range of visual styles, from ultra-realistic photography to anime, oil paintings, and pencil sketches. Transform existing images by describing the desired aesthetic in your prompt.






import xai_sdk
client = xai_sdk.Client()
response = client.image.sample(
prompt="Render this image as an oil painting in the style of impressionism",
model="grok-imagine-image-2.0",
image_url="https://docs.x.ai/assets/api-examples/images/style-realistic.png",
)
print(response.url)Related
Image Generation — Generate images from text prompts
Multi-Image Editing — Edit with multiple source images
Image Prompting Guide — When to edit, and how to phrase an edit prompt
API Reference — Full endpoint documentation
Imagine API Landing Page — Showcase of the Imagine API in action
Last updated:October 8, 2026