目录 · API 文档
POST /v1/images/generations
文生图,OpenAI images.generate 兼容。
请求
- Method:
POST - Content-Type:
application/json - Auth:
Authorization: Bearer aiimg-sk-live-...
请求参数
| 字段 | 类型 | 必填 | 默认 | 说明 |
|---|---|---|---|---|
prompt | string | 是 | — | 文本描述(2-4000 字) |
model | string | 否 | gpt-image-2 | 仅支持 gpt-image-2 / gpt-image-1 |
n | int | 否 | 1 | 1-4 张 |
size | string | 否 | 1024x1024 | WxH,长边 ≤ 3840,需被 16 整除,比例 ≤ 3:1 |
quality | string | 否 | — | low(~10s) / medium(~30s) / high(~60s) / auto |
response_format | string | 否 | url | url 或 b64_json |
user | string | 否 | — | 外部用户 ID(追踪用) |
响应(200)
{
"created": 1714123456,
"data": [
{ "url": "https://chatgpt2.tokensolo.com/images/.../xxx.png" }
],
"aiimg_generation_id": "cmofjncu7007910z3..."
}aiimg_generation_id 是我们的内部任务 ID,可用 GET /v1/images/{id} 复查。OpenAI SDK 会忽略未知字段,不影响兼容。
示例
curl
curl https://aiimg.top/v1/images/generations \
-H "Authorization: Bearer $AIIMG_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-image-2",
"prompt": "金毛犬在樱花树下,胶片质感,柔光",
"n": 1,
"size": "1024x1024",
"quality": "low"
}'Python(OpenAI SDK)
from openai import OpenAI
import os
client = OpenAI(
api_key=os.environ["AIIMG_API_KEY"],
base_url="https://aiimg.top/v1",
)
resp = client.images.generate(
model="gpt-image-2",
prompt="金毛犬在樱花树下,胶片质感,柔光",
n=1,
size="1024x1024",
quality="low",
)
print(resp.data[0].url)Node(OpenAI SDK)
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.AIIMG_API_KEY,
baseURL: "https://aiimg.top/v1",
});
const r = await client.images.generate({
model: "gpt-image-2",
prompt: "金毛犬在樱花树下,胶片质感,柔光",
n: 1,
size: "1024x1024",
quality: "low",
});
console.log(r.data[0].url);计费
每张图扣 2 T 币(默认)。n=4 → 8 T 币。失败自动退款。
常见错误
详见 错误码 页。常见:401 invalid_api_key、402 insufficient_balance、429 rate_limit_exceeded、502 upstream_failed。