How to Build Prompts Using Subject, Composition, Style, and Constraints for GPT-Image2

GPT-Image2 uses an atomic schema that splits prompts into composable subject‑composition objects—subject, lighting, materials, layout, visual details, and constraints—making them machine‑readable, reusable, and automation‑friendly.

The freestylefly/awesome-gpt-image-2 repository implements a structured prompt architecture that replaces prose‑style descriptions with a JSON‑based protocol. This approach compresses natural language into predictable data structures that integrate cleanly with API clients, batch pipelines, and agent workflows.

Understanding the Subject-Composition Architecture

The core innovation is the atomic schema: instead of writing free‑form text like "a cyberpunk car on a neon street, no watermarks please," you construct a JavaScript object with explicit fields. Each field maps to a distinct visual dimension, allowing precise control over generation.

Component Purpose JSON Key
subject Central object or scene to render subject
lighting Direction, quality, and color temperature lighting
materials Surface properties (metal, fabric, glass) materials
layout Positioning, perspective, composition rules layout
visualDetails Texture, color, mood modifiers details
constraints Hard rules that override other fields constraints

The README emphasizes this design: "Atomic schema: split subjects, lighting, materials, layout, and visual details into composable parts" 【1†L62-L64】. This separation enables template reuse—you can swap only the subject while preserving a proven lighting and layout configuration.

Building the Four Core Prompt Components

Subject Definition

The subject field is the mandatory anchor. It describes what appears in the image, not how it looks. Keep it concrete and noun‑heavy: "A futuristic hover‑car" rather than "Something futuristic and cool".

Composition Through Layout

The layout field encodes composition rules directly: "centered, low angle, 16:9 aspect" or "3‑quarter view, rule‑of‑thirds". This replaces vague positional language with standardized terms the engine parses consistently.

Style Enforcement

Styles operate at two levels. First, implicit style emerges from lighting + materials + details combinations. Second, explicit style constraints in the constraints.style field force a specific visual mode like "graffiti‑sketch" or "oil‑painting". The constraint overrides any stylistic drift in other fields.

Constraint Specifications

Constraints are plain objects that act as hard rules—they take precedence over loosely‑matched descriptions elsewhere in the prompt. The docs/templates.md file documents supported constraint keys, while src/apimartClient.js merges them into the final HTTP payload 【2†L103-L111】.

Common constraint keys include:

  • noWatermark — Boolean guarantee against invisible marks
  • exclude — Array of forbidden elements (["text", "logo", "humans"])
  • maxResolution — Output size cap for cost control ("1024x1024")
  • style — Forced visual mode that overrides ambient style signals

Complete Implementation Examples

Example 1: Simple Subject with No‑Watermark Constraint

import { submitPersonalGeneration } from './src/apimartClient.js';

const prompt = {
  subject: "A futuristic hover‑car on a neon‑lit city street",
  lighting: "neon backlight, soft rim",
  materials: "metallic carbon‑fiber body, glowing LED accents",
  layout: "centered, low angle, 16:9 aspect",
  details: "rain‑slick street, reflections, cyber‑punk vibe",
  constraints: {
    noWatermark: true,
    exclude: ["text", "logo"]
  }
};

await submitPersonalGeneration(
  JSON.stringify(prompt),
  process.env.APIMART_API_KEY,
  "en"
);

The submitPersonalGeneration function stringifies the prompt object internally, wraps it with authentication headers, and POSTs to the APIMart generation endpoint.

Example 2: Platform Generation with Style Lock

import { submitPlatformGeneration } from './src/apimartClient.js';

const payload = {
  caseId: 101,
  prompt: {
    subject: "Portrait of a samurai in traditional armor",
    lighting: "soft side light, golden hour",
    materials: "silk, iron, polished lacquer",
    layout: "3‑quarter view, rule‑of‑thirds",
    details: "misty background, subtle brush‑stroke texture",
    constraints: {
      style: "graffiti‑sketch",
      maxResolution: "1024x1024"
    }
  },
  language: "en"
};

await submitPlatformGeneration(payload);

The caseId references a pre‑defined template in the platform account, while the nested prompt object injects case‑specific subject and composition data. The constraints.style field forces the graffiti aesthetic regardless of the traditional materials described.

Automation Pipeline Integration

The subject‑composition style is designed for programmatic prompt construction. According to the repository README, this structure supports "compressing prose‑style prompts into structured protocols" for reuse in batch jobs or agent workflows 【1†L58-L61】.

Key integration points:

When building prompts dynamically, construct the object programmatically, validate against the schema, then pass to submitPersonalGeneration or submitPlatformGeneration depending on your API access tier.

Best Practices for Constraint Usage

  • Place hard requirements in constraints, not descriptions — "noWatermark: true" is enforceable; "clean image without watermarks" in details is not
  • Use exclude arrays for negative prompting — More reliable than negative descriptions in free text
  • Lock style constraints only when necessary — Over‑constraining reduces creative variation from the underlying model
  • Version your prompt objects — The atomic structure diffs cleanly, enabling A/B testing of component changes

Summary

  • Subject‑composition style replaces prose prompts with structured JSON objects containing subject, lighting, materials, layout, details, and constraints fields
  • src/apimartClient.js implements the client‑side payload building and constraint injection 【2†L103-L111】
  • Constraints act as hard rules via keys like noWatermark, exclude, maxResolution, and style
  • Two API methods support different authentication modes: submitPersonalGeneration for API keys, submitPlatformGeneration for platform tokens
  • Agent and automation ready through documented schemas in docs/templates.md and skill definitions in agents/skills/

Frequently Asked Questions

What happens if constraints conflict with other prompt fields?

Constraints always win. The GPT-Image2 backend interprets constraint objects as hard rules that override loosely‑matched descriptions in lighting, details, or other fields. For example, a style: "graffiti‑sketch" constraint forces that aesthetic even if materials describes polished lacquer.

Can I use the subject‑composition style without the apimartClient wrapper?

Yes—apimartClient.js is a convenience wrapper. The underlying API accepts any JSON payload matching the schema documented in docs/templates.md. You can construct and POST the object manually, though the wrapper handles stringification, header injection, and error formatting that you'd otherwise implement yourself.

How do I discover valid constraint keys for my use case?

Reference docs/templates.md in the repository, which documents supported constraint keys and their expected value types. The agents/skills/gpt-image-2-style-library/SKILL.md file also exposes constraint patterns designed for agent interaction. Not all constraints are available on all API tiers—platform accounts typically access more resolution and style options than personal keys.

Is the atomic schema backward‑compatible with text‑only prompts?

No—GPT-Image2's generation engine expects the structured object format. Free‑form text passed where a subject‑composition object is required will fail validation or produce degraded results. The repository's explicit goal is "compressing prose‑style prompts into structured protocols" rather than supporting legacy text interfaces 【1†L58-L61】.

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 →