快速开始
向以下地址发起 JSON 请求,即可生成图片。
POST
https://api.chongplus.plus/v1/images/generations
最小请求体
JSON
{
"model": "gpt-image-2",
"prompt": "A cute orange cat wearing an astronaut helmet, sticker style, clean background.",
"size": "2048x2048"
}
建议使用英文 prompt,图片质量和指令遵循通常会更稳定。为避免尺寸被网关按默认值处理,
建议始终传入下方表格中的合法
size。
认证方式
所有请求都需要使用 Bearer Token。请在请求头中携带你的 API Key。
| Header | 值 | 说明 |
|---|---|---|
Authorization |
Bearer sk-... |
必填。将 sk-... 替换为你的 ChongPlus API Key。 |
Content-Type |
application/json |
文生图必填。图片编辑接口使用 multipart/form-data,由客户端自动设置边界。 |
请求参数
| 字段 | 类型 | 是否必填 | 示例 | 说明 |
|---|---|---|---|---|
model |
string | 必填 | gpt-image-2 |
图片生成模型:gpt-image-2、gpt-image-2.5-flare 或 gpt-image-2.5-sunburst。 |
prompt |
string | 必填 | A futuristic city at sunset... |
图片描述。建议说明主体、风格、构图、背景、光线和画面细节。 |
size |
string | 必填 | 2048x2048 |
分辨率字符串。可用值见下方“尺寸说明”。 |
n |
integer | 可选 | 1 |
生成图片数量。建议范围 1 到 4。 |
response_format |
string | 可选 | b64_json |
响应格式。常见为 Base64 图片数据,部分网关也可能返回 URL。 |
尺寸说明
以下为工具页和 API 示例使用的常见尺寸。最终可用尺寸和扣费以后台实际配置为准。
1K
1024x1024
适合头像、贴纸、方形社媒图。
2K
1536x1024 / 1024x1536 / 2048x2048
适合商品图、海报、横向摄影素材。
4K
3840x2160 / 2160x3840
适合宽屏封面、手机壁纸、短视频封面。
| 清晰度 | 可用 size | 比例 | 常见用途 |
|---|---|---|---|
| 1K | 1024x1024 |
1:1 | 头像、贴纸、方形图片 |
| 2K | 2048x2048 |
1:1 | 高质量方图、商品图 |
| 2K | 1536x1024 |
3:2 | 横向摄影、Banner 素材 |
| 2K | 1024x1536 |
2:3 | 竖版海报、人物图 |
| 4K | 3840x2160 |
16:9 | 宽屏封面、视频封面 |
| 4K | 2160x3840 |
9:16 | 手机壁纸、短视频封面 |
Fallback 规则
如果
size 为空、auto 或传入了不支持的分辨率,网关可能按默认尺寸处理。
为避免结果不符合预期,建议始终传入上表中的合法分辨率。
调用示例
cURL
Shell
curl -X POST "https://api.chongplus.plus/v1/images/generations" \
-H "Authorization: Bearer sk-你的APIKey" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"prompt": "A cinematic product photo of a futuristic gaming console, dark background, neon rim light, ultra detailed.",
"size": "2048x2048"
}'
Python requests
Python
import requests
url = "https://api.chongplus.plus/v1/images/generations"
headers = {
"Authorization": "Bearer sk-你的APIKey",
"Content-Type": "application/json",
}
payload = {
"model": "gpt-image-2",
"prompt": "A cute orange cat wearing an astronaut helmet, sticker style, clean background.",
"size": "1536x1024",
}
response = requests.post(url, headers=headers, json=payload, timeout=300)
response.raise_for_status()
data = response.json()
print(data)
JavaScript fetch
JavaScript
const response = await fetch("https://api.chongplus.plus/v1/images/generations", {
method: "POST",
headers: {
"Authorization": "Bearer sk-你的APIKey",
"Content-Type": "application/json",
},
body: JSON.stringify({
model: "gpt-image-2",
prompt: "A futuristic city at sunset, cyberpunk style, highly detailed.",
size: "3840x2160",
}),
});
if (!response.ok) {
throw new Error(await response.text());
}
const data = await response.json();
console.log(data);
OpenAI SDK 兼容写法
JavaScript
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.CHONGPLUS_API_KEY,
baseURL: "https://api.chongplus.plus/v1",
});
const image = await client.images.generate({
model: "gpt-image-2",
prompt: "A warm editorial photo of a coffee cup beside a laptop",
size: "1024x1024",
n: 1,
});
图片编辑 / 图生图
上传一张参考图并描述修改目标,可用于局部调整、换背景、改风格或基于原图继续创作。
POST
https://api.chongplus.plus/v1/images/edits
该接口使用
multipart/form-data,不要手动设置 Content-Type;让 HTTP 客户端自动添加 boundary。
| 字段 | 类型 | 是否必填 | 说明 |
|---|---|---|---|
image |
file | 必填 | 待编辑的参考图片,以文件方式上传。 |
model |
string | 必填 | 图片编辑模型,例如 gpt-image-2。 |
prompt |
string | 必填 | 描述希望保留和修改的内容,例如主体不变、换为纯白背景。 |
size |
string | 可选 | 输出尺寸,建议使用“尺寸说明”中的合法值。 |
n |
integer | 可选 | 生成数量,建议范围 1 到 4。 |
cURL
Shell
curl -X POST "https://api.chongplus.plus/v1/images/edits" \ -H "Authorization: Bearer sk-你的APIKey" \ -F "model=gpt-image-2" \ -F "prompt=Keep the product unchanged, replace the background with a clean white studio backdrop." \ -F "size=2048x2048" \ -F "n=1" \ -F "image=@./product.png"
Python requests
Python
import requests
url = "https://api.chongplus.plus/v1/images/edits"
headers = {"Authorization": "Bearer sk-你的APIKey"}
data = {
"model": "gpt-image-2",
"prompt": "Keep the product unchanged, replace the background with a clean white studio backdrop.",
"size": "2048x2048",
"n": "1",
}
with open("product.png", "rb") as image_file:
response = requests.post(
url,
headers=headers,
data=data,
files={"image": ("product.png", image_file, "image/png")},
timeout=300,
)
response.raise_for_status()
print(response.json())
返回格式
接口通常返回 OpenAI 兼容的图片结果。不同上游可能返回 URL 或 Base64 图片数据。
URL 形式
JSON
{
"created": 1770000000,
"data": [
{
"url": "https://..."
}
]
}
Base64 形式
JSON
{
"created": 1770000000,
"data": [
{
"b64_json": "iVBORw0KGgoAAAANSUhEUg..."
}
]
}
如果返回的是
b64_json,前端可使用 data:image/png;base64,...
拼接后直接展示或下载。大图建议先转换为 Blob URL 再渲染。
常见错误
| 状态码 | 可能原因 | 处理方式 |
|---|---|---|
401 |
API Key 缺失、格式错误或无效。 | 检查请求头是否为 Authorization: Bearer sk-...。 |
400 |
请求参数错误,例如缺少 model、prompt 或传入不支持的字段。 |
对照请求参数表重新检查 JSON。 |
403 |
Key 无权限、分组不可用或额度不足。 | 检查 Key 分组权限、额度和账户状态。 |
429 |
请求过于频繁或触发限流。 | 降低并发,加入重试退避。 |
500 / 502 / 504 |
上游生成超时、网关超时或服务暂时不可用。 | 稍后重试;持续失败时记录请求时间和错误响应便于排查。 |
错误返回示例
JSON
{
"error": {
"message": "Invalid API key or insufficient quota",
"type": "invalid_request_error"
}
}
在线工具页
如果只是手动生成或调试 Prompt,可以直接使用同源工具页: https://api.chongplus.plus/tools/image-studio/
DOCS
https://api.chongplus.plus/tools/image-studio/docs/