How to Specify Platform-Specific Requirements for Image Generation in GPT-Image-2

You specify platform-specific requirements for image generation by modifying the size, quality, and format parameters in the generateImage() function inside api/generate-image.js before deploying to Vercel.

The freestylefly/awesome-gpt-image-2 repository provides a Vercel serverless function that proxies requests to the GPT-Image-2 API. Understanding how to specify platform-specific requirements for image generation allows you to tailor output resolution, compression, and file format to match the constraints of web dashboards, mobile applications, or print media.

Understanding the Image Generation Flow

Image generation is handled by the Vercel serverless function located at api/generate-image.js. Inside this file, the generateImage() helper function (defined at lines 27-42) constructs the payload sent to the upstream GPT-Image-2 service.

The request body contains three critical fields that control the platform-specific requirements:

body: JSON.stringify({
  model: 'gpt-image-2',
  prompt,
  n: 1,
  size: '1024x1024',   // ← resolution
  quality: 'low',      // ← compression quality
  format: 'jpeg'       // ← output format
})

These values are currently hard-coded in the source code, meaning every image generation request uses the same specifications unless you modify the function.

Platform-Specific Parameters Explained

Image Resolution (size)

The size parameter defines the output dimensions as a string in WIDTHxHEIGHT format. The default value is '1024x1024'.

  • Use '1024x1024' for standard web content
  • Use '512x512' for thumbnails or mobile-optimized assets
  • Use '1792x1024' or wide aspect ratios for banner images

Compression Quality (quality)

The quality parameter controls the compression level and file size. Valid values are 'low', 'medium', and 'high'.

  • low: Fastest generation, smallest file size, artifacting present (default)
  • medium: Balanced quality for most web applications
  • high: Maximum fidelity for print or editorial platforms

Output Format (format)

The format parameter determines the file encoding. Supported values include 'jpeg', 'png', and 'webp'.

  • jpeg: Best for photographs, smallest file size (default)
  • png: Lossless compression required for editing workflows or transparency
  • webp: Modern web format for bandwidth-constrained platforms

Modifying Platform-Specific Requirements

Method 1: Hardcode Values for Static Requirements

For applications where all generated images share the same specifications, edit the payload directly in api/generate-image.js:

  1. Open api/generate-image.js and locate the generateImage() function
  2. Modify the size, quality, or format values to match your target platform

Example for a high-resolution PNG suitable for design tools:

body: JSON.stringify({
  model: 'gpt-image-2',
  prompt,
  n: 1,
  size: '1792x1024',
  quality: 'high',
  format: 'png'
})

Method 2: Expose Parameters via API Request

To allow dynamic platform-specific requirements per request, refactor the function to accept an options object. First, update the request handler to parse incoming parameters:

// In api/generate-image.js request handler
const { prompt, caseId, size = '1024x1024', quality = 'low', format = 'jpeg' } = body;

Then pass these values to the generation function:

const image = await generateImage(prompt, { size, quality, format });

Finally, update generateImage() to accept and utilize the options object when constructing the upstream payload.

Deployment Considerations

Since the generation logic runs as a Vercel serverless function, changes to api/generate-image.js require a new deployment. Push your modifications to the main branch or trigger a manual redeploy through the Vercel dashboard.

Note that environment variables defined in .env.example (such as CIYUAN_API_KEY and CIYUAN_BASE_URL) configure authentication and routing only. These variables do not affect the image-specific generation parameters, which must be modified in the source code itself.

Summary

  • Platform-specific requirements in GPT-Image-2 are controlled by three fields: size, quality, and format in api/generate-image.js
  • Default values are '1024x1024' resolution, 'low' quality, and 'jpeg' format
  • Modify the hard-coded values in the generateImage() function for static requirements
  • Refactor to accept request body parameters for dynamic, caller-defined specifications
  • Any code changes require redeployment to Vercel to take effect
  • Environment variables only handle API keys and URLs, not image generation parameters

Frequently Asked Questions

How do I generate images for mobile apps with smaller file sizes?

Set the size parameter to '512x512' and keep quality at 'low' in the api/generate-image.js payload. This reduces both dimensions and compression artifacts while maintaining acceptable visual quality for mobile screens. You can also switch the format to 'webp' for additional bandwidth savings on modern mobile platforms.

Can I change image specifications without redeploying the code?

No. Because the size, quality, and format values are hard-coded in api/generate-image.js according to the current implementation, any modification to these platform-specific requirements requires editing the source file and redeploying the Vercel function. To avoid redeployment, refactor the code to read these values from the request body or environment variables.

What file formats are supported for platform-specific image generation?

According to the source code in freestylefly/awesome-gpt-image-2, the API accepts 'jpeg', 'png', and 'webp' for the format field. JPEG is the default and works best for photographic content, while PNG provides lossless quality necessary for graphic design workflows. WebP offers superior compression for web platforms.

Where are the image generation settings configured if not in .env files?

The image generation settings are hard-coded in the generateImage() function within api/generate-image.js (lines 27-42). The .env.example file only contains environment variables for CIYUAN_API_KEY and CIYUAN_BASE_URL, which handle authentication and API routing, not the visual specifications of the generated images.

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 →