@idemcore / sdk
的JavaScript / TypeScript客户端 Idemcore API。每一个聊天 答案带有签名收据,此包可以在本地检查该收据。
- 返回答案文本的聊天补全(纯文本或流文本) 和 它的收据id。
- 获取收据及其公共令牌日志。
- 本地验证收据:Ed25519签名(L1),令牌日志链(L2),以及您的 根据收据的担保承诺(披露)迅速答复。
- 服务器端检查:远程验证,在独立构建(L3)上重播,审计导出。
- 零依赖关系,
fetch+仅限WebCrypto。ESM与TypeScript类型。 Node 18+、Deno、Bun、Cloudflare Workers和其他边缘运行时。
解码是贪婪的: 温度固定在0。任何其他温度
InvalidRequestError 在提出请求之前。
安装
npm install @idemcore/sdk
获取API密钥
- 登录到控制台 https://console.idemcore.net/#/login (公共 预览是免费的,有预览限制)。
- 创建API密钥。它开始于
ick_并且只显示一次。 - 出口:
export IDEMCORE_API_KEY="ick_..."
在Node上,客户端读取 IDEMCORE_API_KEY (可选 IDEMCORE_BASE_URL,
默认的 https://api.idemcore.net). 其他地方传递 new Idemcore({ apiKey }).
将密钥保存在服务器上:API不接受来自其他站点的浏览器调用(CORS)。
所以从你的后端或Worker调用它。
快速入门
import { Idemcore } from "@idemcore/sdk";
const client = new Idemcore();
const model = (await client.models())[0].id; // pass a model id explicitly
const r = await client.chat("Name the three primary colours.", { model, maxTokens: 64 });
console.log(r.text);
console.log(r.receiptId); // rcpt_...
// Verify on this machine: signature, token-log chain, and that the receipt
// commits to exactly this prompt and this answer.
const v = await client.verifyLocal(r);
console.log(v.ok); // true
console.log(v.levels); // { L1, L2, disclosure }
r.receipt 是否有完整的签名收据 r.salt 的base64url盐
hash_only 接收(默认隐私模式)。有盐和文字的人都可以
检查承诺,所以在谈话中储存盐。
流媒体
const stream = client.chatStream("Write a haiku about receipts.", { model });
for await (const chunk of stream) process.stdout.write(chunk.delta);
const result = await stream.finalResult(); // receipt arrives with the last chunk
console.log("\n" + result.receiptId);
收据、日志和服务器端检查
await client.getReceipt("rcpt_..."); // GET /v1/receipts/{id}
const log = await client.getReceiptLog("rcpt_..."); // GET /v1/receipts/{id}/log
await client.verifyRemote(r.receipt, { messages: r.messages, salt: r.salt, outputTokenIds: r.outputTokenIds });
await client.replayResult(r); // POST /v1/receipts/replay (L3)
await client.auditExport({ since: "2026-10-01", until: "2026-10-31" }); // NDJSON lines
await client.models(); // GET /v1/models
await client.keys(); // GET /v1/keys (JWKS)
脱机验证,无需客户端
import { verifyReceipt } from "@idemcore/sdk";
const res = await verifyReceipt(receipt, { logText, messages, salt, outputTokenIds });
生成收据签名公钥被绑定(DEFAULT_TRUSTED_KEYS); 通过
keys: await client.keys() 来使用活动键集。
错误
所有错误扩展 IdemcoreError 与 status, type 和 message:
AuthenticationError (401), PermissionDeniedError (403), NotFoundError (404),
ConflictError (409), InvalidRequestError (400/415), RateLimitError (429年,
.retryAfter), InsufficientQuotaError (429), ServiceUnavailableError (503),
InternalServerError xx (5), APIConnectionError (网络)。重试GET请求
429/503 (maxRetries,默认值2)。聊天永远不会自动重试,所以重试永远不会
在你背后开了第二张收据。
使用OpenAI SDK代替
API是openai兼容的: new OpenAI({ baseURL: "https://api.idemcore.net/v1", apiKey })
可以,回执在回复中 idemcore_receipt 字段。这个包增加了
打印收据和本地验证。
许可证
apache - 2.0