How to Use the JSON Template for Programmatic GPT-Image2 Prompts: A Complete Developer Guide
The JSON template for programmatic GPT-Image2 prompts provides a structured, machine-readable schema that eliminates prompt ambiguity and enables reproducible image generation through automated agents.
The awesome-gpt-image-2 repository by freestylefly delivers industrial-grade prompt templates designed for both manual and automated workflows. The JSON variants serve as deterministic contracts between agents and the GPT-Image2 model, encoding layout, style, and content constraints in a parseable format. This guide walks you through the architectural design, practical implementation patterns, and key source files you need to integrate these templates into your own applications.
JSON Template Architecture in awesome-gpt-image-2
Central Prompt Template Store
All prompt templates reside in docs/templates.md. Each template ships with two representations:
- Textual version — human-readable prose for manual copy-paste workflows
- JSON version — marked with "JSON 进阶模板(推荐给 Agent 调用)" for programmatic consumption
The JSON template acts as a parameterized contract. Instead of free-form text, you supply typed fields (type, platform, style, content, constraints) that the model interprets deterministically. This reduces "prompt hallucination" where vague descriptions produce inconsistent outputs.
Style Library Skill Integration
The agents/skills/gpt-image-2-style-library/SKILL.md implements the primary agent-side consumer of JSON templates. Its pipeline:
- Receives a partial or complete JSON payload
- Validates against available style tokens from
data/style-library.json - Fills missing fields using the style library
- Forwards the finalized JSON to the GPT-Image2 API
The reference documentation at agents/skills/gpt-image-2-style-library/references/style-library.md is auto-generated from data/style-library.json. This guarantees that website users and programmatic agents operate from identical style definitions.
JSON Template Structure and Required Fields
The canonical template follows this schema (source: lines 26-46 in docs/templates.md):
{
"type": "UI Screenshot",
"platform": "iOS",
"product": "Fitness App",
"layout": "Card-based feed with bottom tab bar",
"style": {
"theme": "Dark Mode",
"primary_color": "Neon Green",
"typography": "Clean sans-serif"
},
"content": {
"header": "Today's Activity",
"cards": [
{"title": "Running", "data": "5.2 km", "button": "Start"},
{"title": "Calories", "data": "340 kcal"}
]
},
"constraints": "High fidelity, readable text, 9:16 aspect ratio"
}
Key field definitions:
type— Image category (UI Screenshot, Illustration, Photo, etc.)platform— Target platform when applicable (iOS, Android, Web, etc.)layout— Structural description of compositionstyle— Nested object for visual properties (theme, colors, typography)content— Nested object for actual data/text to renderconstraints— Quality directives and technical requirements
Implementation Patterns
Pattern 1: Direct API Integration (Node.js)
For applications that manage their own OpenAI client configuration, send the JSON template directly as the prompt payload:
import fetch from 'node-fetch';
const jsonPrompt = {
type: "UI Screenshot",
platform: "iOS",
product: "Fitness App",
layout: "Card-based feed with bottom tab bar",
style: {
theme: "Dark Mode",
primary_color: "Neon Green",
typography: "Clean sans-serif"
},
content: {
header: "Today's Activity",
cards: [
{title: "Running", data: "5.2 km", button: "Start"},
{title: "Calories", data: "340 kcal"}
]
},
constraints: "High fidelity, readable text, 9:16 aspect ratio"
};
const response = await fetch('https://api.openai.com/v1/images/generations', {
method: 'POST',
headers: {
'Authorization': `Bearer ${process.env.OPENAI_API_KEY}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
model: "gpt-image-2",
prompt: JSON.stringify(jsonPrompt)
})
});
const result = await response.json();
console.log(result.data[0].url);
Note: Stringify the JSON prompt before passing to the API. The GPT-Image2 model accepts the prompt as a string and infers the structured intent from the JSON formatting.
Pattern 2: Skill-Based Integration (Python)
Leverage the repository's built-in validation and style resolution:
import json
import os
from agents.skills.gpt_image_2_style_library import StyleLibrarySkill
# Initialize skill with auto-loaded style library
skill = StyleLibrarySkill()
# Minimal prompt — skill fills style tokens from style-library.json
partial_prompt = {
"type": "UI Screenshot",
"platform": "iOS",
"product": "Fitness App",
"style": {
"theme": "Dark Mode"
# skill auto-resolves primary_color, typography from theme
},
"constraints": "9:16 aspect ratio"
}
result = skill.run(json.dumps(partial_prompt))
print(f"Image URL: {result['url']}")
print(f"Resolved style: {result['resolved_style']}")
The skill pattern provides three advantages over raw API calls:
- Validation — catches unknown type/platform combinations before API request
- Style resolution — expands shorthand references into complete style definitions
- Caching — avoids redundant lookups to
data/style-library.json
Key Source Files for Template Customization
| File | Purpose | When to Reference |
|---|---|---|
docs/templates.md |
Complete template catalog with JSON examples | Selecting base template for your use case |
data/style-library.json |
Source of truth for all style tokens, categories, scene tags | Extending available styles or validating custom tokens |
agents/skills/gpt-image-2-style-library/SKILL.md |
Skill implementation and configuration | Integrating the skill into your agent framework |
agents/skills/gpt-image-2-style-library/references/style-library.md |
Human-readable style reference | Understanding available style combinations without parsing JSON |
Extending the JSON Template System
To add custom templates compatible with the skill architecture:
-
Define your schema in
docs/templates.mdfollowing the nested object pattern (type → platform → style → content → constraints) -
Register style tokens in
data/style-library.jsonif introducing new visual categories -
Regenerate references — the build process updates
style-library.mdautomatically -
Test through the skill to ensure validation passes before production deployment
Summary
- JSON templates in awesome-gpt-image-2 provide deterministic, machine-readable prompts for automated GPT-Image2 workflows
- Dual entry points exist: direct API calls for full control, or the Style Library Skill for built-in validation and style resolution
- Core schema requires
type,platform,layout,style,content, andconstraintsfields for consistent output - Source files
docs/templates.mdanddata/style-library.jsonserve as the authoritative template and style definitions - Skill integration at
agents/skills/gpt-image-2-style-library/SKILL.mdhandles validation, auto-completion, and API forwarding
Frequently Asked Questions
What is the difference between the text and JSON templates?
The text templates are prose descriptions optimized for human readability and manual copying into chat interfaces. The JSON templates encode the same intent as structured data with explicit fields, making them parseable by agents and eliminating ambiguity. According to the repository documentation, JSON templates are specifically recommended for agent invocation ("推荐给 Agent 调用").
How does the Style Library Skill validate my JSON prompt?
The skill loads data/style-library.json at initialization and checks supplied values against available tokens. For example, if you specify "theme": "Dark Mode", the skill verifies this theme exists and can auto-populate related fields like primary_color and typography from the library's definitions. Invalid combinations trigger errors before any API call occurs.
Can I use partial JSON prompts with the skill?
Yes. The skill is designed for incremental completion. You can supply minimal fields (e.g., only type and platform) and the skill resolves the rest using context from style-library.json. This enables flexible agent behaviors where user intent is captured incompletely but executed completely.
Where are the style definitions sourced from?
All style tokens live in data/style-library.json. This file is the single source of truth shared between the website frontend and the agent skill. The human-readable reference at agents/skills/gpt-image-2-style-library/references/style-library.md is generated from this JSON file, ensuring no drift between documentation and runtime behavior.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →