错误

查看错误消息和解决方案。

API 错误

ElevenLabs 使用标准 HTTP 状态码表示请求成功或失败。此外,所有 API 请求都会返回一个 JSON 对象,其中的 detail 属性包含错误信息。

通常,200 HTTP 状态码表示请求成功。4xx 代码表示请求存在问题,例如参数无效或缺少必填字段。500 HTTP 状态码表示 ElevenLabs 服务器出现问题,这种情况应较少发生。

错误属性

属性说明
type发生的错误类型。可能的值请参见下表。
code错误代码。它比类型更具体,可用于确定错误原因。
message错误消息,提供有关错误的更多详情。
status错误状态。这是一个不再使用的旧字段,请改用 code 属性。
request_id错误的请求 ID。这是请求的唯一标识符,可用于排查错误。
param导致错误的参数。如果是验证错误,该字段会指明无效参数。

错误响应示例

以下是使用错误模型 ID 的 API 请求响应:

{
"detail": {
"type": "validation_error",
"code": "invalid_parameters",
"message": "The 'keyterms' parameter is only supported with the 'scribe_v2' model. You specified 'scribe_v1'.",
"status": "invalid_parameters",
"request_id": "3c807fc4c3a1705f9638ecc764a91c01",
"param": "keyterms"
}
}

通过这些错误属性可以看到,这是一个验证错误,代码为 invalid_parameters。消息提供了错误的更多详情,request_id 是可用于排查错误的请求唯一标识符。param 属性指明了导致错误的参数。

SDK 错误处理

ElevenLabs SDK 提供类型化错误类,可让你访问错误详情。

from elevenlabs import ElevenLabs
from elevenlabs.core import ApiError
elevenlabs = ElevenLabs()
try:
audio = elevenlabs.text_to_speech.convert(
voice_id="invalid-voice-id",
model_id="eleven_v4",
text="Hello, world!",
)
except ApiError as e:
print(f"Status code: {e.status_code}")
# Access the error body
if e.body and "detail" in e.body:
detail = e.body["detail"]
print(f"Error type: {detail.get('type')}")
print(f"Error code: {detail.get('code')}")
print(f"Message: {detail.get('message')}")
print(f"Request ID: {detail.get('request_id')}")
# Handle specific error types
if detail.get("type") == "rate_limit_error":
print("Rate limited - implement exponential backoff")
elif detail.get("type") == "authentication_error":
print("Check your API key")

速率限制和并发

如果收到 429 HTTP 状态码,说明你可能在短时间内发出了过多请求,超出了 API 端点的速率限制;或者超出了该 API 端点的并发限制。相应的错误 code 分别为 rate_limit_exceeded 或 concurrent_limit_exceeded。

遇到速率限制时,收到 429 错误后,应在代码中实施指数退避。这意味着在重试请求前增加延迟。

遇到并发限制时,应等待当前请求完成后再发起新请求。更多信息请参阅并发和优先级部分。

错误类型

错误会包含 type 属性,用于指明发生的错误类型。可能的值请参见下表。

类型说明HTTP 状态码
validation_error请求包含无效参数值。400
invalid_request请求结构格式错误或缺少必填字段。400
authentication_error身份验证失败:API 密钥/令牌无效或缺失。401
payment_required用户积分不足或需要付款。402
authorization_error已验证身份的用户没有执行此操作所需的权限。403
not_found未找到请求的资源。404
conflict请求与资源的当前状态冲突。409
rate_limit_error请求过多,请稍后重试。429
internal_error发生意外服务器错误。500
service_unavailable服务暂时不可用,这种情况应较少发生。503

错误代码

代码类型说明
voice_not_foundnot_found指定的音色 ID 不存在。请确认音色 ID 后重试。
sample_not_foundnot_found未找到指定的音色样本。
voice_collection_not_foundnot_found指定的音色集合不存在。
user_not_foundnot_found未找到指定用户。
auth_account_not_foundnot_found未找到身份验证账户。
workspace_not_foundnot_found指定的工作区不存在。
project_not_foundnot_found未找到指定项目。
history_item_not_foundnot_found指定的历史记录项不存在。
collection_not_foundnot_found未找到指定集合。
document_not_foundnot_found指定文档不存在。
file_not_foundnot_found未找到指定文件。
conversation_not_foundnot_found指定对话不存在。
agent_not_foundnot_found未找到指定智能体。
dubbing_not_foundnot_found指定的配音项目不存在。
song_not_foundnot_found未找到指定歌曲。
read_not_foundnot_found未找到指定的阅读内容。
pronunciation_dictionary_not_foundnot_found指定的发音词典不存在。
knowledge_base_not_foundnot_found未找到指定知识库。
phone_number_not_foundnot_found指定电话号码不存在。
tool_not_foundnot_found未找到指定工具。
snapshot_not_foundnot_found指定快照不存在。
task_not_foundnot_found未找到指定任务。
model_not_foundnot_found指定模型不存在。
transcript_not_foundnot_found未找到指定转录文本。
keywords_list_not_foundnot_found未找到指定关键词列表。
category_not_foundnot_found未找到指定类别。
text_too_longvalidation_error提供的文本超过允许的最大长度。
text_too_shortvalidation_error提供的文本短于要求的最小长度。
invalid_textvalidation_error提供的文本包含无效字符或格式。
empty_textvalidation_error文本字段不能为空。
invalid_parametersvalidation_error

一个或多个请求参数无效。请查看 param 属性以确认无效 参数。

missing_required_fieldvalidation_error

请求缺少必填字段。请查看 param 属性以确认缺失的 字段。

invalid_voice_settingsvalidation_error

音色设置包含无效值。请查看 param 属性以确认无效的音色 设置。

invalid_voice_idvalidation_error音色 ID 格式无效。
unsupported_modelvalidation_error指定模型不支持此操作。
invalid_audiovalidation_error提供的音频无效或已损坏。
invalid_audio_formatvalidation_error不支持指定的音频格式。
invalid_output_formatvalidation_error不支持请求的输出格式。
audio_too_longvalidation_error音频超过允许的最长时长。
audio_too_shortvalidation_error音频短于要求的最短时长。
invalid_file_typevalidation_error不支持该文件类型。
invalid_page_sizevalidation_error页面大小参数超出允许范围。
invalid_cursorvalidation_error分页游标无效或已过期。
bad_requestinvalid_request服务器无法理解该请求。
malformed_jsoninvalid_request请求正文包含无效 JSON。
invalid_content_typeinvalid_requestContent-Type 标头缺失或无效。
request_too_largeinvalid_request请求正文超过允许的最大大小。
invalid_api_keyauthentication_error提供的 API 密钥无效。
missing_api_keyauthentication_error请求中未提供 API 密钥。
invalid_authorization_headerauthentication_errorAuthorization 标头格式无效。
unauthorizedauthentication_error访问此资源需要进行身份验证。
sign_in_requiredauthentication_error必须登录才能执行此操作。
forbiddenauthorization_error禁止访问此资源。
insufficient_permissionsauthorization_error你没有执行此操作所需的权限。
workspace_access_deniedauthorization_error你无权访问此工作区。
feature_not_availableauthorization_error当前套餐不提供此功能。
subscription_requiredauthorization_error访问此功能需要付费订阅。
voice_access_deniedauthorization_error你无权访问此音色。
model_access_deniedauthorization_error你无权访问此模型。
conflictconflict发生冲突。
resource_already_existsconflict具有相同标识符的资源已存在。
voice_already_existsconflict此名称的音色已存在。
already_runningconflict操作已在运行。
already_processingconflict资源正在处理中。
concurrent_modificationconflict资源已被其他请求修改。请使用最新版本重试。
slug_already_existsconflict使用此 slug 的资源已存在。
rate_limit_exceededrate_limit_error请求过多。请等待后重试。
concurrent_limit_exceededrate_limit_error

超出最大并发请求数。更高订阅套餐具有更高的 并发限制。

system_busyrate_limit_error系统当前繁忙。请稍后重试。
insufficient_creditspayment_required账户没有足够积分执行此操作。
internal_errorinternal_error发生意外错误。如果问题持续存在,请联系支持团队。
service_unavailableservice_unavailable服务暂时不可用。请稍后重试。
maintenanceservice_unavailable服务正在进行计划维护。