开发者 API
V1 与工作台共用模型、素材、任务恢复和积分账本。请把密钥保留在服务端。
管理 API 密钥请求携带 Authorization: Bearer YOUR_API_KEY。网站 Cookie 不能作为 API 凭据;每次请求均检查有效付费会员和密钥权限。
读取模型,按需上传参考图,获取报价,明确确认该报价,再携带稳定的 Idempotency-Key 提交。每两秒查询一次返回的任务,通过受保护的输出接口下载。
只有生成提交消耗账号积分,报价和创建密钥不扣费。供应商失败沿用现有退款及对账流程;原请求结果未明时,不要更换幂等键重新提交。
每个密钥每分钟最多 60 个已认证请求,429 响应带 Retry-After。有效期为 1–365 天,可随时撤销。
| HTTP | URL | 权限范围 |
|---|---|---|
| GET | /api/v1/models | models:read |
| GET | /api/v1/assets | assets:read |
| GET | /api/v1/assets/{id}/download | assets:read |
| POST | /api/v1/uploads | assets:write |
| PUT | /api/v1/uploads/{id} | assets:write |
| POST | /api/v1/uploads/{id}/complete | assets:write |
| POST | /api/v1/quotes | generations:write |
| POST | /api/v1/generations | generations:write |
| GET | /api/v1/generations/{kind}/{id} | generations:read |
| GET | /api/v1/generations/{kind}/{id}/outputs/{index} | generations:read |
参考图采用三步上传:声明 MIME 和字节数、PUT 文件、完成上传。服务端验证不超过 10 MB 的 JPEG、PNG、WebP。生成时使用返回的素材 ID,不接受外部参考 URL 或其他账号素材。
// Node.js 22+; keep API_KEY on your server.
const base = process.env.API_BASE_URL;
const headers = {
Authorization: `Bearer ${process.env.API_KEY}`,
'Content-Type': 'application/json',
};
const modelsResponse = await fetch(base + '/api/v1/models', { headers });
if (!modelsResponse.ok) throw new Error('Read models failed');
const models = await modelsResponse.json();
const draft = {
"kind": "image",
"modelPreset": "gpt-image-2",
"mode": "text-to-image",
"prompt": "A yellow ceramic mug on a pale blue background",
"aspectRatio": "1:1",
"resolution": "1k",
"outputCount": 1
};
const quoteResponse = await fetch(base + '/api/v1/quotes', {
method: 'POST', headers, body: JSON.stringify({ draft }),
});
if (!quoteResponse.ok) throw new Error('Quote failed');
const quote = await quoteResponse.json();
// Review quote.quote before submitting. Persist this operation ID first.
const operationId = process.env.OPERATION_ID;
if (!operationId) throw new Error('A stable operation ID is required');
const submitted = await fetch(base + '/api/v1/generations', {
method: 'POST',
headers: { ...headers, 'Idempotency-Key': operationId },
body: JSON.stringify({
draft: quote.normalizedDraft,
quoteAcknowledgement: quote.quote,
}),
});
if (!submitted.ok) throw new Error('Check response before retrying');
const { task } = await submitted.json();
const taskResponse = await fetch(
base + '/api/v1/generations/' + task.kind + '/' + task.id, { headers },
);
if (!taskResponse.ok) throw new Error('Read task failed');
const detail = await taskResponse.json();
// Poll at two-second intervals until terminal. Download detail.outputs[].downloadUrl
// with the same Authorization header. Never change the ID to retry an unknown outcome.401:密钥无效、到期或撤销。403:权限或付费会员不足。409:幂等冲突或报价变化,需重新获取并确认报价。422:输入无效。429:限流。503:暂不可用。请读取响应错误码,禁止自动更换幂等键重试付费提交。