gpt-image-2。
核心能力
- 文字生成圖片 - 根據自然語言提示詞生成圖片
- 圖片編輯 - 使用提示詞修改上傳圖片
- 輸出控制 - 設定尺寸與品質
- Images API - 使用 /v1/images/generations
輸出規格
| 屬性 | 取值 |
|---|---|
| 端點 | /v1/images/generations, /v1/images/edits |
| 常用尺寸 | 1024x1024, 1536x1024, 1024x1536, 2048x2048, up to 3840px |
| 尺寸限制 | 邊長為 16 的倍數;長寬比不超過 3:1;總像素 655,360-8,294,400 |
| 品質 | low, medium, high, auto |
| 格式 | png, jpeg, webp |
| 背景 | opaque, auto |
快速範例
- cURL
- Python
curl "https://api.mixroute.ai/v1/images/generations" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"prompt": "A minimal red circle centered on a white background",
"size": "1024x1024",
"n": 1,
"quality": "low"
}'
import requests
response = requests.post(
"https://api.mixroute.ai/v1/images/generations",
headers={"Authorization": "Bearer YOUR_API_KEY"},
json={'model': 'gpt-image-2',
'prompt': 'A minimal red circle centered on a white background',
'size': '1024x1024',
'n': 1,
'quality': 'low'},
)
print(response.json())
參數
| 參數 | 類型 | 必填 | 說明 |
|---|---|---|---|
model | string | 是 | 固定為 gpt-image-2。 |
prompt | string | 是 | 需要生成圖片的文字描述。 |
n | integer | 否 | 生成圖片數量。 |
size | string | 否 | 輸出圖片尺寸。 |
quality | string | 否 | 模型支援時設定輸出品質。 |
output_format | string | 否 | png、jpeg 或 webp。 |
output_compression | integer | 否 | JPEG 或 WebP 壓縮級別,範圍 0-100。 |
background | string | 否 | opaque 或 auto。 |
圖片編輯
- cURL
- Python
curl "https://api.mixroute.ai/v1/images/edits" \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "model=gpt-image-2" \
-F "image=@source.png" \
-F "prompt=Replace the white background with a pale blue background" \
-F "size=1024x1024" \
-F "quality=low"
from openai import OpenAI
client = OpenAI(api_key="YOUR_API_KEY", base_url="https://api.mixroute.ai/v1")
result = client.images.edit(
model="gpt-image-2",
image=open("source.png", "rb"),
prompt="Replace the white background with a pale blue background",
size="1024x1024",
quality="low",
)
print(result.data[0])
編輯參數
| 參數 | 類型 | 必填 | 說明 |
|---|---|---|---|
image | file | 是 | 透過 multipart form data 上傳的來源圖片。 |
model | string | 是 | 固定為 gpt-image-2。 |
prompt | string | 是 | 圖片編輯指令。 |
size | string | 否 | 輸出圖片尺寸。 |
quality | string | 否 | 輸出品質。 |
output_format | string | 否 | png、jpeg 或 webp。 |
output_compression | integer | 否 | JPEG 或 WebP 壓縮級別,範圍 0-100。 |