外观
GPT Image 2
gpt-image-2 支持文生图和图片编辑,并使用 OpenAI 兼容的 size 与 quality 控制项。
API 形式
| 操作 | Endpoint | 模式 |
|---|---|---|
| 图片生成 | POST /v1/images/generations | 同步 |
| 图片生成任务 | POST /v1/async/images/generations | 异步 |
| 图片编辑 | POST /v1/images/edits | 同步 |
| 图片编辑任务 | POST /v1/async/images/edits | 异步 |
价格
每张图片的积分由输出尺寸档位和质量档位决定。quality=auto 按 high 计费,size=auto 默认进入 1K 档。
| 尺寸档 | 长边 | low | medium | high / auto |
|---|---|---|---|---|
| 1K | <= 1536px | 1 | 4 | 14 |
| 2K | <= 2048px | 2 | 17 | 67 |
| 4K | <= 3840px | 4 | 34 | 133 |
请求显示的 costCredits 等于矩阵值乘以 n。
示例
bash
curl https://api.pixapi.ai/v1/images/generations \
-H "Authorization: Bearer $PIXAPI_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"prompt": "A polished product photo of a ceramic coffee cup",
"n": 1,
"size": "1024x1024",
"quality": "high"
}'py
import os
import requests
response = requests.post(
"https://api.pixapi.ai/v1/images/generations",
headers={
"Authorization": f"Bearer {os.environ['PIXAPI_KEY']}",
"Content-Type": "application/json",
},
json={
"model": "gpt-image-2",
"prompt": "A polished product photo of a ceramic coffee cup",
"n": 1,
"size": "1024x1024",
"quality": "high"
},
)
response.raise_for_status()
print(response.json())js
const response = await fetch('https://api.pixapi.ai/v1/images/generations', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.PIXAPI_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
"model": "gpt-image-2",
"prompt": "A polished product photo of a ceramic coffee cup",
"n": 1,
"size": "1024x1024",
"quality": "high"
}),
});
if (!response.ok) {
throw new Error(await response.text());
}
console.log(await response.json());go
package main
import (
"bytes"
"fmt"
"io"
"net/http"
"os"
)
func main() {
body := []byte(`{
"model": "gpt-image-2",
"prompt": "A polished product photo of a ceramic coffee cup",
"n": 1,
"size": "1024x1024",
"quality": "high"
}`)
req, err := http.NewRequest(
"POST",
"https://api.pixapi.ai/v1/images/generations",
bytes.NewBuffer(body),
)
if err != nil {
panic(err)
}
req.Header.Set("Authorization", "Bearer "+os.Getenv("PIXAPI_KEY"))
req.Header.Set("Content-Type", "application/json")
resp, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
result, _ := io.ReadAll(resp.Body)
fmt.Println(string(result))
}全部请求字段和自定义尺寸限制见 GPT Image。
