Maximum Prompt Length for GPT-Image2: Hard Limits and Validation
The maximum prompt length for GPT-Image2 is strictly capped at 10,000 characters.
The freestylefly/awesome-gpt-image-2 repository implements strict prompt validation to prevent oversized payloads from reaching the underlying APIMart service. Understanding this limit is essential for developers integrating with the image generation API, as exceeding the threshold triggers immediate request rejection.
Where the Limit is Defined
The character ceiling is hard-coded at line 5 of shared/apimart.js as the exported constant APIMART_MAX_PROMPT_LENGTH. This centralized definition establishes a single source of truth for the APIMart service constraints across the entire codebase.
// shared/apimart.js (line 5)
export const APIMART_MAX_PROMPT_LENGTH = 10_000;
By referencing this constant rather than scattering magic numbers throughout the application, the repository ensures that validation logic remains synchronized with the external API’s requirements.
How the Limit is Enforced
Before any image generation request reaches the external API, the reserveGeneration function validates the prompt length at line 117 of api/generate-image.js. The function checks if the prompt exceeds APIMART_MAX_PROMPT_LENGTH and throws an error immediately if the constraint is violated.
// api/generate-image.js
import { APIMART_MAX_PROMPT_LENGTH } from '../shared/apimart.js';
export async function reserveGeneration(client, profile, userId, caseId, prompt) {
if (!prompt || prompt.length > APIMART_MAX_PROMPT_LENGTH || !Number.isFinite(caseId)) {
throw new Error('Invalid prompt or case ID');
}
// Proceed with generation...
}
This preemptive validation prevents unnecessary network calls and ensures the APIMart backend never receives malformed requests that would inevitably fail.
Validating Prompts Client-Side
To avoid runtime errors, implement validation logic that mirrors the server's checks. The following pattern trims whitespace and verifies length constraints before submission:
import { APIMART_MAX_PROMPT_LENGTH } from '../shared/apimart.js';
function isPromptValid(prompt) {
const trimmed = String(prompt || '').trim();
return trimmed.length > 0 && trimmed.length <= APIMART_MAX_PROMPT_LENGTH;
}
// Usage
const userPrompt = 'Your detailed image description here...';
if (!isPromptValid(userPrompt)) {
throw new Error(`Prompt must be between 1 and ${APIMART_MAX_PROMPT_LENGTH} characters`);
}
Summary
- The maximum prompt length for GPT-Image2 is 10,000 characters, represented as
10_000in JavaScript numeric literal notation. - The constant
APIMART_MAX_PROMPT_LENGTHinshared/apimart.jsserves as the authoritative source for this limit. - The
reserveGenerationfunction inapi/generate-image.jsenforces this constraint before transmitting requests to the APIMart service. - Client-side validation should check that prompts contain between 1 and 10,000 characters after trimming whitespace.
Frequently Asked Questions
What is the maximum prompt length for GPT-Image2?
The maximum prompt length for GPT-Image2 is 10,000 characters. This hard limit is enforced by the underlying APIMart service and validated in both the client and server code within the freestylefly/awesome-gpt-image-2 repository.
Where is the prompt length limit defined in the codebase?
The limit is defined in shared/apimart.js as the exported constant APIMART_MAX_PROMPT_LENGTH. This centralized definition allows the value to be imported and reused across validation functions, ensuring consistency between client-side checks and server-side enforcement.
What happens if I exceed the 10,000 character limit?
If a prompt exceeds 10,000 characters, the reserveGeneration function in api/generate-image.js throws an error with the message "Invalid prompt or case ID". The request is rejected before reaching the external APIMart API, preventing unnecessary network overhead and API errors.
Can I configure or increase the prompt length limit?
No. The 10,000 character maximum is a fixed constraint of the external APIMart service, not a configurable application setting. The APIMART_MAX_PROMPT_LENGTH constant reflects this external limitation and should not be modified, as the upstream service will reject payloads exceeding this size regardless of local configuration changes.
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 →