生成接口
估算生成积分
创建任务前验证模型输入并预览当前账户积分估价。
接口
POST
/api/v1/developer/generations/estimate鉴权与 Scope
Authorization: Bearer <credential>;仅接受正式账户 API Key / OAuth。
Scope: generations:write
将示例 model_key 和 parameters 替换为当前目录支持的值。拒绝未知字段以及 provider/URL/storage/endpoint 注入。
无需 Idempotency-Key。确认估价后使用相同输入创建;估价不是固定价格保证。
请求参数
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
model_key | string | 是 | 当前公开模型目录返回的完整 key。 |
operation | string | 是 | image_generation 或 video_generation,必须受所选模型支持。 |
prompt | string | 是 | 非空提示词,最多 8,000 字符。 |
negative_prompt | string | 否 | 最多 8,000 字符,须符合模型支持范围。 |
parameters | object | 否 | 只传该模型 input_schema 接受的参数;按模型要求填写尺寸、时长等。 |
reference_upload_ids | UUID[] | 否 | 已完成上传的 upload_id,最多 8 个;模型限制可能更严格。 |
client_trace_id | string | 否 | 最多 128 字符,仅限 [A-Za-z0-9._:-]+。 |
curl --request POST \
--url 'https://api.perchanceai.art/api/v1/developer/generations/estimate' \
--header 'X-App-Id: perchanceai' \
--header 'X-Request-Id: docs-example' \
--header 'Authorization: Bearer <formal_account_credential>' \
--header 'Content-Type: application/json' \
--data '{"model_key":"<model_key_from_catalog>","operation":"image_generation","prompt":"A bright editorial product still life","parameters":{}}'
响应 HTTP 200
以下为说明响应结构的示例,并非实时 API 响应。示例数值和 USD 不代表固定定价或资金余额。空字段省略。
REST 成功响应为 success、code、message、request_id 和 data;下表描述 data。
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
model_key / operation | string | 是 | 已验证的模型和 operation。 |
estimated_credits | integer | 是 | 当前输入及账户的估价。 |
currency | string | 是 | 账户货币配置;省略匿名 quota。 |
{
"success": true,
"code": "OK",
"message": "OK",
"request_id": "docs-example",
"data": {
"model_key": "<model_key_from_catalog>",
"operation": "image_generation",
"estimated_credits": 10,
"currency": "USD"
}
}
相关错误
401 — DEVELOPER_TOKEN_REQUIRED401 — DEVELOPER_TOKEN_INVALID / DEVELOPER_TOKEN_EXPIRED / DEVELOPER_TOKEN_REVOKED403 — DEVELOPER_SCOPE_INSUFFICIENT422 — FIELD_REQUIRED / FIELD_INVALID402 — CREDITS_INSUFFICIENT
缺 bearer 返回 REQUIRED;无效凭据(包括历史匿名令牌)返回 INVALID。过期或撤销凭据使用对应错误码。
{
"success": false,
"code": "DEVELOPER_TOKEN_REQUIRED",
"message": "A developer bearer token is required.",
"request_id": "docs-example"
}