
Generate Image
Generate or edit marketing, UI, and product images through OpenRouter image models without wiring a custom API client yourself.
Overview
generate-image is an agent skill most often used in Build (also Validate, Launch) that generates and edits images via OpenRouter models from the command line.
Install
npx skills add https://github.com/davila7/claude-code-templates --skill generate-imageWhat is this skill?
- Calls OpenRouter image endpoints from a Python CLI with argparse-driven options
- Supports generation models including google/gemini-3-pro-image-preview, black-forest-labs/flux.2-pro, and flux.2-flex
- Edits existing images when you pass an input file plus an editing prompt
- Loads OPENROUTER_API_KEY from a .env file by walking parent directories
- Encodes local images as base64 data URLs for edit requests
- Supports multiple OpenRouter image models including Gemini 3 Pro image preview and Flux.2 Pro/Flex
Adoption & trust: 902 installs on skills.sh; 27.8k GitHub stars; 3/3 security scanners passed (skills.sh audits).
What problem does it solve?
You need on-demand AI images for a product or campaign but do not want to hand-roll OpenRouter requests, base64 encoding, and API key handling.
Who is it for?
Solo builders who already use OpenRouter and want a scriptable image gen/edit step inside Claude Code or similar agents.
Skip if: Teams that require on-device-only generation, enterprise DAM workflows, or guaranteed rights-managed stock without reviewing model provider terms.
When should I use this skill?
You need to generate or edit images via OpenRouter and want the agent to run the bundled Python script with prompts and optional input files.
What do I get? / Deliverables
You get saved or streamed image output from your chosen OpenRouter model with keys loaded from .env, ready to drop into UI, docs, or distribution assets.
- Generated or edited image files on disk
- CLI error output when keys or input paths are missing
Recommended Skills
Journey fit
Spans multiple journey phases - primary shelf plus alternate fits below.
Image generation is most often invoked while building assets and wiring third-party APIs, which maps cleanly to Build. The skill is an OpenRouter API integration script, so integrations is the canonical shelf even when outputs feed frontend or launch content.
Where it fits
Produce a landing-page hero mock from a short product description before committing to a designer.
Generate placeholder illustrations for in-app empty states while UI components are still in flux.
Refresh social preview images from an edit prompt on an existing screenshot.
Batch new blog header art when repurposing release notes into articles.
How it compares
Use instead of ad-hoc curl or one-off Python snippets when you want a repeatable OpenRouter image CLI in the agent toolkit.
Common Questions / FAQ
Who is generate-image for?
Indie developers and agent users who ship SaaS, content, or agent products and need quick API-backed visuals without building a custom image microservice.
When should I use generate-image?
During Build when wiring creative integrations, during Validate for prototype hero images, and during Launch or Grow when regenerating thumbnails, ads, or blog art from prompts or edit passes.
Is generate-image safe to install?
Review the Security Audits panel on this Prism page for scan results; you should treat OPENROUTER_API_KEY as a secret, keep .env out of git, and validate outbound network use matches your policy.
SKILL.md
READMESKILL.md - Generate Image
#!/usr/bin/env python3 """ Generate and edit images using OpenRouter API with various image generation models. Supports models like: - google/gemini-3-pro-image-preview (generation and editing) - black-forest-labs/flux.2-pro (generation and editing) - black-forest-labs/flux.2-flex (generation) - And more image generation models available on OpenRouter For image editing, provide an input image along with an editing prompt. """ import sys import json import base64 import argparse from pathlib import Path from typing import Optional def check_env_file() -> Optional[str]: """Check if .env file exists and contains OPENROUTER_API_KEY.""" # Look for .env in current directory and parent directories current_dir = Path.cwd() for parent in [current_dir] + list(current_dir.parents): env_file = parent / ".env" if env_file.exists(): with open(env_file, 'r') as f: for line in f: if line.startswith('OPENROUTER_API_KEY='): api_key = line.split('=', 1)[1].strip().strip('"').strip("'") if api_key: return api_key return None def load_image_as_base64(image_path: str) -> str: """Load an image file and return it as a base64 data URL.""" path = Path(image_path) if not path.exists(): print(f"❌ Error: Image file not found: {image_path}") sys.exit(1) # Determine MIME type from extension ext = path.suffix.lower() mime_types = { '.png': 'image/png', '.jpg': 'image/jpeg', '.jpeg': 'image/jpeg', '.gif': 'image/gif', '.webp': 'image/webp', } mime_type = mime_types.get(ext, 'image/png') with open(path, 'rb') as f: image_data = f.read() base64_data = base64.b64encode(image_data).decode('utf-8') return f"data:{mime_type};base64,{base64_data}" def save_base64_image(base64_data: str, output_path: str) -> None: """Save base64 encoded image to file.""" # Remove data URL prefix if present if ',' in base64_data: base64_data = base64_data.split(',', 1)[1] # Decode and save image_data = base64.b64decode(base64_data) with open(output_path, 'wb') as f: f.write(image_data) def generate_image( prompt: str, model: str = "google/gemini-3-pro-image-preview", output_path: str = "generated_image.png", api_key: Optional[str] = None, input_image: Optional[str] = None ) -> dict: """ Generate or edit an image using OpenRouter API. Args: prompt: Text description of the image to generate, or editing instructions model: OpenRouter model ID (default: google/gemini-3-pro-image-preview) output_path: Path to save the generated image api_key: OpenRouter API key (will check .env if not provided) input_image: Path to an input image for editing (optional) Returns: dict: Response from OpenRouter API """ try: import requests except ImportError: print("Error: 'requests' library not found. Install with: pip install requests") sys.exit(1) # Check for API key if not api_key: api_key = check_env_file() if not api_key: print("❌ Error: OPENROUTER_API_KEY not found!") print("\nPlease create a .env file in your project directory with:") print("OPENROUTER_API_KEY=your-api-key-here") print("\nOr set the environment variable:") print("export OPENROUTER_API_KEY=your-api-key-here") print("\nGet your API key from: https://openrouter.ai/keys") sys.exit(1) # Determine if this is generation or editing is_editing = input_image is not None if is_editing: print(f"✏️ Editing image with model: {model}") print(f"📷 Input image: {input_image}") print(f"📝 Edit prompt: {prompt}") # Load input image as base64 image_data_url = load