参考
SDK
在你的代码中导入 QiClient。CLI 和 MCP 服务器都是围绕该客户端的外壳:在此修复的问题会同时惠及三者。
安装
与 CLI 相同的包,添加到你的项目中:npm install @sumeria.ai/qi。
# Same package as the CLI, added to your project
npm install @sumeria.ai/qi凭证
传入 API 密钥即可:它自带租户。不传参数时,凭据的解析方式与 CLI 相同:QI_API_KEY 或 qi auth login 保存的密钥。基础 URL 只是高级设置,例如用于其他环境:
// The key is enough. baseUrl is an advanced override, e.g. for a staging environment.
const staging = new QiClient({
apiKey: process.env.STAGING_QI_API_KEY,
baseUrl: process.env.STAGING_QI_BASE_URL,
});上传
uploadAudio、uploadText 和 uploadBot 接受文件路径。resolveFiles 根据文件夹和模式构建列表,nameRules 则改变每个文件发送时所用的名称。
import { QiClient, nameRules, resolveFiles } from "@sumeria.ai/qi";
const qi = new QiClient(); // QI_API_KEY, or the key "qi auth login" saved
const files = resolveFiles(["./calls"], { recursive: true, include: ["*.mp3"], exclude: ["*tmp*"] });
const report = await qi.uploadAudio(files, {
form: "VENTAS", // key, or an id resolved to its key
analysis: "full", // shared tenants: "transcript" skips evaluation
rename: nameRules({ prefix: "dev_", key: "VENTAS" }), // the name it is sent under
concurrency: 4, // requests of 10 files in flight (default 2)
retries: 3, // 429 / 5xx, exponential backoff (default 3)
onProgress: ({ done, total, file }) => console.log(done, total, file.name, file.status),
});
report.accepted; // [{ path, name, status, attempts }]
report.rejected; // ... with errors: [{ code, params }]
report.failed; // ... with message (network, 5xx after retries)
await qi.uploadText(["./chat.csv"], { form: "SOPORTE" });
await qi.uploadBot(["./chat.json"], { bot: "Asistente", form: "BOTQA" });- 文件按每批 10 个发送,并根据 concurrency 同时发送多批。
- 遇到 429 或 5xx 时采用指数退避重试,最多 retries 次。
- 发送前会在本地检查名称。被 API 拒绝的文件会被剔除,批次的其余文件会重新发送。
- 它绝不会因某个文件而抛出异常:报告会说明每个文件的情况,即已接受、带代码被拒绝,或带消息失败。
离线检查名称,规则与 API 相同:
import { QiClient, nameModeFor, validateName } from "@sumeria.ai/qi";
const qi = new QiClient();
validateName("call.mp3", nameModeFor(qi.tenant), { tenant: qi.tenant }); // [] or [{ code, params }]列表与详情
读取方法返回 API 返回的内容,已从 data 中解包。
| 方法 | 返回内容 |
|---|---|
listInteractions | 一页:data、total_records、total_pages 和 has_next_page。 |
iterateInteractions | 所有页,每次 200 条,以异步迭代器形式提供。 |
getInteraction | 详情:各阶段状态、对话和答复。 |
waitForInteraction | 等待所有阶段完成。默认上限为 10 分钟,每 5 秒轮询一次。 |
listForms | 表单,含其 id、标题、类型和键。 |
listBotProfiles | 机器人配置档案。没有该模块时返回 403 MODULE_NOT_IN_PLAN。 |
getUsage | 套餐、已用和可用的 QI 代币、周期结束时间、模块以及完整报告。 |
const page = await qi.listInteractions({ limit: 10, from: "2026-09-01", to: "2026-09-08" });
console.log(page.total_records, page.data);
for await (const row of qi.iterateInteractions({ sourceType: "audio" })) {
// every page, 200 at a time
}
const detail = await qi.getInteraction(id); // status, dialogue, answered_form, ...
const done = await qi.waitForInteraction(id, { timeout: 15 * 60_000, interval: 10_000 });
const forms = await qi.listForms({ type: "audio" }); // [{ id, title, type, key }]
const bots = await qi.listBotProfiles(); // 403 MODULE_NOT_IN_PLAN without the module
const usage = await qi.getUsage(); // { plan, tokensUsed, tokensLimit, nextPayment, modules, report }错误
任何不属于单个文件的问题都会抛出带有 status、code 和 retryable(429 和 5xx 为 true)的 QiError。withRetry 和 mapLimit 已导出,可用于你自己的调用。
import { QiError } from "@sumeria.ai/qi";
try {
await qi.listBotProfiles();
} catch (error) {
if (error instanceof QiError) {
console.error(error.status, error.code); // 403 MODULE_NOT_IN_PLAN
if (error.retryable) {
// 429 or 5xx: the same request could succeed later
}
}
}API 返回的是代码,而不是句子。QiError 使这些代码可被访问,以便提示信息遵循读者的语言。
智能体提示词
将此内容粘贴到编程智能体中,让它把 SDK 接入你的代码。
You are integrating the Sumeria Quality Intelligence SDK (@sumeria.ai/qi) into this codebase.
1. Install: npm install @sumeria.ai/qi
2. Import QiClient and QiError. new QiClient({ apiKey }) is enough: the key carries its
tenant. Without arguments it reads QI_API_KEY or the key "qi auth login" saved — never
hardcode a key in source.
3. Use client methods: qi.uploadAudio(paths, options), qi.uploadText(paths, options),
qi.listInteractions({ limit }), qi.getInteraction(id), qi.waitForInteraction(id).
4. Uploads never throw per file: read report.accepted / report.rejected / report.failed.
Other errors throw QiError — check error.code, not the message, and map codes to this
project's own user-facing copy instead of showing them raw.
5. Wire this into: <name the module or service in this codebase that should call it,
and what should happen on success and on failure>.
Ask before deciding where credentials are read from if this project already has its own
secrets convention.