> ## Documentation Index
> Fetch the complete documentation index at: https://docs.krun.ai/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Krun API base URL: https://api.krun.ai. Authenticate server-side with `Authorization: Bearer $KRUN_API_KEY`; never put a Krun API key in browser code.
> Prefer the Python SDK in examples: `pip install krun-ai`, `from krun import Krun`. The TypeScript SDK `@krun-ai/sdk` is not published on npm yet: do not tell users to `npm install` it.
> The only question type is `choice`. `confidence` is the top-1 minus top-2 probability margin, not the probability that the answer is correct. `choice` is null when `abstain` is true.
> Usage reports `input_tokens` only. There are no output tokens.

# TypeScript SDK

> The official TypeScript SDK for Krun, @krun-ai/sdk, is coming soon. It is not published on npm yet.

<Warning>
  **Coming soon.** The TypeScript SDK, `@krun-ai/sdk`, is not published on npm yet. Until it is, call the [HTTP API](/api-reference/overview) directly from your Node.js server, or use the [Python SDK](/sdks/python).
</Warning>

* Source: [github.com/krun-ai/krun-typescript](https://github.com/krun-ai/krun-typescript)
* npm package: coming soon

We will update this page with install instructions when the package is published.

## Preview

The SDK is implemented. This preview shows the planned interface so you can see what integration will look like. Details can still change before the first release.

```ts Preview theme={null}
import { Krun } from "@krun-ai/sdk";

const client = new Krun(); // reads KRUN_API_KEY

const result = await client.decide({
  context: "Customer wants to return an item.",
  questions: {
    department: {
      type: "choice",
      options: {
        shipping: "Shipping and delivery issues",
        returns: "Returns and refunds",
        billing: "Billing and payment issues",
      },
    },
  },
});

const answer = result.answers.department;
answer.choice;        // "returns", or null if the model abstains
answer.confidence;    // top-1 minus top-2 probability
answer.probabilities; // { shipping: ..., returns: ..., billing: ... }
result.requestId;     // "req_...", for feedback()
```

Planned features:

* ESM, Node.js 20 or later, no runtime dependencies (uses the built-in `fetch`).
* Types inferred from your request: `result.answers.department` autocompletes, and `answer.choice` is typed as `"shipping" | "returns" | "billing" | null`.
* camelCase fields (`requestId`, `abstentionStatus`, `inputTokens`, `taskType`). Your question ids and option ids are never renamed.
* `decide()`, `feedback()` and `models()`, with the same 70-second default timeout and retry policy as the [Python SDK](/sdks/python#retries).

<Note>
  Like the Python SDK, the TypeScript SDK is for server-side code. Never use a Krun API key in browser code. See [Authentication](/api-reference/authentication).
</Note>

## Use the HTTP API from Node.js today

```ts theme={null}
const response = await fetch("https://api.krun.ai/v1/decide", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.KRUN_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    context: "Customer wants to return an item.",
    questions: {
      department: {
        type: "choice",
        options: {
          shipping: "Shipping and delivery issues",
          returns: "Returns and refunds",
          billing: "Billing and payment issues",
        },
      },
    },
  }),
  signal: AbortSignal.timeout(70_000),
});

const requestId = response.headers.get("x-request-id");
const body = await response.json();

if (!response.ok) {
  throw new Error(`${body.error.code}: ${body.error.message} (${body.error.request_id})`);
}

console.log(body.answers.department.choice, requestId);
```

See the [API reference](/api-reference/decide) for the full request and response schema.
