You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Generate new images or edit existing ones using Google's Gemini image generation API (default model: `gemini-3.1-flash-image-preview`).
12
+
Generate new images or edit existing ones. The script picks a provider based on which API keys are available:
13
+
14
+
1.**OpenAI**`gpt-image-2` — used when `OPENAI_API_KEY` is set (default).
15
+
2.**Gemini**`gemini-3.1-flash-image-preview` — used when only `GEMINI_API_KEY` is set.
16
+
17
+
When both keys are set, OpenAI is picked by default; force Gemini with `--provider gemini`. If an auto-selected OpenAI call fails at runtime (quota, moderation, network), the script transparently falls back to Gemini when a Gemini key is available.
| OpenAI |`gpt-image-2`|`--provider auto` (default) when `OPENAI_API_KEY` is set, or `--provider openai`|
74
+
| Gemini |`gemini-3.1-flash-image-preview`|`--provider auto` when only `GEMINI_API_KEY` is set, or `--provider gemini`, or as runtime fallback from a failed auto-OpenAI call |
75
+
76
+
Override either default with `--model`. Note: the model name is provider-specific; passing a Gemini model name while the script falls back to Gemini automatically will not preserve a user-specified OpenAI model (each provider uses its own default during fallback).
2. Generic `--api-key KEY` — kept for backward compatibility with the original Gemini-only script. Under `auto`, it is treated as a Gemini key unless an OpenAI key is provided by `--openai-api-key` or `OPENAI_API_KEY`. Under explicit `--provider openai`, it is treated as an OpenAI key; under explicit `--provider gemini`, it is treated as a Gemini key.
If neither is available, the script exits with an error message.
90
+
When `--provider auto` is selected and OpenAI fails at runtime, fallback to Gemini requires `--gemini-api-key`, `--api-key`, or the `GEMINI_API_KEY` env var.
91
+
92
+
If no key is resolvable for the chosen provider, the script exits with a clear error message listing both ways to fix it.
-At least one of: `test -n "$OPENAI_API_KEY" -o -n "$GEMINI_API_KEY"` (or pass`--openai-api-key`, `--gemini-api-key`, or backward-compatible`--api-key`)
99
+
- If editing: `test -f "path/to/input.png"`
86
100
87
101
- Common failures:
88
-
-`Error: No API key provided.` → set `GEMINI_API_KEY` or pass `--api-key`
102
+
-`Error: No API key found...` → set `OPENAI_API_KEY` or `GEMINI_API_KEY`, or pass an explicit `--*-api-key` flag
89
103
-`Error loading input image:` → wrong path / unreadable file; verify `--input-image` points to a real image
90
-
- “quota/permission/403” style API errors → wrong key, no access, or quota exceeded; try a different key/account
104
+
-`[warn] OpenAI call failed (...); falling back to Gemini.` → informational; a Gemini key was available and produced the image. Investigate the OpenAI error separately (quota, moderation, network)
105
+
- "quota/permission/403" style errors with no fallback → no Gemini key available, or user used `--provider openai` (explicit provider disables fallback). Try a different key, or drop the explicit provider to enable fallback
91
106
92
107
## Filename Generation
93
108
@@ -140,12 +155,17 @@ Use templates when the user is vague or when edits must be precise.
140
155
141
156
## Examples
142
157
143
-
**Generate new image:**
158
+
**Generate new image (auto provider):**
144
159
```bash
145
-
uv run <this-skill-directory>/scripts/generate_image.py --prompt "A serene Japanese garden with cherry blossoms" --filename "2025-11-23-14-23-05-japanese-garden.png" --resolution 4K
160
+
uv run <this-skill-directory>/scripts/generate_image.py --prompt "A serene Japanese garden with cherry blossoms" --filename "2025-11-23-14-23-05-japanese-garden.png" --resolution 2K
146
161
```
147
162
148
-
**Edit existing image:**
163
+
**Force Gemini:**
164
+
```bash
165
+
uv run <this-skill-directory>/scripts/generate_image.py --prompt "A serene Japanese garden with cherry blossoms" --filename "2025-11-23-14-23-05-japanese-garden-4k.png" --resolution 4K --provider gemini
166
+
```
167
+
168
+
**Edit existing image (auto provider):**
149
169
```bash
150
170
uv run <this-skill-directory>/scripts/generate_image.py --prompt "make the sky more dramatic with storm clouds" --filename "2025-11-23-14-25-30-dramatic-sky.png" --input-image "original-photo.jpg" --resolution 2K
0 commit comments