xAI Image Generator
by @mexicanamerican
Generate images from text prompts using xAI's Grok API with options for format, batch size, and automatic media attachment in OpenClaw.
clawhub install xai-image-genπ About This Skill
xai-image-gen
Generate images using xAI's Grok API (grok-imagine-image model).
Description
Production-ready CLI tool for generating images via xAI's image generation API. Supports multiple output formats, resolutions, and batch generation. Automatically outputs MEDIA: paths for OpenClaw auto-attachment.
Features:
xai-gen "" Installation
# Navigate to skills directory
cd ~/.openclaw/workspace/skillsClone or copy this skill
(or install via clawhub when published)
Install dependencies
pip3 install requestsEnsure the script is executable
chmod +x xai-image-gen/xai-gen
Set your xAI API key:
export XAI_API_KEY="your-api-key-here"
Add to your shell profile (~/.bashrc, ~/.zshrc) to persist:
echo 'export XAI_API_KEY="your-api-key-here"' >> ~/.bashrc
Usage
Basic Usage
# Generate with simple prompt
xai-gen "sunset over mountains"Custom filename
xai-gen "cyberpunk city" --filename city.pngGenerate multiple images
xai-gen "futuristic vehicle" --n 3Base64 output (no download)
xai-gen "logo design" --format b64Verbose mode
xai-gen "space station" --verbose
Options
positional arguments:
prompt Text description of the image to generateoptions:
-h, --help Show help message
--model MODEL Model name (default: grok-imagine-image)
--filename FILENAME Output filename (default: out.png)
--format {url,png,b64}
Response format: url (download), png (alias), b64 (base64)
--n N Number of images to generate (default: 1)
--verbose, -v Show detailed progress
Examples
Generate a meme:
xai-gen "dumbest trade meme: YOLO panic fail" --filename trade_meme.png
Batch generation:
xai-gen "logo variations for tech startup" --n 5
Outputs: out_1.png, out_2.png, out_3.png, out_4.png, out_5.png
High-quality artwork:
xai-gen "photorealistic portrait of a cat astronaut" --filename cat_astronaut.png
Integration with OpenClaw
The tool outputs MEDIA: /path/to/image.png which OpenClaw automatically detects and attaches to messages. Use in agent workflows:
# In an agent skill or automation
xai-gen "chart showing Q1 sales data" --filename sales_chart.png
β Image auto-attaches to response
API Details
https://api.x.ai/v1/images/generationsgrok-imagine-imageXAI_API_KEYError Handling
The tool handles common errors gracefully:
Requirements
requestsPlatform Compatibility
Troubleshooting
"XAI_API_KEY not found"
export XAI_API_KEY="xai-..."
"requests library not found"
pip3 install requests
Permission denied
chmod +x xai-gen
API errors
License
MIT License - Free to use and modify
Author
Built for OpenClaw by subagent xAI Image Gen Skill Builder
Version
1.0.0 - Initial release
π‘ Examples
Generate a meme:
xai-gen "dumbest trade meme: YOLO panic fail" --filename trade_meme.png
Batch generation:
xai-gen "logo variations for tech startup" --n 5
Outputs: out_1.png, out_2.png, out_3.png, out_4.png, out_5.png
High-quality artwork:
xai-gen "photorealistic portrait of a cat astronaut" --filename cat_astronaut.png
Integration with OpenClaw
The tool outputs MEDIA: /path/to/image.png which OpenClaw automatically detects and attaches to messages. Use in agent workflows:
# In an agent skill or automation
xai-gen "chart showing Q1 sales data" --filename sales_chart.png
β Image auto-attaches to response
βοΈ Configuration
positional arguments:
prompt Text description of the image to generateoptions:
-h, --help Show help message
--model MODEL Model name (default: grok-imagine-image)
--filename FILENAME Output filename (default: out.png)
--format {url,png,b64}
Response format: url (download), png (alias), b64 (base64)
--n N Number of images to generate (default: 1)
--verbose, -v Show detailed progress
Examples
Generate a meme:
xai-gen "dumbest trade meme: YOLO panic fail" --filename trade_meme.png
Batch generation:
xai-gen "logo variations for tech startup" --n 5
Outputs: out_1.png, out_2.png, out_3.png, out_4.png, out_5.png
High-quality artwork:
xai-gen "photorealistic portrait of a cat astronaut" --filename cat_astronaut.png
Integration with OpenClaw
The tool outputs MEDIA: /path/to/image.png which OpenClaw automatically detects and attaches to messages. Use in agent workflows:
# In an agent skill or automation
xai-gen "chart showing Q1 sales data" --filename sales_chart.png
β Image auto-attaches to response
π Tips & Best Practices
"XAI_API_KEY not found"
export XAI_API_KEY="xai-..."
"requests library not found"
pip3 install requests
Permission denied
chmod +x xai-gen
API errors