API Reference
Use the GPT Image 2 API with your own API key, OpenAI-style request parameters, and credits-based billing.
Overview
The GPT Image 2 API lets you generate images through your GPT Image 2 account. Requests use your site API key and are routed through our server-side Kie integration.
Create an API key from:
/settings/apikeysThen call:
POST /api/v1/images/generations
GET /api/v1/images/tasks/{task_id}Image generation is asynchronous. The create endpoint returns a task id, and the task endpoint returns the final image URLs when generation succeeds.
Authentication
Send your GPT Image 2 API key as a Bearer token:
Authorization: Bearer sk-xxxDo not expose API keys in browser-side code. Use them from your backend, scripts, or serverless functions.
Billing
API usage consumes the same credits as the web app:
| Operation | Credit cost |
|---|---|
| Image generation | 10 credits per image |
If a provider request fails before a task is accepted, consumed credits are refunded automatically by the task failure flow.
Create Image Generation
Endpoint
POST https://gpt-image-2.art/api/v1/images/generationsRequest Body
| Parameter | Type | Required | Description |
|---|---|---|---|
model | string | No | Use gpt-image-2. Internal aliases gpt-image-2-text-to-image and gpt-image-2-image-to-image are also supported. |
prompt | string | Yes | Text description of the image. Required unless image_urls are provided. |
image_urls | string[] | No | Reference image URLs for image-to-image generation. |
n | integer | No | Number of images to generate, from 1 to 10. Default: 1. |
size | string | No | One of 1024x1024, 1536x1024, 1024x1536, 1920x1088, 1088x1920, 3824x2160, 2160x3824, or auto. |
quality | string | No | Provider quality option, for example high or auto. |
output_format | string | No | png, jpeg, or webp when supported by the provider. |
response_format | string | No | Only url is supported. |
user | string | No | Optional end-user identifier for your own tracking. |
Text-to-Image Example
curl https://gpt-image-2.art/api/v1/images/generations \
-H "Authorization: Bearer $GPT_IMAGE_2_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"prompt": "A cinematic product photo of a matte black coffee bag on a marble counter",
"size": "1536x1024",
"quality": "high",
"n": 1
}'Image-to-Image Example
curl https://gpt-image-2.art/api/v1/images/generations \
-H "Authorization: Bearer $GPT_IMAGE_2_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"prompt": "Keep the product unchanged and place it on a clean studio background",
"image_urls": ["https://example.com/product.png"],
"size": "1024x1024",
"n": 1
}'Create Response
{
"id": "8f6d9f87-1b3f-4f89-bdfb-3df8e77b7af3",
"object": "image.generation",
"created": 1714000000,
"model": "gpt-image-2-text-to-image",
"status": "pending",
"credits": 10,
"data": []
}Save the id and poll the task endpoint.
Query Image Task
Endpoint
GET https://gpt-image-2.art/api/v1/images/tasks/{task_id}Example
curl https://gpt-image-2.art/api/v1/images/tasks/8f6d9f87-1b3f-4f89-bdfb-3df8e77b7af3 \
-H "Authorization: Bearer $GPT_IMAGE_2_API_KEY"Success Response
{
"id": "8f6d9f87-1b3f-4f89-bdfb-3df8e77b7af3",
"object": "image.generation",
"created": 1714000000,
"model": "gpt-image-2-text-to-image",
"status": "succeeded",
"credits": 10,
"data": [
{
"url": "https://..."
}
]
}Possible status values:
| Status | Meaning |
|---|---|
pending | Task is queued. |
processing | Provider is generating the image. |
succeeded | Image URLs are available in data. |
failed | Generation failed. |
canceled | Generation was canceled. |
JavaScript Example
const apiKey = process.env.GPT_IMAGE_2_API_KEY;
const createRes = await fetch(
'https://gpt-image-2.art/api/v1/images/generations',
{
method: 'POST',
headers: {
Authorization: `Bearer ${apiKey}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
model: 'gpt-image-2',
prompt:
'A premium skincare bottle on wet stone with soft studio lighting',
size: '1024x1024',
n: 1,
}),
}
);
const task = await createRes.json();
let result = task;
while (['pending', 'processing'].includes(result.status)) {
await new Promise((resolve) => setTimeout(resolve, 3000));
const queryRes = await fetch(
`https://gpt-image-2.art/api/v1/images/tasks/${task.id}`,
{
headers: {
Authorization: `Bearer ${apiKey}`,
},
}
);
result = await queryRes.json();
}
console.log(result.data);Error Format
Errors follow an OpenAI-style shape:
{
"error": {
"message": "Invalid API key provided.",
"type": "authentication_error",
"param": null,
"code": "invalid_api_key"
}
}