Skip to main content

AI Image Creator

Generate PNG images using AI models — Gemini, FLUX.2, Riverflow, SeedDream, GPT-5 Image — routed through Cloudflare AI Gateway (BYOK) or directly via OpenRouter/Google AI Studio. Also analyzes and describes existing images using multimodal vision. Skill name: ai-image-creator Trigger: “generate an image”, “create a PNG”, “make an icon”, “describe this image”, “analyze this image”

Overview

The ai-image-creator skill wraps a Python script (generate-image.py) that calls image generation APIs and saves the result as a PNG. It supports: Multimodal models (gemini, gpt5) accept reference images for editing/style transfer and can analyze existing images. Image-only models (riverflow, flux2, seedream) generate from text prompts only. A companion script (composite-banners.py) generates consistent logo banners across multiple standard sizes using ImageMagick — no API calls required.
Cloudflare AI Gateway acts as a proxy that stores your provider API keys server-side (BYOK — Bring Your Own Key). Your actual keys never leave Cloudflare; only the gateway token is stored locally. This also gives you request logs, caching, and rate limiting.

Step 1: Create a Cloudflare account

Sign up at dash.cloudflare.com (free tier works).

Step 2: Create an AI Gateway

  1. In the Cloudflare dashboard, go to AI > AI Gateway
  2. Click Create Gateway
  3. Enter a name (e.g., my-ai-gateway) — this becomes your AI_IMG_CREATOR_CF_GATEWAY_ID
  4. Click Create
Note your Account ID from the dashboard URL: dash.cloudflare.com/{account_id}/...

Step 3: Enable authentication

  1. In your gateway settings, enable Authentication
  2. Copy the auth token — this is your AI_IMG_CREATOR_CF_TOKEN

Step 4: Add BYOK provider keys

Store your provider keys inside Cloudflare so the script never sends them in request headers. Add OpenRouter key:
  1. In gateway dashboard, go to Provider Keys > Add
  2. Select OpenRouter as the provider
  3. Paste your OpenRouter API key (sk-or-...)
  4. Set alias to default > Save
Add Google AI Studio key:
  1. Provider Keys > Add again
  2. Select Google AI Studio
  3. Paste your Google AI Studio key (AI...)
  4. Set alias to aistudio > Save

Step 5: Set environment variables

Apply: source ~/.zshrc

Setup Option B: OpenRouter Direct (Simplest)

No Cloudflare account needed. One environment variable.

Step 1: Create an OpenRouter account

Sign up at openrouter.ai.

Step 2: Get an API key

Go to openrouter.ai/keys > Create Key. Copy the key (starts with sk-or-...).

Step 3: Add credits

Go to openrouter.ai/credits and add pay-as-you-go credits. Check model pricing at openrouter.ai/models.

Step 4: Set environment variable

This is the only variable needed for Option B. All models are available through OpenRouter.

Setup Option C: Google AI Studio Direct

For using the Gemini model via Google’s API directly (without OpenRouter).

Step 1: Get an API key

Go to aistudio.google.com/apikey > Create API Key. Select or create a Google Cloud project. Copy the key (starts with AI...).

Step 2: Enable billing (required for image generation)

The free tier has a quota of 0 for gemini-3.1-flash-image image generation. You must enable billing on the linked Google Cloud project. Without billing, requests return 429 RESOURCE_EXHAUSTED. OpenRouter (Option B) is simpler if you want to avoid GCP billing setup.

Step 3: Set environment variable


Environment Variables Reference

*For Option A (gateway), provider keys are stored in Cloudflare as BYOK — you do not need to set OPENROUTER_KEY or GEMINI_KEY locally. Gateway mode activates when all three CF_* vars are set and falls back to direct mode if the gateway fails. Add these to your .env file (used by the workspace) or directly to your shell profile. See env-variables.md for full reference.

Usage Examples

Basic image generation (default model: gemini)

Specific model

Transparent background

Requires brew install ffmpeg imagemagick.

Reference image editing (multimodal models only)

Image analysis

Composite banners (existing logo → multiple sizes)

Cost tracking


Agent Integration

@canvas-designer

Canvas uses /ai-image-creator to generate visual assets when implementing UI components — icons, hero images, product shots, backgrounds, and mockup assets. Canvas does not rely on external stock imagery; it generates what the design requires. Typical Canvas workflow:
  1. Identify required image assets from the design spec
  2. Write detailed prompts aligned with the design direction (colors, style, mood)
  3. Generate with ai-image-creator, selecting the model best suited to the asset type
  4. Post-process with ImageMagick if resizing or format conversion is needed
  5. Reference the generated files in the component code

@pixel (Social Media)

Pixel uses /ai-image-creator to generate original imagery for social media posts when assets are not available — thumbnails, banners, carousel visuals, story backgrounds, post artwork. Typical Pixel workflow:
  1. Determine the visual direction from the content calendar entry
  2. Generate platform-specific images (using -a for aspect ratio and -s for size)
  3. Use composite-banners.py when the brand needs consistent logo treatment across multiple sizes

Troubleshooting