[ Docs ]

TypeScript SDK

Planned IdonAI TypeScript / Node client — install target, chat completions, and streaming notes.

Status

The @idonai/sdk package name is reserved. Public install lands when API keys ship. Until then, treat the snippets below as the intended client shape and validate prompts in Quark or against the REST contract.

Install (planned)

typescript
npm install @idonai/sdk

Works the same with pnpm / yarn once the package is on the registry. Target Node for server-side calls; do not put production keys in browser bundles.

Client init

typescript
import { IdonAI } from "@idonai/sdk";

const client = new IdonAI({
  apiKey: process.env.IDONAI_API_KEY,
});

Fail fast if IDONAI_API_KEY is missing in production. See Authentication.

Chat completion

typescript
const response = await client.models.generate({
  model: "origin",
  messages: [
    { role: "user", content: "Explain quantum entanglement." },
  ],
  maxTokens: 1024,
});

console.log(response.content);

Use model: "nextgen" when you need the higher-capability model. Ids match Quark and the API reference.

Streaming

Enable streaming for token-by-token UX (chat UIs, progressive logs). Consume the async iterator / event stream fully and surface cancelation to the user.

typescript
// Sketch — exact helper names may refine at publish time
const stream = await client.models.generate({
  model: "origin",
  messages: [{ role: "user", content: "Outline three steps." }],
  stream: true,
});

for await (const event of stream) {
  process.stdout.write(event.content ?? "");
}

Browser note

Do not call the API with a secret key from the browser. If you need a web demo, proxy through your backend. Restricted browser keys are not available until we publish that model — assume server-only for now.

Errors

Handle rejected promises for 401, 403, 429, and 5xx. On rate limits, honor Retry-After and jittered backoff — see Rate limits. Validate request shapes locally to avoid tight 400 loops.