ToAPIsToAPIs
GPT-Image-2

GPT-Image-2 이미지 생성

Generate images with gpt-image-2, supporting text-to-image and reference_images based image generation

POST
/v1/images/generations

중국 본토 사용자 안내: 중국 본토 사용자는 https://toapis.cn 를 API 엔드포인트(Base URL)로 사용해 주세요. 본 문서의 예시에서 https://toapis.com 을 https://toapis.cn 로 바꿔 주세요.

  • Unified image generation API
  • Select the gpt-image-2 model via the model parameter
  • Supports text-to-image, single-reference, and multi-reference image generation
  • Async task management with task ID based result lookup

Important Change: For better performance and cost control, base64 image data is no longer supported in image_urls or reference_images. Please use the Upload 이미지 API first to upload images and obtain a URL.

Authorizations

Authorizationstring헤더필수

All endpoints require Bearer Token authentication

Get your API Key from the API Key Management Page

Add to request header:

Authorization: Bearer YOUR_API_KEY

Body

modelstring본문필수기본값: gpt-image-2

Image generation model name

Example: "gpt-image-2"

promptstring본문필수

Text prompt for image generation

Maximum 32,000 characters for GPT image models

sizestring본문기본값: 1:1

Output image aspect ratio

Currently supported ratios:

1:1, 3:2, 2:3, 4:3, 3:4, 5:4, 4:5, 16:9, 9:16, 2:1, 1:2, 21:9, 9:21

You can pass auto to let the upstream provider choose the dimensions, but the final aspect ratio and pixel dimensions are not guaranteed.

resolutionstring본문기본값: 1k

Output resolution tier

Supported values: 1k, 2k, 4k

backgroundstring본문

선택적 배경 매개변수입니다. "transparent"를 지정하면 투명 배경 이미지를 생성합니다. 생략하면 일반 이미지를 생성합니다.

텍스트 기반 생성과 reference_images가 포함된 요청 모두에 사용할 수 있습니다. 일반 생성 시 auto 또는 opaque를 보내지 말고 이 필드를 생략하세요.

Playground에서 gpt-image-2를 선택하고 배경을 "일반"에서 "투명"으로 변경하세요. "일반"으로 되돌리면 요청에서 background가 제외됩니다.

Size Reference

size1k2k4k
1:11024x10242048x20482880x2880
3:21536x10242048x13603520x2336
2:31024x15361360x20482336x3520
4:31024x7682048x15363312x2480
3:4768x10241536x20482480x3312
5:41280x10242560x20483216x2576
4:51024x12802048x25602576x3216
16:91536x8642048x11523840x2160
9:16864x15361152x20482160x3840
2:12048x10242688x13443840x1920
1:21024x20481344x26881920x3840
21:92016x8642688x11523840x1648
9:21864x20161152x26881648x3840
ninteger본문기본값: 1

Number of images to generate

Default: 1

response_formatstring본문기본값: url

응답 format

The API returns image URLs, so url is the recommended value

reference_imagesstring[]본문

Reference image URLs for image-to-image generation

⚠️ URL format only (base64 no longer supported)

  • Publicly accessible URLs (http:// or https://)
  • You can use the Upload 이미지 API to upload local files and get URLs
  • Supports single-image and multi-image reference
  • Maximum 14 images
image_urlsstring[]본문

Backward-compatible reference image field

ToAPIs automatically normalizes it to reference_images

응답

idstring

Unique task identifier for status queries

objectstring

Object type, always generation.task

modelstring

모델 name used

statusstring

Task status

  • queued
  • in_progress
  • completed
  • failed
progressinteger

Task progress percentage (0-100)

created_atinteger

Task creation timestamp (Unix timestamp)

요청 예시

curl --request POST \
  --url https://toapis.com/v1/images/generations \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '{
    "model": "gpt-image-2",
    "prompt": "Generate a futuristic city night poster with neon lighting and cinematic composition",
    "n": 1,
    "size": "1:1",
    "resolution": "1k",
    "response_format": "url"
  }'
curl --request POST \
  --url https://toapis.com/v1/images/generations \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '{
    "model": "gpt-image-2",
    "prompt": "保留主体结构,把画面改成赛博朋克风格,增强光影和细节",
    "n": 1,
    "size": "1:1",
    "resolution": "1k",
    "image_urls": [
      "https://example.com/source.png",
       "https://example.com/source.png",
      "https://example.com/source.png"
    ],
    "response_format": "url"
  }'
const response = await fetch('https://toapis.com/v1/images/generations', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer your-ToAPIs-key',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    model: 'gpt-image-2',
    prompt: 'Generate a futuristic city night poster with neon lighting and cinematic composition',
    n: 1,
    size: '1:1',
    resolution: '1k',
    response_format: 'url'
  })
});

const task = await response.json();
console.log(task.id, task.status);
curl --request POST \
  --url https://toapis.com/v1/images/generations \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '{
    "model": "gpt-image-2",
    "prompt": "투명 배경의 귀여운 고양이 스티커를 생성하세요",
    "n": 1,
    "size": "1:1",
    "resolution": "1k",
    "background": "transparent",
    "response_format": "url"
  }'

응답 예시

{
  "id": "task_img_abc123def456",
  "object": "generation.task",
  "model": "gpt-image-2",
  "status": "queued",
  "progress": 0,
  "created_at": 1703884800,
  "metadata": {}
}