リファレンス
SDK
QiClient をコードにインポートします。CLI と MCP サーバーはこのクライアントを包むシェルです。ここでの修正は 3 つすべてに反映されます。
インストール
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 | 1 ページ分: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.