GPT Image 2
OpenAI GPT Image 2 image generation. Publicly, use a single model id: gpt-image-2. It supports both prompt-only generation and reference-image editing.
Model
| Model Name | Output | Mode |
|---|---|---|
gpt-image-2 | Image URLs | Text-to-image, image-to-image |
Pricing
Priced per output resolution tier:
| Resolution | Credits | Price |
|---|---|---|
1k (default) | 2.4 credits | $0.012 |
2k | 4.8 credits | $0.024 |
4k | 7.2 credits | $0.036 |
Create Task
curl -X POST https://api.aivideoapi.ai/v1/images/generations \
-H "Authorization: Bearer sk-your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"input": {
"prompt": "Turn this product photo into a clean studio shot on a white background",
"image_urls": [
"https://example.com/source.png"
],
"aspect_ratio": "1:1",
"nsfw_checker": true
}
}'
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
model | string | Yes | Must be gpt-image-2 |
input | object | Yes | Generation parameters, see below |
callback_url | string | No | Optional callback URL for completion/failure notifications |
Input Parameters
| Field | Type | Required | Description |
|---|---|---|---|
prompt | string | Conditionally | Prompt text, max 20,000 characters |
image_urls | string[] | Conditionally | Reference image URLs for editing. Maximum 16 images. |
aspect_ratio | string | No | Output image aspect ratio, defaults to auto. One of: auto, 1:1, 5:4, 4:3, 3:2, 16:9, 21:9, 9:16, 4:5, 3:4, 2:3, 2:1, 1:2, 9:21. Constraint: when resolution=4k, must be explicitly set (not auto) and limited to 16:9, 9:16, 2:1, 1:2, 21:9, 9:21 |
resolution | string | No | Output resolution tier, defaults to 1k. One of: 1k, 2k, 4k |
nsfw_checker | boolean | No | Safety check toggle, defaults to true |
At least one of prompt or image_urls must be provided.
Example: Text-to-Image
curl -X POST https://api.aivideoapi.ai/v1/images/generations \
-H "Authorization: Bearer sk-your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"input": {
"prompt": "A cinematic night city poster with neon reflections on a rainy street.",
"aspect_ratio": "16:9",
"nsfw_checker": true
}
}'
Example: Image-to-Image
curl -X POST https://api.aivideoapi.ai/v1/images/generations \
-H "Authorization: Bearer sk-your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"input": {
"prompt": "Convert this room into a warm Scandinavian interior design render",
"image_urls": [
"https://example.com/room.jpg"
],
"aspect_ratio": "3:2"
}
}'
Example: 4K Output
curl -X POST https://api.aivideoapi.ai/v1/images/generations \
-H "Authorization: Bearer sk-your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"input": {
"prompt": "An ancient castle under a starry sky, cinematic composition",
"aspect_ratio": "16:9",
"resolution": "4k"
}
}'
Response
{
"code": 200,
"msg": "success",
"data": {
"taskId": "397ce9f2-c04e-4244-ac33-3af19a7cc297"
}
}
Query Task
curl https://api.aivideoapi.ai/v1/tasks/{taskId} \
-H "Authorization: Bearer sk-your-api-key"
Status flow: pending -> processing -> completed or failed.
Completed
{
"id": "397ce9f2-c04e-4244-ac33-3af19a7cc297",
"status": "completed",
"model": "gpt-image-2",
"created_at": 1775383908,
"completed_at": 1775383910,
"output": {
"urls": [
"https://file.aivideoapi.ai/images/2026/04/05/abc123.png"
],
"metadata": {
"model": "gpt-image-2-image-to-image",
"costTime": 70
}
}
}
Failed
{
"id": "57c8772c-f834-46f3-9b7d-81f92e104050",
"status": "failed",
"model": "gpt-image-2",
"created_at": 1775383908,
"error": {
"code": "upstream_error",
"message": "Generation failed"
}
}
Failed tasks are automatically refunded.
Callback Notifications
Pass callback_url when creating the task. When the task completes or fails, we send a POST request whose payload matches the GET /v1/tasks/{taskId} response.
Error Codes
When a request fails, the API returns a JSON error response:
{
"error": {
"code": "insufficient_credits",
"message": "Your credit balance is too low. Please top up.",
"type": "billing_error"
}
}
Error Reference
| HTTP Status | Code | Type | Description |
|---|---|---|---|
| 400 | invalid_request | invalid_request_error | Missing or invalid parameters |
| 401 | invalid_api_key | authentication_error | API key is invalid, disabled, or deleted |
| 402 | insufficient_credits | billing_error | Credit balance too low, please top up |
| 403 | ip_not_allowed | permission_error | Request IP not in the key's allowlist |
| 404 | model_not_found | invalid_request_error | Model does not exist or is inactive |
| 404 | task_not_found | invalid_request_error | Task ID does not exist |
| 429 | rate_limit_exceeded | rate_limit_error | Too many requests, please slow down |
| 429 | spend_limit_exceeded | billing_error | Key spend limit reached (hourly/daily/total) |
| 500 | internal_error | api_error | Unexpected server error |
| 503 | upstream_error | upstream_error | Upstream AI provider returned an error |
Common Scenarios
invalid_request (400)
Returned when required fields are missing or invalid.
{
"error": {
"code": "invalid_request",
"message": "'model' is required.",
"type": "invalid_request_error"
}
}
insufficient_credits (402)
Your balance is too low. Check your balance with GET /v1/credits and top up in Dashboard > Billing.
invalid_api_key (401)
Possible causes:
- The key does not start with
sk- - The key has been disabled or deleted
- The user account has been banned
upstream_error (503)
The upstream AI provider returned an error. This may happen when:
- The input contains sensitive or prohibited content
- The provider is temporarily unavailable
- The request parameters are not supported by the provider
Credits are automatically refunded when a task fails due to upstream errors.