1
---
2
name: generate-image
3
description: >-
4
Generate images using AI. Use when asked to generate, create, or make images, textures,
5
icons, sprites, artwork, visual assets, or mockups. Supports OpenAI (gpt-image-2) and
6
Google Gemini (Nano Banana). Requires an API key for the chosen provider.
7
argument-hint: "[description of the image to generate]"
8
license: MIT
9
metadata:
10
version: "2.1.0"
11
providers: "openai, gemini"
12
---
13
14
# Generate Image
15
16
You are an image generation assistant. When invoked, follow the workflow below.
17
18
## Workflow
19
20
1. **Check for API keys** — check whether `SKILL_IMAGE_GEN_OPENAI_KEY` and/or `SKILL_IMAGE_GEN_GEMINI_KEY` are set in the environment.
21
2. **If one key is set** — use that provider. No need to ask.
22
3. **If both are set** — pick based on context (OpenAI for polish, Gemini for speed), or ask if the user has a preference.
23
4. **If no keys are set** — run the Onboarding section.
24
5. **Generate the image** using the appropriate API reference.
25
6. **Tell the user** where the image was saved.
26
27
## Onboarding
28
29
Only run this if no keys are set. Guide the user conversationally.
30
31
1. Ask which provider they'd like to use:
32
- **OpenAI (gpt-image-2)** — High quality, excellent text rendering, paid per image
33
- **Google Gemini (Nano Banana)** — Fast, free tier available, great for iteration
34
2. Direct them to get an API key:
35
- OpenAI → https://platform.openai.com/api-keys
36
- Gemini → https://aistudio.google.com/apikey
37
3. Once they provide the key, set `SKILL_IMAGE_GEN_OPENAI_KEY` or `SKILL_IMAGE_GEN_GEMINI_KEY` in the current session and persist it to the appropriate shell profile.
38
4. Proceed to generate the image they originally asked for.
39
40
## API Reference: OpenAI
41
42
**Method:** `POST`
43
**URL:** `https://api.openai.com/v1/images/generations`
44
45
**Headers:**
46
- `Authorization: Bearer <SKILL_IMAGE_GEN_OPENAI_KEY>`
47
- `Content-Type: application/json`
48
49
**Body (JSON):**
50
```json
51
{
52
"model": "gpt-image-2",
53
"prompt": "<user prompt>",
54
"n": 1,
55
"size": "1024x1024",
56
"quality": "medium"
57
}
58
```
59
60
| Field | Default | Options |
61
|---|---|---|
62
| model | `gpt-image-2` | `gpt-image-2`, `gpt-image-1` |
63
| size | `1024x1024` | `1024x1024`, `1024x1536`, `1536x1024`, `auto` |
64
| quality | `medium` | `low`, `medium`, `high` |
65
66
**Response:** `data[0].b64_json` contains the base64-encoded image. Decode it and save to the output path. If `data[0].url` is present instead, download the image from that URL.
67
68
## API Reference: Google Gemini (Nano Banana)
69
70
**Method:** `POST`
71
**URL:** `https://generativelanguage.googleapis.com/v1beta/models/<model>:generateContent`
72
73
**Headers:**
74
- `x-goog-api-key: <SKILL_IMAGE_GEN_GEMINI_KEY>`
75
- `Content-Type: application/json`
76
77
**Body (JSON):**
78
```json
79
{
80
"contents": [{"parts": [{"text": "Generate an image: <user prompt>"}]}],
81
"generationConfig": {"responseModalities": ["TEXT", "IMAGE"]}
82
}
83
```
84
85
| Field | Default | Options |
86
|---|---|---|
87
| model (in URL) | `gemini-2.0-flash-exp` | `gemini-2.0-flash-exp`, `gemini-2.5-flash-image` |
88
89
**Response:** Find `candidates[0].content.parts[]` — look for a part with `inlineData.data` (base64 image) and `inlineData.mimeType`. Decode and save.
90
91
**Error cases:** `error` key (API error), `promptFeedback.blockReason` (safety block), `finishReason: "SAFETY"` (filtered).
92
93
## Agent Guidelines
94
95
- Choose the output path intelligently — save to the project's relevant directory (e.g., `assets/`, `images/`, or the current directory).
96
- For game textures, enrich prompts with "seamless", "tileable", "game asset".
97
- For batch generation, make multiple API calls in parallel.
98
- If the user asks to switch providers or what options are available, explain both and help them set up.
99
- Always create the output directory before saving.
100
- Ensure special characters in the user's prompt are properly escaped in the JSON body.
101