skillZs
★ LIVE SKILL TAGS ★
>>> LIVE SKILLS INDEX <<<
* OPEN SOURCE *
NO LOGIN, NO TRACKING
※ REAL INSTALL DATA ※
← back to all skills
thatjuan/agent-skills49 installs

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-api
view source ↗

Is 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

PathBest forNotes
xai_sdkPython, first-party featuresUse client.image.sample() and sample_batch().
RESTAny language, full controlSend JSON to /images/generations or /images/edits.
OpenAI SDKDrop-in image generationPoint base_url / baseURL at https://api.x.ai/v1.
Vercel AI SDKTypeScript apps already using AI SDKUse 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

  1. Choose generation vs editing:
    • New image: POST /v1/images/generations, client.image.sample(), or images.generate().
    • Edit image: POST /v1/images/edits, xAI SDK sample(image_url=...), or Vercel AI SDK provider options.
  2. Set model, prompt, and optional n, aspect_ratio, resolution, or output format.
  3. For image edits, pass a public image URL or a base64 data URI. Up to 5 input images are supported.
  4. Treat generated URLs as temporary. Download them promptly or request base64 output when embedding/saving directly.
  5. 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=...) or images.generate(..., n=...).
  • Different prompts in parallel: use xai_sdk.AsyncClient() with asyncio.gather().
  • Single-image edit: output aspect ratio follows the input image.
  • Multi-image edit: output aspect ratio follows the first input unless aspect_ratio is set.
  • Base64 output: xAI SDK uses image_format="base64"; OpenAI-compatible SDKs use response_format="b64_json".
  • Resolution values: 1k or 2k.
  • 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.

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>