开发者文档

API文档

企微瓣提供 HTTP + JSON 接口。目前没有官方 SDK,任何语言直接发 HTTP 请求即可;命令行场景可使用 qwb CLI。

接口地址

https://www.qiweiban.com/api

认证方式

Authorization: Bearer <token>

返回格式

{ success, data, error }

获取 Token

方式一:登录 Token。用企微瓣账号(手机号 + 密码,或手机号 + 验证码)调用登录接口换取 JWT Token,expiresIn 可选 1d、7d(默认)、30d,最长 30 天。

方式二:API Key。长期服务端集成可使用 qwb_sk_ 开头的 API Key,支持 IP 白名单。 API Key 目前由我们为您开通,请联系我们申请。

两种凭证的用法相同,都放在请求头 Authorization: Bearer ... 中。

cURL
curl -X POST https://www.qiweiban.com/api/auth/token-password \
  -H "Content-Type: application/json" \
  -d '{"phoneNumber": "13800138000", "password": "your_password", "expiresIn": "7d"}'

# 返回
{
  "success": true,
  "data": {
    "token": "eyJhbGciOi...",
    "tokenType": "Bearer",
    "expiresAt": "2026-12-05T08:00:00.000Z",
    "user": { "id": "...", "name": "...", "phoneNumber": "..." }
  }
}

常用接口

认证

POST/auth/token-password
手机号 + 密码换取 Token
POST/auth/send-verification-code
发送短信验证码
POST/auth/token
手机号 + 验证码换取 Token
GET/auth/token-info
查看当前 Token 信息

语音

GET/voice/models
音色列表(系统音色 + 我的克隆声音)
POST/voice/synthesize
语音合成
GET/voice/works
语音作品列表
GET/voice-clone/list
我的克隆声音列表

数字人

GET/digital-human/list
可用数字人列表
POST/digital-human/video/create
创建数字人视频任务
GET/digital-human/video/{videoJobId}/status
查询视频任务状态

AI 能力

GET/ai-models
可用大模型列表
POST/ai-models/chat
AI 对话
POST/image/generate
AI 生成图片

账户

GET/petals/overview
瓣值余额与会员概览
GET/petals/history
瓣值消费记录

请求参数

语音合成

POST /voice/synthesize
参数类型说明
textstring,必填要合成的文本,最长 9999 字
voiceIdstring系统音色 id(/voice/models 中 type 为 system 的 id)
voiceCloneSampleIdstring克隆声音 id(type 为 cloned 的 id),与 voiceId 二选一
speednumber语速 0.5–2.0,默认 1.0
volumenumber音量 0.1–2.0,默认 1.0
pitchnumber音调 -1.0–1.0,默认 0
emotionstringauto / happy / sad / angry / fearful / disgusted / surprised / calm / fluent,默认 auto
formatstringmp3 / wav / pcm,默认 mp3
subtitleEnableboolean是否返回字幕时间轴,默认 false
titlestring作品标题

数字人视频

POST /digital-human/video/create
参数类型说明
digitalHumanIdstring,必填数字人 id(/digital-human/list)
scriptstring口播文本,文本模式必填
audioUrlstring已有音频地址,传入后按音频驱动,不再合成语音
voiceId / voiceCloneSampleIdstring指定配音音色,不传则使用数字人绑定的默认声音
aspectRatiostring'9:16' 或 '16:9'
speednumber语速
isRemoveBgboolean是否去除数字人背景(需数字人支持)

AI 对话

POST /ai-models/chat
参数类型说明
userInputstring,必填用户输入
modelIdstring模型 id(/ai-models),不传使用默认模型
systemPromptstring系统提示词
temperaturenumber0–2,默认 0.7
maxTokensnumber1–8192,默认 2048

图片生成

POST /image/generate
参数类型说明
promptstring,必填图片描述
imagestring | string[]参考图 URL(http/https),用于图生图
sizestring'2k'、'3k' 或 '1024x1024' 这样的宽x高,默认 2k
watermarkboolean是否添加水印,默认 true

代码示例

语音合成

cURL
curl -X POST https://www.qiweiban.com/api/voice/synthesize \
  -H "Authorization: Bearer $QWB_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "text": "大家好,欢迎使用企微瓣。",
    "voiceId": "<系统音色 id,来自 /voice/models>",
    "speed": 1.0,
    "format": "mp3"
  }'

# 使用自己的克隆声音:把 voiceId 换成 "voiceCloneSampleId": "<克隆声音 id>"
# 返回 data.audioUrl(音频地址)、data.costInPetals(消耗瓣值)、data.remainingBalance

生成数字人视频并等待完成

JavaScript (fetch)
const BASE_URL = 'https://www.qiweiban.com/api';
const headers = {
  'Authorization': `Bearer ${process.env.QWB_TOKEN}`,
  'Content-Type': 'application/json',
};

// 1. 创建数字人视频任务(digitalHumanId 来自 GET /digital-human/list)
const createRes = await fetch(`${BASE_URL}/digital-human/video/create`, {
  method: 'POST',
  headers,
  body: JSON.stringify({
    digitalHumanId: '<数字人 id>',
    script: '大家好,欢迎使用企微瓣。',
    aspectRatio: '9:16', // 或 '16:9'
  }),
});
const { data } = await createRes.json();
const videoJobId = data.videoJobId;

// 2. 轮询任务状态:PENDING / PROCESSING / COMPLETED / FAILED
while (true) {
  const res = await fetch(`${BASE_URL}/digital-human/video/${videoJobId}/status`, { headers });
  const { data: job } = await res.json();
  if (job.status === 'COMPLETED') { console.log(job.videoUrl); break; }
  if (job.status === 'FAILED') throw new Error(job.errorMessage);
  await new Promise((r) => setTimeout(r, 10_000));
}
Python (requests)
import os, time, requests

BASE_URL = "https://www.qiweiban.com/api"
headers = {"Authorization": f"Bearer {os.environ['QWB_TOKEN']}"}

res = requests.post(f"{BASE_URL}/digital-human/video/create", headers=headers, json={
    "digitalHumanId": "<数字人 id>",
    "script": "大家好,欢迎使用企微瓣。",
    "aspectRatio": "9:16",
})
video_job_id = res.json()["data"]["videoJobId"]

while True:
    job = requests.get(f"{BASE_URL}/digital-human/video/{video_job_id}/status", headers=headers).json()["data"]
    if job["status"] == "COMPLETED":
        print(job["videoUrl"]); break
    if job["status"] == "FAILED":
        raise RuntimeError(job["errorMessage"])
    time.sleep(10)

计费与错误

  • 接口调用按账户瓣值扣费,与网页端价格一致;余额可通过 GET /petals/overview 查询。
  • 401:Token 缺失、无效或已过期;400:参数错误;429:登录请求过于频繁;瓣值不足时请求会失败并在 error 中说明。
  • 出错时响应体为 { "success": false, "error": "错误说明" }。

需要 API Key 或技术支持?

开通 API Key、对接问题或需要更多接口,请联系我们