On this page
GPT Image 2 API
Generate production-ready images from prompts or reference images through one predictable async API. imya handles model routing, task state, credits, and generated assets.
REST API · v1 · Async tasks

Make your first request
The API is asynchronous: create a task, keep the returned task ID, then retrieve the task until a result is ready.
- 1
Create an API key
Generate a key from your imya account settings.
- 2
Create a task
Send the model ID, prompt, and output options.
- 3
Retrieve the result
Poll the task or receive a callback when it finishes.
Authentication
Send your imya API key as a Bearer token on every request. Keep it on your server and never expose it in browser code.
Authorization: Bearer YOUR_IMYA_API_KEY
Content-Type: application/jsonCreate an image generation
Creates an asynchronous GPT Image 2 task and reserves the estimated credits.
/v1/images/generationscurl https://imya.ai/v1/images/generations \
-H "Authorization: Bearer YOUR_IMYA_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"prompt": "A luxury perfume product photo on warm marble, soft studio light",
"size": "1:1",
"quality": "medium",
"n": 1
}'Retrieve a task
Returns the latest task state, final credit usage, generated assets, or a structured error.
/v1/tasks/{task_id}curl https://imya.ai/v1/tasks/task_01jz_example \
-H "Authorization: Bearer YOUR_IMYA_API_KEY"Request parameters
| Field | Type | Required | Description |
|---|---|---|---|
| model | string | Yes | Use gpt-image-2. |
| prompt | string | Yes | Text prompt for the image. |
| size | string | No | 1:1, 3:2, 2:3, 4:3, 3:4, 16:9, or 9:16. |
| quality | string | No | medium or high. |
| n | number | No | Number of images. Default is 1. |
| image_urls | string[] | No | Reference images for image-to-image. |
| callback_url | string | No | Optional HTTPS webhook URL. |
Responses
{
"id": "task_01jz_example",
"status": "pending",
"model": "gpt-image-2",
"credits_reserved": 13
}{
"id": "task_01jz_example",
"status": "succeeded",
"model": "gpt-image-2",
"credits_used": 13,
"data": [
{
"url": "https://cdn.imya.ai/generated/example.png",
"width": 1024,
"height": 1024
}
]
}Credit billing
Credits belong to the user who owns the API key. The reserved estimate is returned when a task is created; the completed task reports the final amount used. Model, output count, quality, and membership discount determine the final charge.
Task status
pendingThe task was accepted and is waiting to start.
processingThe model is generating the requested output.
succeededGeneration finished and data contains the assets.
failedGeneration failed. Read the structured error object.
Errors
401Missing or invalid API key.
402The account does not have enough credits.
422The model, prompt, size, or quality is invalid.
429The API key reached its rate or concurrency limit.
500The generation provider or imya service returned an error.
Want to test the model before integrating?
Open the hosted GPT Image 2 generator to compare prompts and output settings without writing code.
Try GPT Image 2 online