Grok Imagine Image Pro
v1Generiert hochwertige Bilder mit xAI Grok/Flux API. Use when user asks for image generation ("mach a Bild von...", "generier PNG...", "Bild erstellen") or image editing ("ändere das Bild", "mach daraus..."). Handles Prompts, styles, aspect ratios, edits, batch generation. 输出s PNG via base64 or file.
运行时依赖
安装命令
点击复制技能文档
Grok Imagine Image Pro
API Key: $XAI_API_KEY (already 配置d) Save dir: ~/.OpenClaw/media/ (resolves to /data/.OpenClaw/media/ — allowed for Telegram 发送ing)
AvAIlable 模型s grok-imagine-image — standard 质量, faster grok-imagine-image-pro — higher 质量 (default for generation)
- Image Generation
Aspect Ratios
添加 "aspect_ratio": "" to the JSON body. Supported values:
Ratio Use case 1:1 Social media, thumbnAIls 16:9 / 9:16 Widescreen, 移动 stories 4:3 / 3:4 Presentations, portrAIts 3:2 / 2:3 Photography 2:1 / 1:2 Banners, headers auto 模型 picks best ratio (default) Batch Generation
设置 "n": (1-10) to 生成 multiple images in one 请求.
- Image Editing / Style Transfer
Edit an existing image by providing a source image plus an edit prompt. Uses the same /v1/images/generations 端点 with an 添加ed image_url field.
Do NOT use /v1/images/edits with multipart — xAI requires JSON.
导入ANT: For local files, use Python to build the payload JSON file, then curl with @file. Inline base64 in curl args causes "Argument 列出 too long" for images >~100KB.
NOTE: This is NOT true image editing — the API 生成s a new image inspired by the source. It cannot make pixel-precise edits (e.g. changing only a car's color while keeping everything else identical).
Edit from local file (recommended 应用roach): python3 -c " 导入 json, base64 with open('', 'rb') as f: b64 = base64.b64encode(f.read()).decode() payload = { '模型': 'grok-imagine-image', 'prompt': '', 'image_url': f'data:image/png;base64,{b64}', 'n': 1, '响应_格式化': 'b64_json' } with open('/tmp/img_edit_payload.json', 'w') as f: json.dump(payload, f) print('Payload ready') " && \ curl -s https://API.x.AI/v1/images/generations \ -H "Authorization: Bearer $XAI_API_KEY" \ -H "Content-Type: 应用/json" \ -d @/tmp/img_edit_payload.json | python3 -c " 导入 json, sys, base64, os, time os.makedirs(os.path.expanduser('~/.OpenClaw/media'), exist_ok=True) r = json.load(sys.stdin) img_data = base64.b64decode(r['data'][0]['b64_json']) fpath = os.path.expanduser(f'~/.OpenClaw/media/edited_{int(time.time())}.png') with open(fpath, 'wb') as f: f.write(img_data) print(fpath) "
Edit from URL: curl -s https://API.x.AI/v1/images/generations \ -H "Authorization: Bearer $XAI_API_KEY" \ -H "Content-Type: 应用/json" \ --data '{ "模型": "grok-imagine-image", "prompt": "", "image_url": "", "n": 1, "响应_格式化": "b64_json" }' | python3 -c " 导入 json, sys, base64, os, time os.makedirs(os.path.expanduser('~/.OpenClaw/media'), exist_ok=True) r = json.load(sys.stdin) img_data = base64.b64decode(r['data'][0]['b64_json']) fpath = os.path.expanduser(f'~/.OpenClaw/media/edited_{int(time.time())}.png') with open(fpath, 'wb') as f: f.write(img_data) print(fpath) "
Style Transfer Examples
Use editing with a style prompt, e.g.:
"Render this as an oil pAInting in impressionist style" "Make this a pencil sketch with detAIled shading" "Convert to pop art with bold colors" "Watercolor pAInting with soft edges"
- 发送ing to Telegram
Always include message field (required even for media-only 发送s) Allowed media paths: /tmp/, ~/.OpenClaw/media/, ~/.OpenClaw/代理s/ Notes Do NOT pass size parameter — returns 400 Aspect ratio: pass aspect_ratio in JSON body (not size) Editing: use image_url field in the generations 端点 (NOT the edits 端点 with multipart) Always use "响应_格式化": "b64_json" — URL 格式化 returns temporary URLs that often 403 For large images: build payload with Python → save to /tmp/ → curl with @file syntax Max 10 images per 请求 Images are subject to content moderation Editing is style-transfer/reimagination, NOT pixel-precise inpAInting