Get the FREE Ultimate OpenClaw Setup Guide β†’
m

xAI Image Generator

Scanned

@mexicanamerican

npx machina-cli add skill @mexicanamerican/xai-image-gen --openclaw
Files (1)
SKILL.md
4.0 KB

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:

  • 🎨 Simple CLI interface: xai-gen "<prompt>"
  • πŸ–ΌοΈ Multiple output formats: URL download, base64 encoding
  • πŸ”’ Batch generation (multiple images per prompt)
  • ⚑ Fast, pure API implementation (Pi-safe)
  • πŸ›‘οΈ Robust error handling with user-friendly messages
  • πŸ“Ž Auto-attaches generated images in OpenClaw
  • 🎯 Uses xAI's native resolution (no size parameter needed)

Installation

# Navigate to skills directory
cd ~/.openclaw/workspace/skills

# Clone or copy this skill
# (or install via clawhub when published)

# Install dependencies
pip3 install requests

# Ensure 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.png

# Generate multiple images
xai-gen "futuristic vehicle" --n 3

# Base64 output (no download)
xai-gen "logo design" --format b64

# Verbose mode
xai-gen "space station" --verbose

Options

positional arguments:
  prompt                Text description of the image to generate

options:
  -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

  • Endpoint: https://api.x.ai/v1/images/generations
  • Model: grok-imagine-image
  • Authentication: Bearer token via XAI_API_KEY
  • Rate Limits: Subject to xAI API limits (check xAI docs)
  • Timeout: 60s for generation, 30s for download

Error Handling

The tool handles common errors gracefully:

  • ❌ Missing API key β†’ Clear instructions
  • ❌ Network errors β†’ Descriptive messages
  • ❌ API timeouts β†’ Retry suggestions
  • ❌ Invalid parameters β†’ Usage hints
  • ❌ File write errors β†’ Permission checks

Requirements

  • Python: 3.7+
  • Dependencies: requests
  • API Key: xAI API key (get from https://console.x.ai)
  • Network: Internet connection required

Platform Compatibility

  • βœ… Linux (tested on Raspberry Pi)
  • βœ… macOS
  • βœ… Windows (via WSL or native Python)
  • βœ… ARM64 / ARMv7 (Pi-safe, pure API calls)

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

  • Check API key validity
  • Verify account has credits
  • Check xAI status page

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

Source

git clone https://clawhub.ai/mexicanamerican/xai-image-genView on GitHub

Overview

This production-ready CLI creates images from text prompts using xAI's Grok API. It supports multiple output formats, batch generation, and automatically outputs MEDIA: paths for OpenClaw integration, making image attachment seamless.

How This Skill Works

The tool calls xAI's Grok-imagine-image model via the /v1/images/generations endpoint using a Bearer token from XAI_API_KEY. It can return URLs, PNGs, or base64 data and can generate multiple images per prompt in a single run. It also outputs MEDIA: paths so OpenClaw can auto-attach the generated images.

When to Use It

  • You need a quick image generated from a descriptive prompt for social posts or demos.
  • You want multiple variants of a concept in a single run (batch generation).
  • You need different output formats (URL, PNG, or base64) to fit downstream tools.
  • You rely on OpenClaw and require automatic MEDIA attachments from generated images.
  • You’re building AI art assets or demos with a simple, scriptable CLI workflow.

Quick Start

  1. Step 1: Set your API key in your environment: export XAI_API_KEY="your-api-key"
  2. Step 2: Run a prompt to generate images: xai-gen "sunset over mountains"
  3. Step 3: (Optional) specify --n for batch or --format to choose url/png/b64; rely on MEDIA: paths for OpenClaw attachment

Best Practices

  • Craft concise, specific prompts to guide the Grok model toward the desired style and content.
  • Use --n to generate multiple variants and select the best result.
  • Ensure the XAI_API_KEY environment variable is set and valid before running.
  • Choose the output format that best suits your integration (url for downloads, b64 for embedding).
  • Rely on the MEDIA: outputs to verify OpenClaw auto-attachment works as expected.

Example Use Cases

  • Generate a meme with a custom filename: xai-gen "dumbest trade meme: YOLO panic fail" --filename trade_meme.png
  • Batch logo variations for a startup: xai-gen "logo variations for tech startup" --n 5
  • Produce a photorealistic cat astronaut portrait: xai-gen "photorealistic portrait of a cat astronaut" --filename cat_astronaut.png
  • Output base64 for embedding in chat: xai-gen "logo design" --format b64
  • Create a data chart image with OpenClaw attachment: xai-gen "chart showing Q1 sales data" --filename sales_chart.png

Frequently Asked Questions

Add this skill to your agents
Sponsor this space

Reach thousands of developers β†—