curl --request POST 'https://api.voicecheap.ai/v1/actions/thumbnails_upload_initialize' \
--header "x-api-key: $VOICECHEAP_API_KEY" \
--header 'Content-Type: application/json' \
--data '{"requestId":"19372a86-ee2f-4c6d-835b-ec1b10b7c68b","filename":"reference.png","contentType":"image/png","fileSize":7340032}'
const input = {
requestId: '19372a86-ee2f-4c6d-835b-ec1b10b7c68b',
filename: 'reference.png',
contentType: 'image/png',
fileSize: 7340032,
};
const response = await fetch('https://api.voicecheap.ai/v1/actions/thumbnails_upload_initialize', {
method: 'POST',
headers: {
'x-api-key': process.env.VOICECHEAP_API_KEY,
'Content-Type': 'application/json',
},
body: JSON.stringify(input),
});
const body = await response.json();
if (!response.ok) throw new Error(body.code + ': ' + body.message);
console.log(body);
import os
import requests
response = requests.post(
"https://api.voicecheap.ai/v1/actions/thumbnails_upload_initialize",
headers={"x-api-key": os.environ["VOICECHEAP_API_KEY"]},
json={"requestId": "19372a86-ee2f-4c6d-835b-ec1b10b7c68b", "filename": "reference.png", "contentType": "image/png", "fileSize": 7340032},
timeout=120,
)
body = response.json()
if not response.ok:
raise RuntimeError(f"{body.get('code')}: {body.get('message')}")
print(body)
{
"data": {
"uploadId": "c547fb7f-f334-46a8-a8bb-80b5b343889a",
"key": "uploads/example-user/2502829e-3fde-4aad-b3c7-ce0f779fa2e6-reference.png",
"partSize": 5242880,
"maxConcurrency": 4
},
"requestId": "19372a86-ee2f-4c6d-835b-ec1b10b7c68b"
}
{
"data": {
"requestId": "19372a86-ee2f-4c6d-835b-ec1b10b7c68b",
"operation": "thumbnails_upload_initialize",
"createdAt": 1792144800000,
"updatedAt": 1792144820000,
"status": "running",
"pollAfterSeconds": 5
},
"requestId": "19372a86-ee2f-4c6d-835b-ec1b10b7c68b"
}
{
"data": {
"requestId": "19372a86-ee2f-4c6d-835b-ec1b10b7c68b",
"operation": "thumbnails_upload_initialize",
"createdAt": 1792144800000,
"updatedAt": 1792144820000,
"status": "completed",
"resultStored": false,
"message": "The action completed. Retrieve its output from the corresponding history or resource action."
},
"requestId": "19372a86-ee2f-4c6d-835b-ec1b10b7c68b"
}
缩略图
初始化缩略图参考图上传
准备上传最大 8 MiB 的 JPG、PNG 或 WebP 参考图像。使用 thumbnails_upload_sign_parts 获取 PUT URL,上传文件字节后调用 thumbnails_upload_complete,并在生成时使用其 fileKey。
POST
/
v1
/
actions
/
thumbnails_upload_initialize
curl --request POST 'https://api.voicecheap.ai/v1/actions/thumbnails_upload_initialize' \
--header "x-api-key: $VOICECHEAP_API_KEY" \
--header 'Content-Type: application/json' \
--data '{"requestId":"19372a86-ee2f-4c6d-835b-ec1b10b7c68b","filename":"reference.png","contentType":"image/png","fileSize":7340032}'
const input = {
requestId: '19372a86-ee2f-4c6d-835b-ec1b10b7c68b',
filename: 'reference.png',
contentType: 'image/png',
fileSize: 7340032,
};
const response = await fetch('https://api.voicecheap.ai/v1/actions/thumbnails_upload_initialize', {
method: 'POST',
headers: {
'x-api-key': process.env.VOICECHEAP_API_KEY,
'Content-Type': 'application/json',
},
body: JSON.stringify(input),
});
const body = await response.json();
if (!response.ok) throw new Error(body.code + ': ' + body.message);
console.log(body);
import os
import requests
response = requests.post(
"https://api.voicecheap.ai/v1/actions/thumbnails_upload_initialize",
headers={"x-api-key": os.environ["VOICECHEAP_API_KEY"]},
json={"requestId": "19372a86-ee2f-4c6d-835b-ec1b10b7c68b", "filename": "reference.png", "contentType": "image/png", "fileSize": 7340032},
timeout=120,
)
body = response.json()
if not response.ok:
raise RuntimeError(f"{body.get('code')}: {body.get('message')}")
print(body)
{
"data": {
"uploadId": "c547fb7f-f334-46a8-a8bb-80b5b343889a",
"key": "uploads/example-user/2502829e-3fde-4aad-b3c7-ce0f779fa2e6-reference.png",
"partSize": 5242880,
"maxConcurrency": 4
},
"requestId": "19372a86-ee2f-4c6d-835b-ec1b10b7c68b"
}
{
"data": {
"requestId": "19372a86-ee2f-4c6d-835b-ec1b10b7c68b",
"operation": "thumbnails_upload_initialize",
"createdAt": 1792144800000,
"updatedAt": 1792144820000,
"status": "running",
"pollAfterSeconds": 5
},
"requestId": "19372a86-ee2f-4c6d-835b-ec1b10b7c68b"
}
{
"data": {
"requestId": "19372a86-ee2f-4c6d-835b-ec1b10b7c68b",
"operation": "thumbnails_upload_initialize",
"createdAt": 1792144800000,
"updatedAt": 1792144820000,
"status": "completed",
"resultStored": false,
"message": "The action completed. Retrieve its output from the corresponding history or resource action."
},
"requestId": "19372a86-ee2f-4c6d-835b-ec1b10b7c68b"
}
准备上传最大 8 MiB 的 JPG、PNG 或 WebP 参考图像。使用 thumbnails_upload_sign_parts 获取 PUT URL,上传文件字节后调用 thumbnails_upload_complete,并在生成时使用其 fileKey。
所需权限:
POST https://api.voicecheap.ai/v1/actions/thumbnails_upload_initialize
身份验证和权限
string
必填
在此请求头中发送 VoiceCheap API 密钥。也支持通过 Authorization: Bearer 发送同一 API 密钥。OAuth 访问令牌仅适用于 MCP,此 REST 端点不接受 OAuth
访问令牌。
thumbnails:write.
需要有效的付费订阅。权限不会改变团队角色、资源归属、媒体额度或套餐限制。
参数
string
在传输层可选:如果省略,服务器会在验证前注入标识符。请自行提供稳定的 UUID v4,以便在响应丢失后安全恢复。格式: “uuid”. 匹配模式:
^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$.string
必填
图像文件名,其扩展名须与 contentType 匹配。最小长度: 1. 最大长度: 250. 匹配模式:
\.(?:jpe?g|png|webp)$.string
必填
文本值。允许的值: “image/jpeg”, “image/png”, “image/webp”.
integer
必填
精确文件大小,单位为字节,最大为 8 MiB。最小值: 1. 最大值: 8388608.
完整输入架构
完整输入架构
以下 JSON Schema 保留了发现接口公开的确切字段名、嵌套类型、默认值、范围和可接受值。其他跨字段规则列于操作说明中。
{
"type": "object",
"properties": {
"requestId": {
"description": "UUID v4 for this action. Reuse the same ID with identical arguments on retries.",
"type": "string",
"format": "uuid",
"pattern": "^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$"
},
"filename": {
"type": "string",
"minLength": 1,
"maxLength": 250,
"pattern": "\\.(?:jpe?g|png|webp)$",
"description": "The image filename, with an extension matching contentType."
},
"contentType": {
"type": "string",
"enum": ["image/jpeg", "image/png", "image/webp"]
},
"fileSize": {
"type": "integer",
"minimum": 1,
"maximum": 8388608,
"description": "Exact file size in bytes, up to 8 MiB."
}
},
"required": ["filename", "contentType", "fileSize"],
"additionalProperties": false
}
幂等性
为每次修改操作在 requestId 或 Idempotency-Key HTTP 请求头中提供 UUID v4。网络故障后,请使用相同标识符和完全相同的参数重试。如果同时提供这两个值,它们必须一致。重放已保存的请求不会重复执行操作,也不会再次扣除月度调用次数。失败或中断的请求不会自动重新执行。 对于每次修改操作,如果重试时发现同一请求仍在运行,即使首次执行通常为同步操作,也可能返回 HTTP 202。如果执行已完成但 resultStored 为 false,重试会返回 HTTP 200 和已保存的请求状态,而非原始结果。请通过对应领域的历史记录、结果或下载操作获取输出。请求示例
请将示例资源标识符和媒体键替换为账户返回的值。重试同一次修改操作时,请保持请求标识符不变。curl --request POST 'https://api.voicecheap.ai/v1/actions/thumbnails_upload_initialize' \
--header "x-api-key: $VOICECHEAP_API_KEY" \
--header 'Content-Type: application/json' \
--data '{"requestId":"19372a86-ee2f-4c6d-835b-ec1b10b7c68b","filename":"reference.png","contentType":"image/png","fileSize":7340032}'
const input = {
requestId: '19372a86-ee2f-4c6d-835b-ec1b10b7c68b',
filename: 'reference.png',
contentType: 'image/png',
fileSize: 7340032,
};
const response = await fetch('https://api.voicecheap.ai/v1/actions/thumbnails_upload_initialize', {
method: 'POST',
headers: {
'x-api-key': process.env.VOICECHEAP_API_KEY,
'Content-Type': 'application/json',
},
body: JSON.stringify(input),
});
const body = await response.json();
if (!response.ok) throw new Error(body.code + ': ' + body.message);
console.log(body);
import os
import requests
response = requests.post(
"https://api.voicecheap.ai/v1/actions/thumbnails_upload_initialize",
headers={"x-api-key": os.environ["VOICECHEAP_API_KEY"]},
json={"requestId": "19372a86-ee2f-4c6d-835b-ec1b10b7c68b", "filename": "reference.png", "contentType": "image/png", "fileSize": 7340032},
timeout=120,
)
body = response.json()
if not response.ok:
raise RuntimeError(f"{body.get('code')}: {body.get('message')}")
print(body)
响应
首次执行成功时返回 HTTP 200,操作结果位于 data 下。重放请求时可能改为返回已保存的请求状态。示例展示了一种支持的响应,并未包含所有可选字段。 新的多分片图片参考文件上传会话、未来的对象键、以字节为单位的分片大小,以及最大并行上传数量。此操作不会上传任何图片字节,也不会使 key 达到可用于生成的就绪状态。{
"data": {
"uploadId": "c547fb7f-f334-46a8-a8bb-80b5b343889a",
"key": "uploads/example-user/2502829e-3fde-4aad-b3c7-ce0f779fa2e6-reference.png",
"partSize": 5242880,
"maxConcurrency": 4
},
"requestId": "19372a86-ee2f-4c6d-835b-ec1b10b7c68b"
}
{
"data": {
"requestId": "19372a86-ee2f-4c6d-835b-ec1b10b7c68b",
"operation": "thumbnails_upload_initialize",
"createdAt": 1792144800000,
"updatedAt": 1792144820000,
"status": "running",
"pollAfterSeconds": 5
},
"requestId": "19372a86-ee2f-4c6d-835b-ec1b10b7c68b"
}
{
"data": {
"requestId": "19372a86-ee2f-4c6d-835b-ec1b10b7c68b",
"operation": "thumbnails_upload_initialize",
"createdAt": 1792144800000,
"updatedAt": 1792144820000,
"status": "completed",
"resultStored": false,
"message": "The action completed. Retrieve its output from the corresponding history or resource action."
},
"requestId": "19372a86-ee2f-4c6d-835b-ec1b10b7c68b"
}
结果字段
| 字段 | 说明 |
|---|---|
data.uploadId | 标识活动上传会话的 UUID。请将其传给其余上传操作。 |
data.key | 将由当前账户拥有的对象键。请使用成功完成上传后返回的 fileKey 作为生成引用。 |
data.partSize | 所需的分片大小,以字节为单位;最后一个分片包含剩余字节,大小可不同。 |
data.maxConcurrency | 建议的最大并行分片上传数:4。 |
恢复并轮询此请求
即使连接丢失,也应使用同一标识符。如果 resultStored 为 false,请通过相应的历史记录、结果或下载操作获取输出。切勿仅为查看进度而启动第二次生成。curl --request POST 'https://api.voicecheap.ai/v1/actions/action_request_get' \
--header "x-api-key: $VOICECHEAP_API_KEY" \
--header 'Content-Type: application/json' \
--data '{"requestId":"19372a86-ee2f-4c6d-835b-ec1b10b7c68b","operation":"thumbnails_upload_initialize"}'
HTTP 200
{
"data": {
"requestId": "19372a86-ee2f-4c6d-835b-ec1b10b7c68b",
"operation": "thumbnails_upload_initialize",
"status": "completed",
"createdAt": 1792144800000,
"updatedAt": 1792144820000,
"resultStored": true,
"result": {
"uploadId": "c547fb7f-f334-46a8-a8bb-80b5b343889a",
"key": "uploads/example-user/2502829e-3fde-4aad-b3c7-ce0f779fa2e6-reference.png",
"partSize": 5242880,
"maxConcurrency": 4
}
}
}
操作说明
- 需要 thumbnails:write 权限;无需额外的上传权限范围。
- filename 会去除首尾空白,长度必须为 1–250 个字符,且必须以 .jpg、.jpeg、.png 或 .webp 结尾。扩展名必须与 contentType 匹配:image/jpeg、image/png 或 image/webp。fileSize 是精确的整数字节数,范围为 1 至 8,388,608。
- 对于这些参考文件,共用的上传实现返回的 partSize 为 5 MiB(5,242,880 bytes)。不超过 5 MiB 的文件使用一个分片;大于 5 MiB 且不超过 8 MiB 的文件使用两个分片。使用 thumbnails_upload_sign_parts 请求 PUT URL,上传字节数据,然后调用 thumbnails_upload_complete。
- 将完成上传后返回的 fileKey 作为 thumbnails_generate 中 referenceImageKeys 的一项。初始化结果使用 key,而不是 fileKey。完成上传前,请勿将 key 传给生成操作。
- 生产环境的上传会话在 24 小时后过期。签名分片 URL 在一小时后过期。完成和中止操作会移除活动会话;此后 sign-parts 和 complete 均返回 Upload not found。这两类响应都不包含 expiresAt 字段。
- 此操作使用已连接用户自己的生成内容和上传文件,包括凭据在团队上下文中连接时。
- 请使用 UUID v4 requestId 或 HTTP Idempotency-Key 标头,并在重试时以完全相同的输入重复使用。集成层会记录每次变更,并返回其已记录的状态或结果,不会重新执行。失败或中断的请求不会自动重试。
- 对象键中的文件名会经过清理,且可能被缩短。请保留返回的完整 key 和 uploadId,不要自行构造。生成时会验证图像字节,上传时也会验证声明的大小和类型。
用量
每次成功调用消耗一次月度 API/MCP 调用额度。媒体额度和操作本身的生成限额也适用。错误
| HTTP 状态 | 代码 | 含义或恢复方式 |
|---|---|---|
| 400 | CREDENTIAL_IN_QUERY | 凭证通过 access_token 或 api_key 查询参数提供。请在标头中发送凭证。 |
| 400 | IDEMPOTENCY_CONFLICT | Idempotency-Key 请求头必须与请求体中的 requestId 字段一致。 |
| 400 | INVALID_REQUEST_ID | requestId 或 Idempotency-Key 不是 UUID v4。 |
| 400 | REFERENCE_IMAGE_INVALID | 文件扩展名与声明的图片 contentType 不匹配。 |
| 400 | VALIDATION_ERROR | 某个参数缺失、值不受支持、超出限额,或不属于严格输入架构。 |
| 401 | API_KEY_EXPIRED | API 密钥已过期。 |
| 401 | INVALID_API_KEY | 请提供有效且未过期的 API 密钥。 |
| 401 | INVALID_CREDENTIAL | Authorization 标头格式错误或与 x-api-key 冲突。 |
| 401 | MISSING_CREDENTIAL | 未提供可用的请求头凭据,或其长度超过 4096 个字符。 |
| 401 | USER_NOT_FOUND | 该凭据对应的账户已不存在。 |
| 403 | ACCOUNT_UNAVAILABLE | 调用者账户或计费账户不可用,或正在删除。 |
| 403 | AMBIGUOUS_TEAM_API_KEY | 此凭据对应的用户属于多个团队,因此计费上下文不明确。 |
| 403 | INSUFFICIENT_SCOPE | 请授予全部所需权限,或选择其他凭据。 |
| 403 | INTEGRATION_PLAN_UNSUPPORTED | 无法验证该账户的集成限制。 |
| 403 | SUBSCRIPTION_REQUIRED | 请使用有效的付费订阅。 |
| 403 | TEAM_OWNER_NOT_FOUND | 找不到实际生效的团队所有者账户。 |
| 409 | CONCURRENT_ACTION_LIMIT_REACHED | 此账户已有 10 个集成操作正在运行。请先轮询现有请求,再启动另一个操作。 |
| 409 | IDEMPOTENCY_CONFLICT | 该请求标识符已用于不同参数;请求头与请求体中的标识符不一致时,也会返回相同代码及 HTTP 400。 |
| 429 | INTEGRATION_MONTHLY_LIMIT_REACHED | 请等待月度额度重置,或更改套餐。 |
| 429 | INTEGRATION_RATE_LIMIT_REACHED | 如果提供了 Retry-After,请等待其指定的时间,并采用退避重试。 |
| 500 | INTERNAL_ERROR | 在决定是否重试修改操作前,请检查已保存的请求状态和资源历史记录。 |
| 503 | ACTION_RESULT_UNAVAILABLE | 操作已执行,但未能保存结果。在启动新的生成前,请检查已保存的请求状态和资源历史记录。 |
| 503 | INTERNAL_ERROR | 无法创建或保存上传会话。请使用相同的写入操作标识符重试,并检查其记录状态。 |
| 503 | SERVER_RESTARTING | 服务器正在重启。请稍后重试;对于修改操作,请保持请求标识符不变。 |
{
"code": "INSUFFICIENT_SCOPE",
"message": "This credential does not permit the requested action.",
"status": 403,
"details": {
"requiredScopes": ["thumbnails:write"]
}
}
此页面对您有帮助吗?

