| name | ai-image-generation |
| description | Generate images with AI (xAI Grok, FAL, etc.) — reference image analysis, brand palette extraction, prompt engineering, vision fallbacks |
AI Image Generation
Create brand-consistent images through AI image providers. This covers the end-to-end process: examining reference images, pulling brand color palettes, constructing detailed prompts, and setting up providers.
Prerequisites
- Image generation provider configured (
image_gen.provider in config, e.g. xai)
- API key set (e.g.
XAI_API_KEY in .env)
- For vision analysis:
vision.provider set, or use the fallback approach below
Workflow
1. Analyze Reference Images First
When the user supplies reference images, ALWAYS examine them before generating. Never infer the style from a text description alone.
If vision_analyze tool is available:
vision_analyze(image_url="path", question="Describe the visual style in detail: colors, composition, typography, textures, lighting, materials, mood, and overall aesthetic.")
If vision_analyze is NOT available (fallback via xAI API):
Use execute_code to call the xAI vision API directly:
import base64, json, os, urllib.request
api_key = ""
with open("/data/.ion/.env") as f:
for line in f:
if line.startswith("XAI_API_KEY="):
api_key = line.strip().split("=", 1)[1]
with open(image_path, "rb") as f:
b64 = base64.b64encode(f.read()).decode()
payload = json.dumps({
"model": "grok-4.5",
"messages": [{"role": "user", "content": [
{"type": "image_url", "image_url": {"url": f"data:image/jpeg;base64,{b64}", "detail": "high"}},
{"type": "text", "text": "Describe this image's visual style in detail..."}
]}],
"max_tokens": 800
})
req = urllib.request.Request("https://api.x.ai/v1/chat/completions",
data=payload.encode(),
headers={"Content-Type": "application/json", "Authorization": f"Bearer {api_key}"})
resp = urllib.request.urlopen(req, timeout=60)
Available xAI vision models (as of 2026-07): grok-4.5, grok-4.3. Do NOT use grok-2-vision — it's not available.
2. Extract Brand Palette
Before generating, identify the ACTUAL brand colors. Priority order:
- Brand kit repo (e.g.
paxlabs-inc/matrix-brand-kit/tokens/colors.css) — fetch from GitHub raw URL
- Design tokens files in the project (search for
*tokens*, *colors*, *palette*)
- Ask the user for hex codes
NEVER use generic template colors or guess from other files in the codebase. Template starter files (like brand-guidelines-starter.md) contain placeholder values, not real brand colors.
3. Build Prompts
Structure each prompt with:
- Art style/technique first (hand-drawn brush, photorealistic, 3D render, etc.)
- Subject/content (what's being depicted)
- Exact colors with hex codes from the brand palette
- Composition notes (negative space, asymmetry, focal point)
- Materials/textures (frosted glass, chalky gouache, metallic, etc.)
- Lighting (rim light, bloom, volumetric, studio, etc.)
- Explicit exclusions ("No gradients, no 3D, no photorealism" when appropriate)
4. Generate
Use image_generate tool:
image_generate(prompt="...", aspect_ratio="landscape|portrait|square")
- Generate 3-5 variations per batch for the user to choose from
- Use
landscape (16:9) as default aspect ratio unless specified otherwise
- All images in a batch should explore different subjects/compositions within the same style
5. Present Results
Display each image inline with a brief label describing the concept. Ask which direction to refine.
Provider Configuration
xAI (Grok)
ion config set XAI_API_KEY "your-key"
ion config set image_gen.provider xai
ion config set vision.provider xai
- Model:
grok-imagine-image (auto-selected)
- Storage: enabled by default (public URLs, may incur billing)
- Resolution: 1K default
FAL
ion config set FAL_KEY "your-key"
Style Reference Patterns
Anthropic-style Hand-Drawn Brush
- Freehand digital brush strokes with visible pressure variation
- Organic, slightly wobbly lines — never geometric or perfect
- Flat solid fills (no gradients, no shading)
- Chalky/gouache-like opacity on dark backgrounds
- Sparse composition, generous negative space
- Dashed energy rays as quick gestural marker flicks
- Single accent color on dark ground
Apple-style Premium Tech
- Dramatic studio lighting, soft rim light, bloom
- Frosted glass, holographic, subsurface scattering materials
- Deep black void backgrounds, generous negative space
- Cinematic, monumental scale
- Clean geometric sans-serif implied in composition
- Monochromatic or tightly restricted palette
User Style Preferences (this user)
- Apple-level luxury tech aesthetic
- Dark backgrounds (#0a0a0a or deeper)
- Electric blue-cyan dominant palette, warm gold accents (for non-Matrix work)
- Frosted glass / holographic / volumetric materials
- Dramatic rim lighting with bloom
- Generous negative space, minimal compositions
- Bold geometric sans-serif when typography is needed
- Mood: calm, intelligent, powerful, futuristic — quiet confidence over hype
- For Matrix-branded work: ALWAYS use the brand palette from
references/matrix-brand-palette.md (sage #99bd9c on warm charcoal #161615)
- Anthropic-style hand-drawn brush is a preferred illustration style for Matrix
Video-to-Style Analysis
When the user sends a video as a style reference, extract frames before analyzing:
ffprobe -v error -show_entries format=duration,stream=width,height -of csv=p=0 input.mp4
ffmpeg -y -i input.mp4 -vf "fps=1,scale=1024:-1" /tmp/ref_frame_%02d.png
ffmpeg -y -i input.mp4 -vf "fps=4,scale=1024:-1" /tmp/ref_frame_%02d.png
Then analyze the best frame(s) via the xAI vision API (see fallback section above). Never ask the user to describe a video — extract and analyze it yourself.
Social Media Campaign Illustration Workflow
When generating a themed set of illustrations for a social media campaign:
- Analyze the reference — extract style DNA (colors, line quality, mood, textures)
- Define the content grid — map out 15-20 distinct concepts that cover the brand's themes
- Batch-generate in groups of 3 — use parallel
image_generate calls (max 3 per turn)
- Write captions in brand voice — each post gets a caption that matches the illustration's energy
- Create a posting strategy — group posts by phase (launch, build, community, values, momentum)
- Deliver as a structured plan — markdown file with image paths, captions, and scheduling
The full plan should include:
- Image file path for each post
- Caption text (platform-ready, with hashtags)
- Posting schedule / phase grouping
- Platform-specific notes (X vs Telegram vs Instagram)
Pitfalls
- Don't guess brand colors from template files or other projects. Always fetch the actual brand token file.
- Don't use
grok-2-vision — it's not in the available models list. Use grok-4.5 or grok-4.3.
- Don't generate without analyzing references first when the user provides them. The style extraction is the whole point.
- Don't retry
vision_analyze if the tool doesn't exist in the session. Fall back to the xAI API via execute_code immediately.
- API key redaction: The
.env file values are redacted in terminal() and read_file() output. To read the actual key, use Python's open() directly within execute_code — the raw file read works, only the tool output layer redacts.
- Don't ask the user to describe a video — extract frames with ffmpeg and analyze them. The user expects you to process the media, not ask them about it.