跳到导航

错误

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

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系统当前繁忙。请稍后重试。
daily_generation_limit_reachedrate_limit_error

已达到图片、视频及其他创意内容的每日生成上限。 Go、Starter 和 Creator 套餐在任意连续 24 小时内最多可生成 1,000 次。升级至 Pro、Scale 或企业版可无限制进行每日生成。

insufficient_creditspayment_required账户积分不足,无法执行此操作。
internal_errorinternal_error发生意外错误。如持续出现,请联系支持团队。
service_unavailableservice_unavailable服务暂时不可用。请稍后重试。
maintenanceservice_unavailable服务正在进行计划维护。