grok-imagine-api
xAI Grok Imagine API expertise for generating, editing, and refining images through xAI REST, xai_sdk, OpenAI-compatible SDKs, and Vercel AI SDK. Use when code calls `api.x.ai/v1/images/generations` or `api.x.ai/v1/images/edits`, imports `xai_sdk` or `@ai-sdk/xai`, points an OpenAI SDK at `https://api.x.ai/v1`, or mentions Grok Imagine, `grok-imagine-image`, `grok-imagine-image-quality`, `aspect_ratio`, image editing, image variations, base64 image output, or `sample_batch()`.
How do I install this agent skill?
npx skills add https://github.com/thatjuan/agent-skills --skill grok-imagine-apiIs this agent skill safe to install?
- Gen Agent Trust Hubpass
The skill provides comprehensive documentation and code examples for integrating with the xAI Grok Imagine API for image generation and editing. It follows standard practices for SDK usage and secret management, using placeholders for API keys. Security analysis found no malicious behaviors or hidden code.
- Socketpass
No alerts
- Snykpass
Risk: LOW · No issues
What does this agent skill do?
Grok Imagine API
Grok Imagine is xAI's image generation and editing API. It supports text-to-image, JSON-based image edits, multi-image edits, multi-turn refinement, batch variations, aspect-ratio control, 1k/2k resolution, URL output, and base64 output.
Use official xAI docs for exact current model availability and pricing when that matters. Do not recommend the deprecated grok-imagine-image-pro; migrate existing uses to grok-imagine-image-quality or the current documented Grok Imagine image model.
Quick start
Raw REST:
curl -X POST https://api.x.ai/v1/images/generations \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $XAI_API_KEY" \
-d '{
"model": "grok-imagine-image",
"prompt": "A collage of London landmarks in a stenciled street-art style"
}'
Python xAI SDK:
import xai_sdk
client = xai_sdk.Client()
response = client.image.sample(
model="grok-imagine-image",
prompt="A collage of London landmarks in a stenciled street-art style",
)
print(response.url)
OpenAI-compatible generation:
from openai import OpenAI
client = OpenAI(base_url="https://api.x.ai/v1", api_key="YOUR_API_KEY")
response = client.images.generate(
model="grok-imagine-image",
prompt="A collage of London landmarks in a stenciled street-art style",
)
print(response.data[0].url)
Integration choices
| Path | Best for | Notes |
|---|---|---|
xai_sdk | Python, first-party features | Use client.image.sample() and sample_batch(). |
| REST | Any language, full control | Send JSON to /images/generations or /images/edits. |
| OpenAI SDK | Drop-in image generation | Point base_url / baseURL at https://api.x.ai/v1. |
| Vercel AI SDK | TypeScript apps already using AI SDK | Use xai.image("grok-imagine-image") with generateImage(). |
The OpenAI SDK's images.edit() is not supported for Grok Imagine edits because it sends multipart/form-data; xAI image edits require application/json.
Core workflow
- Choose generation vs editing:
- New image:
POST /v1/images/generations,client.image.sample(), orimages.generate(). - Edit image:
POST /v1/images/edits, xAI SDKsample(image_url=...), or Vercel AI SDK provider options.
- New image:
- Set
model,prompt, and optionaln,aspect_ratio,resolution, or output format. - For image edits, pass a public image URL or a base64 data URI. Up to 5 input images are supported.
- Treat generated URLs as temporary. Download them promptly or request base64 output when embedding/saving directly.
- Check moderation metadata when using
xai_sdk; do not assume every request produces a usable image.
Common patterns
- Same prompt, multiple variants: use
sample_batch(..., n=...)orimages.generate(..., n=...). - Different prompts in parallel: use
xai_sdk.AsyncClient()withasyncio.gather(). - Single-image edit: output aspect ratio follows the input image.
- Multi-image edit: output aspect ratio follows the first input unless
aspect_ratiois set. - Base64 output: xAI SDK uses
image_format="base64"; OpenAI-compatible SDKs useresponse_format="b64_json". - Resolution values:
1kor2k. - Maximum images per request: 10.
Reference
See references/image-api.md for endpoint shapes, parameter names by SDK, editing payloads, aspect ratios, response handling, and troubleshooting.
How can the creator link this skill?
Add the canonical catalog link to the repository README so users can inspect current installs and available audits. The publishing guide covers the complete discovery path.
<a href="https://skillzs.dev/skills/thatjuan/agent-skills/grok-imagine-api">View grok-imagine-api on skillZs</a>