Images API
生成图像,支持多种图像模型。
请求
http
POST /v1/images/generations请求头
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
Authorization | string | ✅ | Bearer sk-你的密钥 |
Content-Type | string | ✅ | application/json |
请求体
json
{
"model": "gpt-image-1",
"prompt": "A beautiful sunset over the ocean",
"n": 1,
"size": "1024x1024"
}参数说明
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | ✅ | 图像模型名称 |
prompt | string | ✅ | 图像描述 |
n | int | ❌ | 生成数量 (1-10),默认 1 |
size | string | ❌ | 图像尺寸,默认 1024x1024 |
响应
json
{
"created": 1234567890,
"data": [
{
"url": "https://xxx.com/image.png"
}
]
}示例
Python
python
from openai import OpenAI
client = OpenAI(
api_key="sk-你的密钥",
base_url="https://api.nextapi.pro/v1"
)
response = client.images.generate(
model="gpt-image-1",
prompt="A beautiful sunset over the ocean",
n=1,
size="1024x1024"
)
print(response.data[0].url)cURL
bash
curl https://api.nextapi.pro/v1/images/generations \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-你的密钥" \
-d '{
"model": "gpt-image-1",
"prompt": "A beautiful sunset over the ocean",
"n": 1,
"size": "1024x1024"
}'