Understanding the Structure of a Generated Prompt by the GPT-Image2 Skill
The GPT-Image2 skill constructs a JSON payload containing five mandatory fields and two optional fields through the buildApimartGenerationPayload function located in shared/apimart.js.
The freestylefly/awesome-gpt-image-2 repository provides a skill for generating images via the Apimart API. Understanding the structure of a generated prompt by the GPT-Image2 skill reveals how raw user input transforms into a structured API request compatible with the gpt-image-2 model.
Structure of a Generated Prompt: Core Payload Components
Every prompt generated by the skill follows a consistent JSON schema defined in shared/apimart.js. The payload always includes five fixed parameters that control the generation behavior, with optional extensions for localization and callbacks.
Mandatory Fields
The buildApimartGenerationPayload function creates an object with the following required properties:
model: Fixed string value"gpt-image-2"identifying the target model.prompt: The user-supplied text trimmed of leading and trailing whitespace viaString(prompt || '').trim().n: Hardcoded integer1specifying the number of images to generate per request.size: Fixed aspect ratio string"1:1"producing square images.resolution: Default quality bucket"1k"representing approximately 1024 pixels.
Optional Configuration Fields
The payload dynamically appends two additional fields when provided in the options parameter:
language: Accepts"zh"for Chinese or"en"for English, normalized viaoptions.language === 'zh' ? 'zh' : 'en'.webhook: A callback URL string where Apimart POSTs the generation result upon completion.
Implementation in shared/apimart.js
The payload construction logic resides in shared/apimart.js within the exported buildApimartGenerationPayload function. This utility transforms raw input into the standardized format required by the Apimart image-generation API.
export function buildApimartGenerationPayload(prompt, options = {}) {
const payload = {
model: APIMART_MODEL, // → "gpt-image-2"
prompt: String(prompt || '').trim(),
n: 1,
size: '1:1',
resolution: '1k'
};
if (options.webhook) payload.webhook = options.webhook;
if (options.language) payload.language = options.language === 'zh' ? 'zh' : 'en';
return payload;
}
The function uses a defensive default for the prompt parameter, ensuring empty or undefined inputs convert to empty strings before trimming.
Practical Code Examples
Basic English Prompt
This example demonstrates a standard generation request with English language support:
const payload = buildApimartGenerationPayload(
'a futuristic city skyline at sunset',
{ language: 'en' }
);
// Result:
// {
// model: 'gpt-image-2',
// prompt: 'a futuristic city skyline at sunset',
// n: 1,
// size: '1:1',
// resolution: '1k',
// language: 'en'
// }
Chinese Prompt with Webhook
This configuration includes both language specification and an asynchronous callback URL:
const payload = buildApimartGenerationPayload(
'一只在月光下漫步的狐狸',
{ language: 'zh', webhook: 'https://myapp.example.com/callback' }
);
// Result:
// {
// model: 'gpt-image-2',
// prompt: '一只在月光下漫步的狐狸',
// n: 1,
// size: '1:1',
// resolution: '1k',
// language: 'zh',
// webhook: 'https://myapp.example.com/callback'
// }
Architecture Overview
Three primary files coordinate the prompt generation and delivery process:
shared/apimart.js: Contains thebuildApimartGenerationPayloadfunction that defines the structure of a generated prompt by the GPT-Image2 skill.src/apimartClient.js: Invokes the payload builder and manages HTTP transmission to the Apimart API endpoint.api/generate-image.js: Handles incoming client requests, extracts the raw prompt, and orchestrates the generation workflow using the payload builder.
Summary
- The GPT-Image2 skill generates a standardized JSON payload with five mandatory fields:
model,prompt,n,size, andresolution. - Optional
languageandwebhookfields append dynamically based on theoptionsparameter passed to the builder function. - The
buildApimartGenerationPayloadfunction inshared/apimart.jshandles all payload construction and input sanitization through defensive string coercion. - The skill exclusively uses the
"gpt-image-2"model with square (1:1) aspect ratio and1kresolution defaults for all generations. - Three files—
shared/apimart.js,src/apimartClient.js, andapi/generate-image.js—form the complete request pipeline from client request to API delivery.
Frequently Asked Questions
What are the default values for image generation in the GPT-Image2 skill?
The skill defaults to generating one square image (n: 1, size: "1:1") at approximately 1024px resolution (resolution: "1k") using the gpt-image-2 model. These values are hardcoded in the buildApimartGenerationPayload function and apply to every request unless the underlying API implementation changes.
How does the skill handle empty or undefined prompts?
The function applies defensive programming by converting the input via String(prompt || '').trim(). This ensures undefined or null values become empty strings rather than causing runtime errors, and removes accidental leading or trailing whitespace that might affect generation quality.
Can the GPT-Image2 skill generate multiple images per request?
No, the current implementation explicitly sets n: 1 in all payloads. The skill architecture currently limits generation to single images regardless of user preferences or API capabilities, as enforced by the hardcoded value in shared/apimart.js.
Where should I configure the webhook URL for asynchronous results?
Pass the webhook option when calling buildApimartGenerationPayload. The function checks if (options.webhook) and adds the field directly to the payload object. The URL must be fully qualified (including protocol) and accessible from the Apimart API servers to receive the POST callback upon generation completion.
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 →