Repository Public
1<!-- source: https://docs.x.ai/developers/model-capabilities/images/editing (from https://docs.x.ai/llms-full.txt, retrieved 2026-09-19T05:28:55Z) -->2#### Model Capabilities34# Image Editing56Edit an existing image by providing a source image along with your prompt. The model understands the image content and applies your requested changes.78> [!WARNING]9>10> The OpenAI SDK's `images.edit()` method is not supported for image editing because it uses `multipart/form-data`, while the xAI API requires `application/json`. Use the xAI SDK, Vercel AI SDK, or direct HTTP requests instead.1112With the xAI SDK, use the same `sample()` method; just add the `image_url` parameter:1314```python customLanguage="pythonXAI"15import base6416import xai_sdk1718client = xai_sdk.Client()1920# Load image from file and encode as base6421with open("photo.png", "rb") as f:22 image_data = base64.b64encode(f.read()).decode("utf-8")2324response = client.image.sample(25 prompt="Render this as a pencil sketch with detailed shading",26 model="grok-imagine-image-2.0",27 image_url=f"data:image/png;base64,{image_data}",28)2930print(response.url)31```3233```bash34# Using a public URL as the source image35curl -X POST https://api.x.ai/v1/images/edits \36 -H "Content-Type: application/json" \37 -H "Authorization: Bearer $XAI_API_KEY" \38 -d '{39 "model": "grok-imagine-image-2.0",40 "prompt": "Render this as a pencil sketch with detailed shading",41 "image": {42 "url": "https://docs.x.ai/assets/api-examples/images/style-realistic.png",43 "type": "image_url"44 }45 }'46```4748```javascript customLanguage="javascriptAISDK"49import { xai } from "@ai-sdk/xai";50import { generateImage } from "ai";51import fs from "fs";5253// Load image and encode as base6454const imageBuffer = fs.readFileSync("photo.png");55const base64Image = imageBuffer.toString("base64");5657const { image } = await generateImage({58 model: xai.image("grok-imagine-image-2.0"),59 prompt: {60 text: "Render this as a pencil sketch with detailed shading",61 images: [`data:image/png;base64,${base64Image}`],62 },63});6465console.log(image.base64);66```6768You can provide the source image as:6970* A **public URL** pointing to an image71* A **base64-encoded data URI** (e.g., `data:image/jpeg;base64,...`)72* A **`file_id`** from the [Files API](/developers/files) — see [Imagine → Files API Integration](/developers/model-capabilities/imagine/files/inputs)7374## Multi-turn editing7576Chain 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.7778## Style transfer7980The `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.8182## Related8384* [Image Generation](/developers/model-capabilities/images/generation) — Generate images from text prompts85* [Multi-Image Editing](/developers/model-capabilities/images/multi-image-editing) — Edit with multiple source images86* [API Reference](/developers/rest-api-reference) — Full endpoint documentation87* [Imagine API Landing Page](https://x.ai/api/imagine) — Showcase of the Imagine API in action88