Generate image
POST /api/ai/image/generate — submit a text-to-image or image-to-image task across GPT Image 2 and Nano Banana models.
Submits a new image generation task. Credits are pre-debited on submission and refunded automatically if the upstream provider fails the task.
Supported models
| Model ID | Modes | Max refs | Prompt cap | Credit rule |
|---|---|---|---|---|
gpt-image-2 | text-to-image, image-to-image | 4 | 20,000 chars | Flat 3 credits per call |
nano-banana-2 | text-to-image, image-to-image | 14 | 20,000 chars | 4 / 6 / 8 credits by 1K / 2K / 4K |
nano-banana-pro | text-to-image, image-to-image | 8 | 10,000 chars | 12 / 20 credits by 2K / 4K |
google/nano-banana | text-to-image, image-to-image | 10 | 5,000 chars | Flat 3 credits per call |
GPT Image 2 profile
When model is gpt-image-2, this endpoint behaves as a single unified text/edit API:
inputImageUrlsomitted: text-to-image mode.inputImageUrlspresent: image-to-image edit mode, up to4reference images.aspectRatiosupportsauto,1:1,16:9,9:16,4:3,3:4,3:2,2:3,4:5,5:4, and21:9.- Current public pricing is a flat
3credits per request.
Field notes
promptis required for every model.inputImageUrlsis the only field that switches the endpoint from generation to editing.aspectRatiois the safest cross-model layout control. Resolution, output format, and similar knobs are model-specific.providerInputis an advanced passthrough for provider-specific overrides. It is not schema-validated, so only use it if you control the upstream contract.- The submitted task response includes
creditsUsed. Use that value instead of reimplementing billing logic client-side.
Authorization
bearerAuth API keys are in closed beta — send your key as Authorization: Bearer <key>. In the meantime, first-party usage from the web dashboard is authenticated via session cookie. See Authentication for details.
In: header
Request Body
application/json
TypeScript Definitions
Use the request body type in TypeScript.
Response Body
application/json
application/json
application/json
application/json
application/json
curl -X POST "https://gptimage2api.org/api/ai/image/generate" \ -H "Content-Type: application/json" \ -d '{ "prompt": "A luxury skincare bottle on warm paper, embossed serif label, soft editorial side light", "model": "gpt-image-2", "aspectRatio": "4:5" }'{
"taskId": "tsk_01J9XA5M2R9W4QZC4PYJF3N7ND",
"status": 0,
"creditsUsed": 12
}{
"error": "Invalid request",
"details": {}
}{
"error": "Unauthorized"
}{
"error": "Insufficient credits",
"required": 12
}{
"error": "string"
}