@idemcore/sdk

中文文档
0.1.2发布于 2026/11/01Apache-2.0TypeScriptES Module零依赖构建来源已验证

Idemcore API client with signed receipts and local receipt verification. Zero dependencies; Node 18+, browsers, Workers.

原始使用文档
文档目录9 节
  1. Install
  2. Get an API key
  3. Quickstart
  4. Streaming
  5. Receipts, logs and server-side checks
  6. Offline verification without the client
  7. Errors
  8. Using the OpenAI SDK instead
  9. License

@idemcore/sdk

JavaScript / TypeScript client for the Idemcore API. Every chat answer comes with a signed receipt, and this package can check that receipt locally.

  • Chat completions (plain or streaming) that return the answer text and its receipt id.
  • Fetch a receipt and its public token log.
  • Verify receipts locally: Ed25519 signature (L1), token-log chain (L2), and your prompt / answer against the receipt's salted commitments (disclosure).
  • Server-side checks: remote verify, replay on an independent build (L3), audit export.
  • Zero dependencies, fetch + WebCrypto only. ESM with TypeScript types. Node 18+, Deno, Bun, Cloudflare Workers and other edge runtimes.

Decoding is greedy: temperature is fixed at 0. Any other temperature throws InvalidRequestError before a request is made.

Install

npm install @idemcore/sdk

Get an API key

  1. Sign in to the console at https://console.idemcore.net/#/login (the public preview is free, with preview limits).
  2. Create an API key. It starts with ick_ and is shown only once.
  3. Export it:
export IDEMCORE_API_KEY="ick_..."

On Node the client reads IDEMCORE_API_KEY (and optionally IDEMCORE_BASE_URL, default https://api.idemcore.net). Elsewhere pass new Idemcore({ apiKey }). Keep keys on the server: the API does not accept browser calls from other sites (CORS), so call it from your backend or a Worker.

Quickstart

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 is the full signed receipt and r.salt the base64url salt of a hash_only receipt (the default privacy mode). Anyone with the salt and the text can check the commitments, so store the salt with the conversation.

Streaming

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);

Receipts, logs and server-side checks

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)

Offline verification without the client

import { verifyReceipt } from "@idemcore/sdk";

const res = await verifyReceipt(receipt, { logText, messages, salt, outputTokenIds });

The production receipt-signing public key is bundled (DEFAULT_TRUSTED_KEYS); pass keys: await client.keys() to use the live key set instead.

Errors

All errors extend IdemcoreError with status, type and message: AuthenticationError (401), PermissionDeniedError (403), NotFoundError (404), ConflictError (409), InvalidRequestError (400/415), RateLimitError (429, .retryAfter), InsufficientQuotaError (429), ServiceUnavailableError (503), InternalServerError (5xx), APIConnectionError (network). GET requests are retried on 429/503 (maxRetries, default 2). Chat is never retried automatically, so a retry never creates a second receipt behind your back.

Using the OpenAI SDK instead

The API is OpenAI-compatible: new OpenAI({ baseURL: "https://api.idemcore.net/v1", apiKey }) works, with the receipt in the response's idemcore_receipt field. This package adds typed receipts and local verification.

License

Apache-2.0

版本与发布记录

@idemcore/sdk 共发布 4 个版本,首次发布于 2026/11/01;过去 12 个月发布了 4 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.1.2latest2026/11/012 天前
0.1.12026/11/012 天前
0.1.02026/11/012 天前
0.0.0-stage2026/11/012 天前

关于 @idemcore/sdk 的常见问题

@idemcore/sdk 是什么?

Idemcore API客户端与签名收据和本地收据验证。零依赖关系;Node 18+、浏览器、worker。

如何安装 @idemcore/sdk?

在项目目录运行 npm install @idemcore/sdk,或使用 pnpm add / yarn add / bun add。

@idemcore/sdk 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@idemcore/sdk 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@idemcore/sdk 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=18。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@idemcore/sdk 可以商用吗?

@idemcore/sdk 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@idemcore/sdk 还在维护吗?

最新版本 0.1.2 发布于 2026/11/01(2 天前);至今共发布 4 个版本,其中过去 12 个月发布了 4 个;首次发布于 2026/11/01。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。