鉴权
开发者 API 使用 API Key。请在请求头传入 Authorization: Bearer sk-neutral-example。 示例密钥仅为中性占位,生产环境请替换为控制台生成的真实 Key。
接口路径
| 路径 | 用途 | 模式 |
|---|---|---|
/v1/images/generations | 文生图 | 同步 |
/v1/images/edits | 图文生图 | 同步 |
/v1/responses | Responses 图像工具兼容 | 同步 |
/v1/async/images/generations | 文生图任务提交 | 异步 |
/v1/async/images/edits | 图文生图任务提交 | 异步 |
/v1/tasks/{task_id} | 任务查询 | 查询 |
/v1/models | 模型列表和折扣后价格 | 查询 |
请求示例
包含 curl、Python、TypeScript、JavaScript。每个示例都可以一键复制为 Markdown。
# 文生图
curl https://api.example.com/v1/images/generations \
-H "Authorization: Bearer sk-neutral-example" \
-H "Content-Type: application/json" \
-d '{
"model": "dream-lite",
"prompt": "一张蓝白色调的产品封面图",
"n": 1,
"size": "1024x1024",
"response_format": "url"
}'
# 异步任务查询
curl https://api.example.com/v1/tasks/task_neutral_001 \
-H "Authorization: Bearer sk-neutral-example"from openai import OpenAI
client = OpenAI(
base_url="https://api.example.com/v1",
api_key="sk-neutral-example",
)
result = client.images.generate(
model="dream-lite",
prompt="一张适合文章封面的清爽插图",
n=1,
size="1024x1024",
)
print(result.data[0].url)import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.example.com/v1",
apiKey: "sk-neutral-example",
});
const response = await client.responses.create({
model: "dream-vision",
input: "生成一张蓝白色 SaaS 产品示意图",
tools: [{ type: "image_generation" }],
});
console.log(response.output);const response = await fetch("https://api.example.com/v1/async/images/generations", {
method: "POST",
headers: {
"Authorization": "Bearer sk-neutral-example",
"Content-Type": "application/json"
},
body: JSON.stringify({
model: "dream-lite",
prompt: "一张干净的应用图标展示图",
n: 2,
size: "1344x768"
})
});
const batch = await response.json();
console.log(batch);响应与错误
同步成功响应返回图片 URL 或 Base64、任务状态和计费信息。异步提交返回 batch id 和 task id。 错误响应包含稳定错误码、中文提示和可恢复建议。
{
"error": {
"code": "insufficient_balance",
"message": "积分不足,请充值后重试。",
"task_id": null
}
}计费说明
系统按模型、生成张数、用户分组折扣和任务最终状态结算。任务失败、取消或任务级超时会退回未确认的预扣积分。