Skip to main content

Install

ESM only, Node.js 20 or later, no runtime dependencies (it uses the built-in fetch).
Multimodal inputs, multi questions and assets require @krun-ai/sdk 0.3.0 or later, which also sets the default timeout to 180 seconds. With an earlier version, use decide(), feedback() and models() for text, and call the HTTP API for assets.

Quickstart

When questions is written inline, TypeScript infers the ids: result.answers.department autocompletes, and answer.choice is typed as "shipping" | "returns" | "billing" | null. Fields are camelCase (requestId, abstentionStatus, inputTokens, taskType). Your question ids and option ids are never renamed.

Decision primitives

noul and score questions work the same way, with answers typed by their question:

Multimodal inputs and multi

Requires @krun-ai/sdk 0.3.0 or later. Upload media with client.assets.create() and reference it by assetId in a list of content parts:
See Multimodal inputs for supported types, limits and known limitations.

Feedback and models

Timeouts and retries

After a period without traffic, the first request can take up to about 2 minutes while the model loads. Keep the timeout at 180 seconds or more; with a version before 0.3.0, set timeout: 180_000 yourself. The retry policy is the same as the Python SDK: decide() and models() retry once after connection errors and 502, 503 or 504; feedback(), assets.create() and assets.delete() are never retried. See Timeouts and cold starts.
Like the Python SDK, the TypeScript SDK is for server-side code. Never use a Krun API key in browser code. See Authentication.

Use the HTTP API directly

Without the SDK, call the API with fetch:
See the API reference for the full request and response schema.