GPT-Image-2 API Руководство по модели
Краткий вывод
- Use POST /v1/images/generations with model=gpt-image-2.
- Supports prompt generation and reference_images URL inputs for guided generation.
- Reference images must be URLs, so local files must be uploaded first instead of passing base64 directly.
- The endpoint returns an async task id for later status polling.
Ключевые возможности
- Text to image:Submit standard prompt-driven image generation tasks through the unified API.
- Reference-guided generation:Pass image URLs through reference_images for style or subject guidance.
- Async task workflow:The endpoint returns a task id for queueing and polling pipelines.
Когда использовать
- When integrating a standard text-to-image workflow through the gateway.
- When references are needed for style continuation or subject guidance.
- When image generation must fit into async task orchestration.
Когда не использовать
- When a synchronous final image response is required.
- When your workflow depends on passing base64 references directly.
Особенности работы
- The endpoint returns a task object before the final image is ready.
- Poll queued, in_progress, completed, and failed states through the image task status API.
- Reference workflows require reference_images URLs, so local files must be uploaded first.
- size and resolution combinations must follow documented limits.
Минимальный запрос
{
"model": "gpt-image-2",
"prompt": "Minimal premium cosmetics ad image with soft studio lighting and clean background",
"size": "1:1",
"resolution": "1K",
"response_format": "url"
}
Минимальный ответ
{
"id": "task_img_xxxxxxxx",
"object": "generation.task",
"model": "gpt-image-2",
"status": "queued",
"progress": 0,
"created_at": 1703884800,
"metadata": {}
}
Ключевые параметры
| Параметр | Тип | Обяз. | По умолчанию | Диапазон | Описание |
|---|
| model | string | Да | gpt-image-2 | - | Use gpt-image-2 as the exact model id. |
| prompt | string | Да | - | - | Primary prompt for image generation or editing. |
| size | string | Нет | 1:1 | 1K: 1:1 | 3:2 |
| resolution | string | Нет | 1K | 1K | 2K |
| reference_images | string[] | Нет | - | URL array | Reference image URL array. Local files must be uploaded first; no direct base64 references. |
| image_urls | string[] | Нет | - | URL array (compat field) | Compatibility field; prefer reference_images for new integrations. |
| response_format | string | Нет | url | url | b64_json |
Частые ошибки
| HTTP | Code | Триггер | Исправление | Повтор |
|---|
| 400 | invalid_request_error | Missing required fields or invalid size-resolution combinations. | Validate model, prompt, size, resolution, and response_format against docs. | Retry only after correcting the payload. |
| 400 | invalid_reference_images | Passing base64, local paths, or non-URL reference_images values. | Upload the image first and pass the resulting URL in reference_images. | Retry after fixing the reference image input. |
| 401 | authentication_error | Missing Authorization header or invalid API key. | Verify bearer token format and key scope. | Retry after fixing authentication. |
| 429 | rate_limit_exceeded | Request rate, concurrency, or current quota hits upstream rate limiting. | Apply exponential backoff first, then review request rate, concurrency, and quota usage. | Use 1s/2s/4s backoff with jitter; if it persists, reduce submission pressure. |
FAQ
- How do I call gpt-image-2?
Call POST /v1/images/generations with model=gpt-image-2, prompt, and optional size, resolution, and reference_images.
- Does gpt-image-2 support image-to-image?
Yes. Pass reference_images URLs to guide output style or subject consistency.
- Why can’t I pass base64 reference images directly?
The current docs require reference_images to be URLs. Upload local files first and then pass the returned URLs.
- How do I check status after the task id is returned?
Poll the image task status endpoint until the task is completed, then read the output image fields.
- Ошибка у модели изображений или видео: invalid apitype: -1
Обычно это означает, что запрос отправлен не в тот endpoint. Модели изображений и видео обычно не используют chat endpoint. Вместо этого нужно отправлять HTTP-запрос на создание задачи по документации и затем опрашивать endpoint статуса задачи. Сначала проверьте фактический код запроса, URL и payload.
- Задача на генерацию изображения или видео завершилась ошибкой, но списание произошло
Сначала попросите у пользователя лог задачи или скриншот и проверьте, есть ли там статистика входных или выходных токенов. Если учет токенов есть, запрос, скорее всего, был отправлен через chat endpoint, а не через правильный media workflow. Модели изображений и видео обычно работают как асинхронные HTTP task API: сначала отправляется задача, затем выполняется опрос по task id согласно документации.
Связанные API