Skip to content

Commit abd2c37

Browse files
authored
Merge pull request #197 from OpenLAIR/fix-inno-figure-gen-openai-keys
Fix inno figure provider key handling
2 parents 5097ef0 + 77fab8d commit abd2c37

2 files changed

Lines changed: 317 additions & 152 deletions

File tree

skills/inno-figure-gen/SKILL.md

Lines changed: 52 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
---
22
name: inno-figure-gen
33
description: >
4-
Generate/edit images with Gemini image models (default:
5-
gemini-3.1-flash-image-preview). Use for image create/modify requests incl.
6-
edits. Supports text-to-image + image-to-image; 1K/2K/4K; use --input-image.
7-
Use --model to select a different model.
4+
Generate/edit images with OpenAI gpt-image-2 by default, falling back to
5+
Gemini (gemini-3.1-flash-image-preview) when OPENAI_API_KEY is unset.
6+
Supports text-to-image + image-to-image; 1K/2K/4K; use --input-image for
7+
editing, --provider to force a provider, --model to override the model.
88
---
99

10-
# Gemini Image Generation & Editing
10+
# Image Generation & Editing (GPT Image default, Gemini fallback)
1111

12-
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.
1318

1419
## Usage
1520

@@ -22,12 +27,12 @@ Keep the distinction clear:
2227

2328
**Generate new image:**
2429
```bash
25-
uv run <this-skill-directory>/scripts/generate_image.py --prompt "your image description" --filename "output-name.png" [--resolution 1K|2K|4K] [--model MODEL] [--api-key KEY]
30+
uv run <this-skill-directory>/scripts/generate_image.py --prompt "your image description" --filename "output-name.png" [--resolution 1K|2K|4K] [--provider auto|openai|gemini] [--model MODEL] [--openai-api-key KEY | --gemini-api-key KEY]
2631
```
2732

2833
**Edit existing image:**
2934
```bash
30-
uv run <this-skill-directory>/scripts/generate_image.py --prompt "editing instructions" --filename "output-name.png" --input-image "path/to/input.png" [--resolution 1K|2K|4K] [--model MODEL] [--api-key KEY]
35+
uv run <this-skill-directory>/scripts/generate_image.py --prompt "editing instructions" --filename "output-name.png" --input-image "path/to/input.png" [--resolution 1K|2K|4K] [--provider auto|openai|gemini] [--model MODEL] [--openai-api-key KEY | --gemini-api-key KEY]
3136
```
3237

3338
**Important:** Always run from the user's current working directory so images are saved where the user is working, not in the skill directory.
@@ -45,49 +50,59 @@ Goal: fast iteration without burning time on 4K until the prompt is correct.
4550

4651
## Resolution Options
4752

48-
The Gemini 3 Pro Image API supports three resolutions (uppercase K required):
53+
The script accepts three resolution tiers (uppercase K required):
4954

50-
- **1K** (default) - ~1024px resolution
51-
- **2K** - ~2048px resolution
52-
- **4K** - ~4096px resolution
55+
- **1K** (default) - ~1024px
56+
- **2K** - ~2048px
57+
- **4K** - ~4096px (Gemini) / **3840×2160 landscape** under OpenAI
5358

5459
Map user requests to API parameters:
5560
- No mention of resolution → `1K`
5661
- "low resolution", "1080", "1080p", "1K" → `1K`
5762
- "2K", "2048", "normal", "medium resolution" → `2K`
5863
- "high resolution", "high-res", "hi-res", "4K", "ultra" → `4K`
5964

60-
## Model Selection
65+
**OpenAI 4K note:** `gpt-image-2` supports non-square 4K outputs within its size limits. `--resolution 4K` with OpenAI maps to `3840×2160`.
6166

62-
The default model is `gemini-3.1-flash-image-preview`. You can override it with the `--model` flag:
67+
## Provider & Model Selection
6368

64-
```bash
65-
uv run <this-skill-directory>/scripts/generate_image.py --prompt "..." --filename "..." --model gemini-3.1-flash-image-preview
66-
```
69+
Two providers are available:
70+
71+
| Provider | Default model | When chosen |
72+
| -------- | ------------------------------------ | ------------------------------------------------------------ |
73+
| 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).
77+
78+
Common model options:
79+
- **OpenAI:** `gpt-image-2` (default)
80+
- **Gemini:** `gemini-3.1-flash-image-preview` (default, fast), `gemini-3-pro-image-preview` (higher quality, slower)
6781

68-
Available models depend on your Gemini API access. Common options:
69-
- `gemini-3.1-flash-image-preview` (default) - Fast image generation
70-
- `gemini-3-pro-image-preview` - Higher quality, slower
82+
## API Keys
7183

72-
## API Key
84+
The script resolves provider-specific keys first, while preserving the original Gemini-only `--api-key` behavior:
7385

74-
The script checks for API key in this order:
75-
1. `--api-key` argument (use if user provided key in chat)
76-
2. `GEMINI_API_KEY` environment variable
86+
1. Explicit, provider-specific flags: `--openai-api-key KEY`, `--gemini-api-key KEY`
87+
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.
88+
3. Environment variables: `OPENAI_API_KEY`, `GEMINI_API_KEY`
7789

78-
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.
7993

8094
## Preflight + Common Failures (fast fixes)
8195

8296
- Preflight:
8397
- `command -v uv` (must exist)
84-
- `test -n \"$GEMINI_API_KEY\"` (or pass `--api-key`)
85-
- If editing: `test -f \"path/to/input.png\"`
98+
- 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"`
86100

87101
- 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
89103
- `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
91106

92107
## Filename Generation
93108

@@ -140,12 +155,17 @@ Use templates when the user is vague or when edits must be precise.
140155

141156
## Examples
142157

143-
**Generate new image:**
158+
**Generate new image (auto provider):**
144159
```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
146161
```
147162

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):**
149169
```bash
150170
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
151171
```

0 commit comments

Comments
 (0)