账号
创建账号
创建渠道账号。auth_mode 必填且仅可为 qrcode、code 或 session。当 provider 与 auth_mode 组合要求手机号时(例如 WhatsApp + auth_mode=code),必须通过 provider_data.phone 提供;该值会持久化并在后续认证动作中复用。 余额模式直接创建,无需先获取报价;201 表示建号与扣款已提交,授权前仍须核对 billing.state。同工作区已有建号进行中返回 409 wallet_account_creation_in_progress。Idempotency-Key 可选;超时先核对结果,只有使用原键重试才能保证不重复购买。
https://api.unifyport.ai/v1/accounts支持的渠道
调用前准备
在服务端使用资源所属工作区的 X-Api-Key。运行示例前替换所有占位符。
使用目标工作区的 API Key。余额模式账号按 30 天以 USD 计费;钱包余额和充值请在 Dashboard 查看。
请求参数
请求头
X-Api-Key工作区 API Key,工作区由该请求头解析得到。
Content-Type发送 JSON 请求体时使用 application/json。
Idempotency-Key余额建号可选传单个 Idempotency-Key;同一业务请求及未知结果重试沿用原键。不传时前一笔完成后的再次请求会新建账号。
请求体
name可读的账号名称。
provider客户可用的渠道标识:telegram、whatsapp、whatsapp-protocol、line、twitter、zalo 或 tiktok。
enum: telegram, whatsapp, line, twitter, zalo, tiktok, whatsapp-protocol, x, x_client, twitter_client
region用于分配的渠道区域。请通过 列出渠道区域 选择 allocatable: true 的区域。
minLength: 1
status账号业务状态,例如 active 或 inactive。
runtime_status渠道支持通过账号配置修改时,请求设置的运行时状态。
enum: unknown, starting, running, stopping, stopped, reconnecting, disconnected, error
auth_mode创建账号时必填;认证流程仅可为 qrcode、code 或 session。
enum: qrcode, code, session
capabilities[]账号能力列表。PATCH 时省略表示保留,传 [] 表示清空,null 非法。
metadata平台侧元数据。PATCH 时省略表示保留,传 {} 表示清空,null 非法。
provider_account_ref渠道侧账号标识,通常在授权完成后由系统写入。
provider_data渠道配置。PATCH 时省略表示保留,{} 清空且不补充默认凭证,null 非法。TikTok provider_data.enable_comment 仅接受 Boolean,默认 false;字符串、数字、null 返回 400 invalid_request。在线修改需 reconnect,start 成功不证明配置已应用;关闭不撤回已排队事件。Telegram 的 code、qrcode、session 均可省略 api_id 和 api_hash;自定义凭证须为同一应用的成对字符串。创建时未指定自定义凭证、非空配置替换时缺省凭证字段,均使用平台默认值;所需默认配置不可用时请求失败。平台默认凭证变更不会替换已有账号凭证。请勿记录密钥。
proxy该账号可选的出站代理配置。
如何理解结果
余额模式直接创建,无需先获取报价;201 表示建号与扣款已提交,授权前仍须核对 billing.state。同工作区已有建号进行中返回 409 wallet_account_creation_in_progress。Idempotency-Key 可选;超时先核对结果,只有使用原键重试才能保证不重复购买。
响应 201 · PREPAID_QUOTA
{
"request_id": "<REQUEST_ID>",
"data": {
"id": "acc_example",
"name": "Telegram Production",
"provider": "telegram",
"region": "<REGION>",
"status": "active",
"runtime_status": "stopped",
"auth_mode": "qrcode",
"capabilities": [
"send_message",
"receive_message"
]
}
}
响应 201 · ACCOUNT_WALLET_30D
{
"request_id": "<REQUEST_ID>",
"data": {
"id": "acc_example",
"name": "Messaging account",
"provider": "telegram",
"region": "<REGION>",
"status": "active",
"runtime_status": "stopped",
"auth_mode": "qrcode",
"capabilities": [
"send_message",
"receive_message"
],
"billing": {
"period_start_at": "2026-10-19T00:00:00Z",
"period_end_at": "2026-11-18T00:00:00Z",
"amount_minor": 1000,
"currency": "USD",
"operation_id": "op_example",
"state": "ACTIVE"
}
}
}
响应体
provider_profileobject渠道上报的资料,例如 display_name;账号认证完成前不返回。
provider_profile渠道上报的资料,例如 display_name;账号认证完成前不返回。
id渠道侧账号标识。WhatsApp 返回 LID;账号资料同步完成前可能省略。
device_id仅 WhatsApp 账号详情在可确认当前会话时提供的可选登录设备编号;重新授权后可能变化,不作为永久设备标识。
minimum: 0 · maximum: 65535
phone已归一化的账号手机号,不含空格、连字符和开头加号。
username渠道上报的用户名(如有)。
display_name账号展示名称;WhatsApp 按 BusinessName 优先、PushName 回退的规则生成。
push_nameWhatsApp 当前账号设置的 PushName;其他渠道不定义该字段语义。
business_nameWhatsApp BusinessName;渠道未返回时该字段缺失。
first_name渠道上报的名字(如有)。
last_name渠道上报的姓氏(如有)。
avatar_url渠道上报的账号头像 URL(如有)。
bio渠道上报的账号简介或状态文本(如有)。
platformWhatsApp 配对时上报的登录平台标识。请将其视为不透明字符串并兼容未知值;其他渠道不定义该字段语义。该字段与 device_platform 不同。
billingobject消息账号已付周期,仅余额账号存在;不能从钱包余额推断已购买。
billing消息账号已付周期,仅余额账号存在;不能从钱包余额推断已购买。
period_start_at服务端返回的已付周期起点。
format: date-time
period_end_at服务端返回的已付周期终点。
format: date-time
amount_minor服务端不可变金额,单位为 USD 分,须按精确整数处理。
minimum: 1 · format: int64
currency仅 USD。
operation_id来自 billing.operation_id 或删除响应的公开标识,在原工作区原样复用。
state计费或操作状态,不证明账号已授权、在线或退款已入账。
enum: ACTIVE, DELETING, DELETED, COMPENSATED, REVIEW
id账号唯一标识(acc_...),用于账号维度的路由。
name可读的账号名称。
provider渠道标识。调用其他接口时原样使用 API 返回的值;此接口的返回范围见下方枚举。
enum: telegram, whatsapp, line, twitter, zalo, tiktok, whatsapp-protocol
region该账号被分配到的渠道区域。
status账号生命周期状态,例如 active。
runtime_status标准化的运行时状态,取值之一:unknown、starting、running、stopping、stopped、reconnecting、disconnected 或 error。
enum: unknown, starting, running, stopping, stopped, reconnecting, disconnected, error
auth_mode账号使用的认证流程:code、qrcode 或 session。
capabilities[]账号已启用的能力,例如 send_message 与 receive_message。
metadata存储在账号上的自有环境标签。
provider_account_ref渠道侧标识,可附加用于将该账号与你自有系统关联。
proxy账号绑定的出站代理配置,未配置时省略。
响应
201201 Created
请求成功,响应体示例如上。
400请求错误
请求体、路径或参数不合法。
401未授权
X-Api-Key 请求头缺失或无效。
403禁止访问
请求已识别,但不允许执行该操作。
404未找到
未找到请求的资源;请结合 error.code 和当前操作核对。
409冲突
当前操作与已有的渠道账号或资源冲突。
500服务端错误
服务端遇到了未预期的错误。
503服务不可用
所需的后端服务暂时不可用。
失败后怎么处理
检查 HTTP 状态和 error.code/numeric_code,保存 request_id 用于排查。按原因修正参数、继续授权或检查运行态。重试发送及其他写操作前先确认上一次结果,避免重复操作。 错误码参考
结合当前操作读取 HTTP 状态、error.code 和 error.numeric_code。数字码按字符串处理。保留 request_id 排障;它不是幂等键或任务标识。
- auth_mode_phone_required · 20019 · 400
此授权方式要求创建账号时填写 provider_data.phone。
处理与重试: 按当前操作与渠道条件修正参数后再请求。重复提交相同的无效请求不会解决错误。
示意 JSON;message 随实际原因变化 · 400 · 20019
{ "request_id": "req_example", "error": { "code": "auth_mode_phone_required", "numeric_code": "20019", "message": "Phone number is required for this auth mode" } }- invalid_request · 10000 · 400
检查 JSON 请求体和必填字段。
处理与重试: 按当前操作与渠道条件修正参数后再请求。重复提交相同的无效请求不会解决错误。
示意 JSON;message 随实际原因变化 · 400 · 10000
{ "request_id": "req_example", "error": { "code": "invalid_request", "numeric_code": "10000", "message": "Invalid request parameters" } }- invalid_target_workspace · 11003 · 400
工作区覆盖目标为空或格式无效。移除覆盖请求头,改用目标工作区所属的 API Key。
触发条件: 适用于携带 X-Workspace-Id 工作区覆盖请求头的请求。
处理与重试: 按当前操作与渠道条件修正参数后再请求。重复提交相同的无效请求不会解决错误。
示意 JSON;message 随实际原因变化 · 400 · 11003
{ "request_id": "req_example", "error": { "code": "invalid_target_workspace", "numeric_code": "11003", "message": "Invalid target workspace" } }- unsupported_provider_auth_mode · 20018 · 400
请使用此渠道支持的 auth_mode。
处理与重试: 选择文档列为支持的渠道与动作。重复请求不会增加能力或开通内测权限。
示意 JSON;message 随实际原因变化 · 400 · 20018
{ "request_id": "req_example", "error": { "code": "unsupported_provider_auth_mode", "numeric_code": "20018", "message": "Auth mode not supported by this provider" } }- wallet_invalid_request · 20021 · 400
请检查余额建号参数,以及可选的 Idempotency-Key 请求头。
处理与重试: 按当前操作与渠道条件修正参数后再请求。重复提交相同的无效请求不会解决错误。
示意 JSON;message 随实际原因变化 · 400 · 20021
{ "request_id": "req_example", "error": { "code": "wallet_invalid_request", "numeric_code": "20021", "message": "Invalid wallet account request" } }- invalid_api_key · 11001 · 401
检查 API Key 是否正确且已启用。
处理与重试: 保留 request_id 与结构化错误码,先排查当前操作,再决定下一步。
示意 JSON;message 随实际原因变化 · 401 · 11001
{ "request_id": "req_example", "error": { "code": "invalid_api_key", "numeric_code": "11001", "message": "Invalid API key" } }- missing_api_key · 11000 · 401
请添加 X-Api-Key 请求头。
处理与重试: 保留 request_id 与结构化错误码,先排查当前操作,再决定下一步。
示例 · 401 · 11000
{ "request_id": "req_xxx", "error": { "code": "missing_api_key", "numeric_code": "11000", "message": "Missing X-Api-Key header" } }- workspace_override_forbidden · 11002 · 403
请求尝试使用此 API Key 无权使用的工作区覆盖。移除覆盖请求头,改用目标工作区所属的 API Key。
触发条件: 适用于携带 X-Workspace-Id 工作区覆盖请求头的请求。
处理与重试: 保留 request_id 与结构化错误码,先排查当前操作,再决定下一步。
示意 JSON;message 随实际原因变化 · 403 · 11002
{ "request_id": "req_example", "error": { "code": "workspace_override_forbidden", "numeric_code": "11002", "message": "Workspace override is not allowed" } }- target_workspace_not_found · 11004 · 404
覆盖指定的工作区不存在或不可用。核对工作区归属,移除覆盖请求头并使用目标工作区 API Key;重复请求不会增加访问权限。
触发条件: 适用于携带 X-Workspace-Id 工作区覆盖请求头的请求。
处理与重试: 核对目标标识、资源归属与当前工作区。不要把已确认缺失或无法访问的目标当作临时服务故障自动重试。
示意 JSON;message 随实际原因变化 · 404 · 11004
{ "request_id": "req_example", "error": { "code": "target_workspace_not_found", "numeric_code": "11004", "message": "Target workspace not found" } }- account_allocation_busy · 20011 · 409
账号正在分配,请稍后重试。
处理与重试: 保留 request_id 与结构化错误码,先排查当前操作,再决定下一步。
示意 JSON;message 随实际原因变化 · 409 · 20011
{ "request_id": "req_example", "error": { "code": "account_allocation_busy", "numeric_code": "20011", "message": "Allocation is busy in the current region; please retry later" } }- duplicate_provider_account · 20015 · 409
工作区内已有另一个账号绑定相同的渠道身份。
处理与重试: 保留 request_id 与结构化错误码,先排查当前操作,再决定下一步。
示意 JSON;message 随实际原因变化 · 409 · 20015
{ "request_id": "req_example", "error": { "code": "duplicate_provider_account", "numeric_code": "20015", "message": "A provider account with the same identity already exists in this workspace" } }- no_allocatable_server · 20013 · 409
此区域暂无可分配资源,请查询其他可分配区域。
处理与重试: 保留 request_id 与结构化错误码,先排查当前操作,再决定下一步。
示意 JSON;message 随实际原因变化 · 409 · 20013
{ "request_id": "req_example", "error": { "code": "no_allocatable_server", "numeric_code": "20013", "message": "No allocatable server in the current region" } }- wallet_account_creation_in_progress · 20030 · 409
当前工作区已有余额账号正在创建,请等待完成后再试。
处理与重试: 保留 request_id 与结构化错误码,先排查当前操作,再决定下一步。
示意 JSON;message 随实际原因变化 · 409 · 20030
{ "request_id": "req_example", "error": { "code": "wallet_account_creation_in_progress", "numeric_code": "20030", "message": "Account creation is in progress; please wait" } }- wallet_idempotency_conflict · 20024 · 409
幂等键已绑定其他业务参数,请先核对原操作结果,避免重复建号。
处理与重试: 保留 request_id 与结构化错误码,先排查当前操作,再决定下一步。
示意 JSON;message 随实际原因变化 · 409 · 20024
{ "request_id": "req_example", "error": { "code": "wallet_idempotency_conflict", "numeric_code": "20024", "message": "Idempotency key was used for a different request" } }- wallet_insufficient_funds · 20023 · 409
钱包不足以支付本次建号,所有者可充值后确认原请求。
处理与重试: 保留 request_id 与结构化错误码,先排查当前操作,再决定下一步。
示意 JSON;message 随实际原因变化 · 409 · 20023
{ "request_id": "req_example", "error": { "code": "wallet_insufficient_funds", "numeric_code": "20023", "message": "Insufficient wallet balance" } }- wallet_workspace_disabled · 20022 · 409
新余额消费已关闭;不代表既有账号操作已取消。
处理与重试: 保留 request_id 与结构化错误码,先排查当前操作,再决定下一步。
示意 JSON;message 随实际原因变化 · 409 · 20022
{ "request_id": "req_example", "error": { "code": "wallet_workspace_disabled", "numeric_code": "20022", "message": "New wallet purchases are disabled" } }- workspace_account_quota_exceeded · 20014 · 409
工作区消息账号额度已用满,请检查用量与额度。
处理与重试: 保留 request_id 与结构化错误码,先排查当前操作,再决定下一步。
示意 JSON;message 随实际原因变化 · 409 · 20014
{ "request_id": "req_example", "error": { "code": "workspace_account_quota_exceeded", "numeric_code": "20014", "message": "Workspace account quota exceeded" } }- create_account_failed · 20002 · 500
创建账号:资源创建失败或无法确认创建结果。
处理与重试: 再次创建前先列出或查询已有资源,确认上次创建是否已生效。修正根本原因并保留 request_id,不要自动创建重复资源。
示意 JSON;message 随实际原因变化 · 500 · 20002
{ "request_id": "req_example", "error": { "code": "create_account_failed", "numeric_code": "20002", "message": "Failed to create account" } }- allocation_service_unavailable · 20012 · 503
账号分配服务暂不可用,请稍后重试。
处理与重试: 保留 request_id 与结构化错误码,先排查当前操作,再决定下一步。
示意 JSON;message 随实际原因变化 · 503 · 20012
{ "request_id": "req_example", "error": { "code": "allocation_service_unavailable", "numeric_code": "20012", "message": "Allocation service is temporarily unavailable" } }- wallet_unavailable · 20028 · 503
钱包数据或配置暂不可用;写入失败可能结果未知,请核对原操作。
处理与重试: 先读取资源当前状态,确认上一次改动结果,再决定是否重试。保留 request_id;结果未知时不要自动重复写入。
示意 JSON;message 随实际原因变化 · 503 · 20028
{ "request_id": "req_example", "error": { "code": "wallet_unavailable", "numeric_code": "20028", "message": "Wallet service is unavailable" } }