← 返回
内容创作 Key 中文

xAI Image Generator

Generate images from text prompts using xAI's Grok API with options for format, batch size, and automatic media attachment in OpenClaw.
利用 xAI Grok API 将文本提示生成图像,支持格式、批量大小设置及 OpenClaw 自动媒体附件。
mexicanamerican
内容创作 clawhub v1.0.0 1 版本 99863.4 Key: 需要
★ 0
Stars
📥 1,462
下载
💾 58
安装
1
版本
#latest

概述

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 ""
  • 🖼️ 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

版本历史

共 1 个版本

  • v1.0.0 当前
    2026-03-28 22:41 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

content-creation

AdMapix

fly0pants
广告情报与应用数据分析助手,支持搜索广告素材、分析应用排名、下载量、收入及市场洞察,用于广告素材和竞品分析。
★ 295 📥 136,494
content-creation

Baidu Wenku AIPPT

ide-rea
使用百度文库 AI 智能生成 PPT,自动根据内容选择模板。
★ 66 📥 46,208
content-creation

Humanizer

biostartechnology
消除AI写作痕迹,使文本更自然真实。基于维基百科"AI写作特征"指南,识别并修正夸张象征、宣传用语、肤浅-ing分析、模糊归因、破折号滥用、三项排比、AI词汇、负面平行结构及冗长连接词等模式。
★ 860 📥 199,873