AgentAnon commited on
Commit
c2c151c
·
verified ·
1 Parent(s): 00f1578

Upload ideogram 4 prompting.md

Browse files
Files changed (1) hide show
  1. ideogram 4 prompting.md +362 -0
ideogram 4 prompting.md ADDED
@@ -0,0 +1,362 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Prompting Guide
2
+
3
+ Ideogram 4 is trained exclusively on **structured JSON captions** (represented as string type). While the
4
+ model can accept plain-text prompts, providing a JSON object that follows the
5
+ caption schema gives significantly better results, especially for
6
+ controllability, spatial layout, and style fidelity.
7
+
8
+ ## Plain-text vs. JSON prompts
9
+
10
+ You can pass in plain-text prompts directly to the model and it will work. The
11
+ sampling parameters come from a named preset in `ideogram4.PRESETS` (the same
12
+ ones `run_inference.py` exposes via `--sampler-preset`), unpacked into the
13
+ `pipe()` call:
14
+
15
+ ```python
16
+ from ideogram4 import PRESETS
17
+
18
+ preset = PRESETS["V4_QUALITY_48"]
19
+ images = pipe(
20
+ "a golden retriever on a skateboard",
21
+ height=1024,
22
+ width=1024,
23
+ num_steps=preset.num_steps,
24
+ guidance_schedule=preset.guidance_schedule,
25
+ mu=preset.mu,
26
+ std=preset.std,
27
+ )
28
+ ```
29
+
30
+
31
+ But for higher quality image generations and more control, pass a JSON string as the prompt:
32
+
33
+ ```python
34
+ import json
35
+ from ideogram4 import PRESETS
36
+
37
+ caption = {
38
+ "high_level_description": "A golden retriever riding a skateboard down a sunny sidewalk.",
39
+ "style_description": {
40
+ "aesthetics": "warm, playful, vibrant",
41
+ "lighting": "bright afternoon sunlight, long soft shadows",
42
+ "photo": "shallow depth of field, eye-level, 85mm lens",
43
+ "medium": "photograph",
44
+ "color_palette": ["#F5C542", "#87CEEB", "#4A4A4A", "#FFFFFF", "#2E8B57"]
45
+ },
46
+ "compositional_deconstruction": {
47
+ "background": "A sun-drenched suburban sidewalk lined with green hedges and a white picket fence. Dappled light filters through overhead trees.",
48
+ "elements": [
49
+ {"type": "obj", "bbox": [200, 300, 800, 900], "desc": "A golden retriever with a fluffy coat, standing on a red skateboard with all four paws. Its tongue is out and ears are flapping in the wind."},
50
+ {"type": "obj", "bbox": [250, 750, 750, 950], "desc": "A worn red skateboard with black wheels rolling along the concrete sidewalk."}
51
+ ]
52
+ }
53
+ }
54
+
55
+ preset = PRESETS["V4_QUALITY_48"]
56
+ images = pipe(
57
+ json.dumps(caption, separators=(",", ":"), ensure_ascii=False),
58
+ height=1024,
59
+ width=1024,
60
+ num_steps=preset.num_steps,
61
+ guidance_schedule=preset.guidance_schedule,
62
+ mu=preset.mu,
63
+ std=preset.std,
64
+ )
65
+ ```
66
+
67
+ ## Magic prompt
68
+
69
+ Writing these captions by hand is optional. *Magic prompt* uses an LLM to expand
70
+ a plain-text prompt into a full structured caption for you, so you get the
71
+ quality of a JSON prompt from a casual one. It is enabled by default in
72
+ `run_inference.py`; you can also call it directly:
73
+
74
+ ```python
75
+ import os
76
+ from ideogram4 import ClaudeOpusMagicPromptV1, PRESETS
77
+
78
+ magic = ClaudeOpusMagicPromptV1(api_key=os.environ["MAGIC_PROMPT_API_KEY"])
79
+ caption = magic.expand("a golden retriever on a skateboard", aspect_ratio="1:1")
80
+ preset = PRESETS["V4_QUALITY_48"]
81
+ images = pipe(
82
+ caption,
83
+ height=1024,
84
+ width=1024,
85
+ num_steps=preset.num_steps,
86
+ guidance_schedule=preset.guidance_schedule,
87
+ mu=preset.mu,
88
+ std=preset.std,
89
+ )
90
+ ```
91
+
92
+ The package ships three configurations, registered by name in
93
+ `ideogram4.MAGIC_PROMPTS` (the keys `run_inference.py` accepts via
94
+ `--magic-prompt-model`):
95
+
96
+ | Config class | Registry key | Backend |
97
+ | :--- | :--- | :--- |
98
+ | `Ideogram4MagicPromptV1` | `ideogram-4-v1` | Ideogram's hosted magic-prompt API (free; reads `IDEOGRAM_API_KEY`) |
99
+ | `ClaudeOpusMagicPromptV1` | `claude-opus-v1` | [OpenRouter](https://openrouter.ai) (reads `MAGIC_PROMPT_API_KEY`) |
100
+ | `ClaudeSonnetMagicPromptV1` | `claude-sonnet-v1` | [OpenRouter](https://openrouter.ai) (reads `MAGIC_PROMPT_API_KEY`) |
101
+
102
+ `ideogram-4-v1` is the default and is **free**. It runs the expansion
103
+ server-side, so there is no local model or system prompt involved — it just needs
104
+ an Ideogram API key (get one at
105
+ [developer.ideogram.ai](https://developer.ideogram.ai)). The `claude-*`
106
+ configurations instead send one of our open-source system prompt to an OpenRouter model;
107
+ select one with `--magic-prompt-model` and export `MAGIC_PROMPT_API_KEY`:
108
+
109
+ ```bash
110
+ python run_inference.py \
111
+ --prompt "an isometric illustration of a tiny city floating in the clouds" \
112
+ --output out.png \
113
+ --quantization "nf4" \
114
+ --magic-prompt-model claude-opus-v1 \
115
+ --magic-prompt-key "$MAGIC_PROMPT_API_KEY"
116
+ ```
117
+
118
+ See the README's [CLI](../README.md#cli) section for the rest of the flags.
119
+
120
+ Our magic-prompt system prompts are **open source** (they ship in
121
+ `src/ideogram4/magic_prompt_system_prompts/`), so you're also welcome to
122
+ construct the caption with any system prompt and LLM of your choosing.
123
+
124
+ **A few caveats:**
125
+
126
+ - At Ideogram we've tested this magic prompt with **Claude Opus**. You're welcome
127
+ to implement your own `MagicPrompt` configurations and/or drive a different LLM
128
+ with our system prompt, but those paths aren't tested by us and quality may
129
+ vary.
130
+ - The magic prompt shipped here is **not** the same magic prompt used in
131
+ production at [Ideogram.ai](https://ideogram.ai) — results will differ from the
132
+ hosted product (including the `ideogram-4-v1` API).
133
+
134
+ ## JSON caption schema
135
+
136
+ > **Note:** Following this schema is **not required** — the model accepts any
137
+ > string as a prompt. The schema below describes the exact structure the model
138
+ > was trained on, and matching it minimizes train/eval mismatch so the model
139
+ > generates closer to its full quality. Treat the "required" / "must" language
140
+ > in the rest of this section as the format the [`CaptionVerifier`](../src/ideogram4/caption_verifier.py)
141
+ > checks against, not as a hard pipeline constraint. Deviating from the schema
142
+ > is allowed; it just means you're sampling outside the training distribution.
143
+
144
+ The full caption schema has three top-level fields:
145
+
146
+ 1. `high_level_description` — optional string, but strongly recommended.
147
+ 2. `style_description` — optional object.
148
+ 3. `compositional_deconstruction` — **required** object.
149
+
150
+ `compositional_deconstruction` must always be present. Within it, both
151
+ `background` and `elements` are required.
152
+
153
+ ### `high_level_description`
154
+
155
+ A one- or two-sentence summary of the entire image. Strongly recommended in every prompt.
156
+
157
+ ```json
158
+ "high_level_description": "A medium-shot photograph of a barista pouring latte art in a cozy cafe."
159
+ ```
160
+
161
+ ### `style_description`
162
+
163
+ Controls the visual style, lighting, medium, and color palette.
164
+
165
+ `style_description` must contain **exactly one** of:
166
+
167
+ - `photo` — for photographic captions (paired with `medium: "photograph"`).
168
+ - `art_style` — for non-photographic captions (illustration, painting, 3D render, etc.).
169
+
170
+ `aesthetics`, `lighting`, and `medium` are also required when `style_description` is present. `color_palette` is optional.
171
+
172
+ **Key order is strict** and depends on which of `photo` / `art_style` is used:
173
+
174
+ | Caption type | Required key order |
175
+ | :----------- | :----------------- |
176
+ | Photo (uses `photo`) | `aesthetics`, `lighting`, `photo`, `medium`, `color_palette` |
177
+ | Non-photo (uses `art_style`) | `aesthetics`, `lighting`, `medium`, `art_style`, `color_palette` |
178
+
179
+ `color_palette` is the only field in this list that may be omitted; if it is included it must remain in the final position.
180
+
181
+ Field descriptions:
182
+
183
+ | Field | Type | Description |
184
+ | :---- | :--- | :---------- |
185
+ | `aesthetics` | string | Aesthetic keywords (e.g. "moody, cinematic, desaturated") |
186
+ | `lighting` | string | Lighting description (e.g. "golden hour, rim light, dramatic shadows") |
187
+ | `photo` | string | Camera/lens details for photographic outputs (e.g. "35mm, f/1.4, bokeh"). Use this OR `art_style`, not both. |
188
+ | `medium` | string | Medium type: `"photograph"`, `"illustration"`, `"3d_render"`, `"painting"`, `"graphic_design"`, etc. |
189
+ | `art_style` | string | Art style description for non-photo captions (e.g. "flat vector illustration, bold outlines"). Use this OR `photo`, not both. |
190
+ | `color_palette` | list[str] | Hex color codes that steer the image's dominant colors. Up to 16 entries. |
191
+
192
+ ### `compositional_deconstruction`
193
+
194
+ Provides fine-grained spatial control over the image layout using bounding
195
+ boxes and per-element descriptions. Both fields below are required.
196
+
197
+ | Field | Type | Description |
198
+ | :---- | :--- | :---------- |
199
+ | `background` | string | Description of the background/environment (required) |
200
+ | `elements` | list[dict] | List of elements with optional bounding boxes (required) |
201
+
202
+ `background` must come before `elements`.
203
+
204
+ Each element in `elements` must follow a fixed **key order** depending on its
205
+ type. `bbox` and `color_palette` are optional within an element; if present they
206
+ must appear in the positions shown below.
207
+
208
+ | Type | Required key order |
209
+ | :--- | :----------------- |
210
+ | `"obj"` | `type`, `bbox`, `desc`, `color_palette` |
211
+ | `"text"` | `type`, `bbox`, `text`, `desc`, `color_palette` |
212
+
213
+ Field descriptions:
214
+
215
+ | Field | Type | Description |
216
+ | :---- | :--- | :---------- |
217
+ | `type` | string | `"obj"` for objects/subjects, `"text"` for in-image text |
218
+ | `bbox` | list[int] | `[y_min, x_min, y_max, x_max]` in normalized `0–1000` coordinates (origin at top-left). Optional. |
219
+ | `desc` | string | Detailed description of the element |
220
+ | `text` | string | (only for `type: "text"`) The literal text to render |
221
+ | `color_palette` | list[str] | Optional per-element palette. Up to 5 hex entries. |
222
+
223
+ **Key ordering matters.** The model was trained on JSON with a consistent key
224
+ order, so maintaining it improves generation quality. The pipeline runs
225
+ [`CaptionVerifier`](../src/ideogram4/caption_verifier.py) on every prompt and emits
226
+ warnings for unknown keys, missing required keys, or out-of-order keys.
227
+
228
+ **Hex color format.** Colors in `color_palette` must be uppercase
229
+ `#RRGGBB` strings (e.g. `#1B1B2F`, not `#1b1b2f` or `#fff`).
230
+
231
+ **Encoding.** When serializing with Python's `json` module, pass
232
+ `separators=(",", ":")` and `ensure_ascii=False`.
233
+ `CaptionVerifier` warns when it detects `\uXXXX` escapes with no literal
234
+ non-ASCII characters in the raw text.
235
+
236
+ ## Color palette conditioning
237
+
238
+ One of Ideogram 4's distinctive features is **color palette control**. By
239
+ providing a `color_palette` array of hex colors in `style_description`, you
240
+ can steer the dominant colors of the generated image.
241
+
242
+ ```json
243
+ "style_description": {
244
+ "aesthetics": "moody, cinematic",
245
+ "lighting": "low-key, deep shadows",
246
+ "photo": "35mm, f/1.4",
247
+ "medium": "photograph",
248
+ "color_palette": ["#1B1B2F", "#162447", "#1F4068", "#E43F5A", "#F5F5F5"]
249
+ }
250
+ ```
251
+
252
+ Tips for effective color palette use:
253
+
254
+ - **Up to 16 colors** in `style_description.color_palette` for the overall
255
+ image palette, and **up to 5 colors** per element in
256
+ `compositional_deconstruction.elements[*].color_palette`.
257
+ - **Include background colors** — if you want a dark background, include the
258
+ dark hex in the palette.
259
+ - **Contrast pairs** — include both your highlight and shadow colors for more
260
+ controlled lighting.
261
+ - **Uppercase hex only** — `#RRGGBB` form, no shorthand.
262
+
263
+ ### Example: warm sunset palette
264
+
265
+ ```json
266
+ {
267
+ "high_level_description": "A lone sailboat on calm water at sunset.",
268
+ "style_description": {
269
+ "aesthetics": "serene, warm, golden hour",
270
+ "lighting": "golden hour backlighting, warm atmospheric haze",
271
+ "photo": "wide angle, f/8, long exposure",
272
+ "medium": "photograph",
273
+ "color_palette": ["#FF6B35", "#F7C59F", "#004E89", "#1A659E", "#2B2D42"]
274
+ },
275
+ "compositional_deconstruction": {
276
+ "background": "A calm ocean stretching to a low horizon, sky washed in orange and pink with thin wisps of cloud.",
277
+ "elements": [
278
+ {"type": "obj", "desc": "A single sailboat with a white triangular sail, silhouetted against the setting sun."}
279
+ ]
280
+ }
281
+ }
282
+ ```
283
+
284
+
285
+ ### Example: corporate design palette
286
+
287
+ ```json
288
+ {
289
+ "high_level_description": "A clean, modern business card layout for a tech company.",
290
+ "style_description": {
291
+ "aesthetics": "minimal, professional, geometric",
292
+ "lighting": "even, diffuse studio lighting",
293
+ "medium": "graphic_design",
294
+ "art_style": "flat vector design, generous whitespace, sans-serif typography",
295
+ "color_palette": ["#FFFFFF", "#F0F0F0", "#333333", "#0066FF", "#00CC88"]
296
+ },
297
+ "compositional_deconstruction": {
298
+ "background": "A solid off-white card surface with subtle paper texture.",
299
+ "elements": [
300
+ {"type": "text", "text": "ACME TECH", "desc": "Bold dark grey sans-serif company name across the upper third of the card."},
301
+ {"type": "text", "text": "hello@acme.tech", "desc": "Small blue sans-serif contact email near the bottom of the card."}
302
+ ]
303
+ }
304
+ }
305
+ ```
306
+
307
+
308
+
309
+ ## Full example
310
+
311
+ ```json
312
+ {
313
+ "high_level_description": "A medium-shot photograph of Formula 1 driver Max Verstappen wearing his Red Bull Racing racing suit and cap, smiling as he holds his racing helmet and talks to a man in a white shirt and black vest at a race track.",
314
+ "style_description": {
315
+ "aesthetics": "saturated primary colors, rule of thirds, joyful and triumphant",
316
+ "lighting": "overcast daylight, diffused, soft subtle shadows",
317
+ "photo": "shallow depth of field, sharp focus, eye-level, telephoto",
318
+ "medium": "photograph"
319
+ },
320
+ "compositional_deconstruction": {
321
+ "background": "The background is an out-of-focus racing paddock or track environment. Several blurred figures are visible, including one in an orange shirt. A purple and white structure with a red 'F1' logo stands on the left. The scene is outdoors with daylight, though the sky is not visible.",
322
+ "elements": [
323
+ {"type": "obj", "bbox": [55, 642, 1000, 937], "desc": "An older man standing in profile, facing left toward Max Verstappen. He has grey hair and fair skin. He is wearing a white long-sleeved button-down shirt with a navy blue quilted vest over it. He has a slight smile."},
324
+ {"type": "obj", "bbox": [34, 137, 1000, 617], "desc": "Max Verstappen, a fair-skinned male Formula 1 driver, positioned in the center. He is facing forward with a joyful expression and a slight smile. He wears a navy blue Red Bull Racing team uniform with numerous sponsor logos and a matching baseball cap with the number '1'. He is holding a white and red racing helmet in his hands. He has a silver watch on his left wrist."},
325
+ {"type": "obj", "bbox": [422, 212, 792, 452], "desc": "Max Verstappen's racing helmet, held in front of his chest. It features a white, red, and yellow design with the Red Bull logo and the 'Player 0.0' branding. The visor is clear and open."},
326
+ {"type": "text", "bbox": [657, 0, 755, 142], "text": "F1", "desc": "Large, stylized red logo on a black and purple background in the lower left."},
327
+ {"type": "text", "bbox": [768, 0, 818, 147], "text": "Formula 1\nWorld Championship™", "desc": "Small white sans-serif text below the F1 logo on the left side."},
328
+ {"type": "text", "bbox": [78, 447, 117, 510], "text": "ORACLE\nRed Bull\nRacing", "desc": "Very small white and orange logo on the front of the navy blue cap."},
329
+ {"type": "text", "bbox": [78, 417, 120, 440], "text": "1", "desc": "Bold red numeral '1' on the front left side of the navy blue cap."},
330
+ {"type": "text", "bbox": [332, 442, 363, 483], "text": "Red Bull", "desc": "Small yellow and red text logo on the collar of the uniform."},
331
+ {"type": "text", "bbox": [373, 490, 423, 532], "text": "RAUCH", "desc": "Small yellow and blue logo on the right chest of the uniform."},
332
+ {"type": "text", "bbox": [422, 473, 500, 532], "text": "BYBIT\nHONDA", "desc": "Medium-sized white sans-serif text on the right chest of the uniform."},
333
+ {"type": "text", "bbox": [410, 203, 442, 257], "text": "RAUCH", "desc": "Small yellow logo on the left upper arm of the uniform."},
334
+ {"type": "text", "bbox": [530, 448, 627, 510], "text": "Red Bull", "desc": "Medium red text logo on the right side of the torso, part of the Red Bull graphic."},
335
+ {"type": "text", "bbox": [680, 417, 768, 523], "text": "Red Bull", "desc": "Large red text logo across the lower torso of the uniform."},
336
+ {"type": "text", "bbox": [797, 475, 815, 518], "text": "MAX", "desc": "Small white text next to a Dutch flag on the belt area of the uniform."},
337
+ {"type": "text", "bbox": [558, 317, 715, 355], "text": "Player 0.0", "desc": "Black sans-serif text on a white band on the racing helmet."},
338
+ {"type": "text", "bbox": [560, 800, 582, 835], "text": "IA.COM", "desc": "Small blue sans-serif text on the right sleeve of the white shirt."},
339
+ {"type": "text", "bbox": [968, 8, 997, 332], "text": "© Anadolu Agency via Getty Images", "desc": "Small white watermark text in the bottom left corner."}
340
+ ]
341
+ }
342
+ }
343
+ ```
344
+
345
+ ## Safety filter
346
+
347
+ NSFW prompts are blocked. Instead of an image, the model returns a gray screen
348
+ with the text "Image blocked by safety filter". False positive rates for safety
349
+ is higher for non-json like prompts. We are aware that this is an issue an we may
350
+ make a future checkpoint update to improve it.
351
+
352
+ # Congratulations!
353
+
354
+ You are now a certified Ideogram 4 prompter!
355
+
356
+ With structured JSON captions, you have fine-grained control over composition,
357
+ color palettes, typography, and spatial layout — capabilities that go far
358
+ beyond what plain-text prompts can express!
359
+ We'd love to see what you create :-)
360
+ Share your results, experiments, and creative discoveries with the community,
361
+ especially the unexpected ones. Tag us on social media or open a discussion on
362
+ the repo. Happy generating!