How to Use GPT-Image2 Prompt Templates for Automation: A Developer’s Guide

GPT-Image2 ships a machine-readable structured prompt library in docs/templates.md that separates prompts into discrete JSON fields, enabling you to programmatically fill parameters, validate structure, and automate image generation via the api/generate-image.js endpoint or generated agent skills.

The freestylefly/awesome-gpt-image-2 repository provides an industrial-grade automation framework for AI image generation. By treating prompts as structured data rather than raw strings, you gain version-controlled templates, type-safe parameter filling, and direct integration with LLM agents like Claude and Cursor.

Understanding the Structured Template Architecture

At the core of the automation system lies docs/templates.md, which defines every prompt as both human-readable plain text and a JSON schema. For example, the UI Screenshot template (starting at line 24) provides a structured breakdown of fields including type, platform, product, layout, style, content, and constraints.

This dual-format design serves a critical automation purpose: while humans read the Markdown documentation, machines parse the JSON schema to construct valid prompts programmatically. The JSON version eliminates manual string concatenation errors and ensures every required field is populated before reaching the model.

Loading Templates from the Style Library

Before filling parameters, your automation script must locate the correct template schema. The repository indexes all templates in data/style-library.json, which maps template anchors (like tpl-ui or tpl-infographic) to their respective schema definitions.

import styleLibrary from '../data/style-library.json';

// Select the UI Screenshot template by anchor
const uiTemplate = styleLibrary.templates.find(t => t.anchor === 'tpl-ui');

// Access the base JSON schema
const baseSchema = uiTemplate.json;

By referencing the style library, your automation pipeline always uses the latest approved template versions tracked in Git, ensuring consistency across development environments.

Programmatically Filling Template Fields

Once loaded, the JSON schema acts as a type-safe skeleton for your prompt. You populate discrete fields rather than concatenating strings, which enables validation and reusability.

const filled = {
  ...uiTemplate.json,                     // Base schema from docs/templates.md
  platform: 'Web',
  product: 'Dashboard',
  layout: 'Sidebar + Main panel',
  style: {
    theme: 'Light',
    primary_color: '#0066FF',
    typography: 'Roboto'
  },
  content: {
    header: 'Analytics Overview',
    cards: [
      { title: 'Visitors', data: '12k' },
      { title: 'Conversions', data: '3%' }
    ]
  },
  constraints: 'High fidelity, 16:9 aspect ratio'
};

This approach enforces predictable structure—every field is validated before it reaches the generation API, preventing malformed prompts that waste compute resources.

Converting JSON to API-Ready Text Prompts

The api/generate-image.js endpoint (lines 26-38) expects a plain-text prompt payload in the POST body. To bridge the gap between structured JSON and the raw text API, implement a conversion function that flattens your object into the specific format the model expects.

function jsonToPrompt(obj) {
  return `
Type: ${obj.type}
Platform: ${obj.platform}
Product: ${obj.product}
Layout: ${obj.layout}
Theme: ${obj.style.theme}
Primary colour: ${obj.style.primary_color}
Typography: ${obj.style.typography}
Header: ${obj.content.header}
Cards: ${obj.content.cards.map(c => c.title + ':' + c.data).join(', ')}
Constraints: ${obj.constraints}
`.trim();
}

const promptText = jsonToPrompt(filled);

This transformation step maintains the separation between your structured data (which lives in version control) and the runtime API requirements.

Executing the Image Generation

With the prompt text constructed, send the payload to the generation endpoint. The handler in api/generate-image.js forwards the request to the underlying image service and returns the resulting URL.

fetch('/api/generate-image', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ 
    prompt: promptText, 
    caseId: 123 
  })
})
.then(r => r.json())
.then(res => {
  if (res.ok) {
    console.log('✅ Image URL:', res.image);
  } else {
    console.error('❌ Generation error:', res.error);
  }
});

Generating Reusable Agent Skills

For teams using Claude, Cursor, or other LLM-as-tool frameworks, the repository includes scripts/generate-style-skill.mjs (lines 7-13). This utility reads docs/templates.md and automatically generates a skill package exposing each template as a callable function.

node scripts/generate-style-skill.mjs

The resulting skill allows direct function calls like uiScreenshot({platform: 'iOS', product: 'Fitness App'}) without manually handling JSON conversion. This creates plug-and-play skills that non-technical team members can invoke through natural language while the automation handles the underlying API structure.

Summary

  • Structured templates in docs/templates.md provide JSON schemas that validate prompt fields before generation.
  • Version-controlled schemas via data/style-library.json ensure automation pipelines always use approved template versions.
  • Programmatic filling of discrete fields (platform, style, content) eliminates string concatenation errors.
  • Runtime conversion functions bridge JSON structures and the plain-text prompt parameter expected by api/generate-image.js.
  • Skill generation via scripts/generate-style-skill.mjs exposes templates as callable functions for LLM agents.

Frequently Asked Questions

How does the JSON schema prevent prompt errors?

The JSON schema in docs/templates.md defines required fields and data types for each template. When your automation script populates these fields programmatically, you can validate the structure before sending it to api/generate-image.js, ensuring the model receives complete prompts without missing constraints or malformed content descriptors.

Can I use these templates with LLM agents like Claude or Cursor?

Yes. Run scripts/generate-style-skill.mjs to generate a skill package that exposes each template as a typed function. The generated skill (lines 7-13 of the script) handles the JSON-to-text conversion internally, allowing agents to call specific templates directly with natural language parameters.

What is the difference between the style library and the templates file?

The data/style-library.json serves as an index that maps template anchors (like tpl-ui) to their source locations, while docs/templates.md contains the actual JSON schemas and human-readable documentation. Your automation should query the library to locate templates, then reference the Markdown file for the full schema definition.

Does the API accept JSON directly or require text conversion?

According to the source code in api/generate-image.js (lines 26-38), the endpoint accepts a plain-text prompt field in the POST body. You must convert your filled JSON template to a formatted string using a function like jsonToPrompt() before sending the request, as the underlying service expects structured natural language rather than raw JSON.

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:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →