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": {}
}
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
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": {}
}
中国本土のユーザー向け: 中国本土のユーザーは
https://toapis.cn を API エンドポイント(Base URL)としてご利用ください。本ドキュメント内の例では https://toapis.com を https://toapis.cn に置き換えてください。- Unified image generation API
- Select the
gpt-image-2model via themodelparameter - 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
string
必須
All endpoints require Bearer Token authenticationGet your API Key from the API Key Management PageAdd to request header:
Authorization: Bearer YOUR_API_KEY
Body
string
デフォルト:"gpt-image-2"
必須
Image generation model nameExample:
"gpt-image-2"string
必須
Text prompt for image generationMaximum 32,000 characters for GPT image models
string
デフォルト:"1:1"
Output image aspect ratioCurrently 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:21string
デフォルト:"1k"
Output resolution tierSupported values:
1k, 2k, 4kstring
背景の任意パラメータ.
"transparent" を指定すると透明背景の画像を生成します. 省略すると通常の画像生成になります.テキストからの生成と reference_images を含むリクエストの両方で使用できます. 通常の生成では auto や opaque を送信せず, このフィールドを省略してください.Playground で gpt-image-2 を選択し, 背景を “通常” から “透明” に変更します. “通常” に戻すとリクエストから background が除かれます.Size Reference
| size | 1k | 2k | 4k |
|---|---|---|---|
1:1 | 1024x1024 | 2048x2048 | 2880x2880 |
3:2 | 1536x1024 | 2048x1360 | 3520x2336 |
2:3 | 1024x1536 | 1360x2048 | 2336x3520 |
4:3 | 1024x768 | 2048x1536 | 3312x2480 |
3:4 | 768x1024 | 1536x2048 | 2480x3312 |
5:4 | 1280x1024 | 2560x2048 | 3216x2576 |
4:5 | 1024x1280 | 2048x2560 | 2576x3216 |
16:9 | 1536x864 | 2048x1152 | 3840x2160 |
9:16 | 864x1536 | 1152x2048 | 2160x3840 |
2:1 | 2048x1024 | 2688x1344 | 3840x1920 |
1:2 | 1024x2048 | 1344x2688 | 1920x3840 |
21:9 | 2016x864 | 2688x1152 | 3840x1648 |
9:21 | 864x2016 | 1152x2688 | 1648x3840 |
integer
デフォルト:1
Number of images to generateDefault: 1
string
デフォルト:"url"
レスポンス formatThe API returns image URLs, so
url is the recommended valuestring[]
Reference image URLs for image-to-image generation⚠️ URL format only (base64 no longer supported)
- Publicly accessible URLs (
http://orhttps://) - You can use the Upload 画像API to upload local files and get URLs
- Supports single-image and multi-image reference
- Maximum 6 images
string[]
Backward-compatible reference image fieldToAPIs automatically normalizes it to
reference_imagesレスポンス
string
Unique task identifier for status queries
string
Object type, always
generation.taskstring
モデル name used
string
Task status
queuedin_progresscompletedfailed
integer
Task progress percentage (0-100)
integer
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": {}
}