Skip to Content
unii.docs
Sdks

TypeScript SDK

A type-safe client for building with the Unii API

Installation

Install the Unii TypeScript SDK using your preferred package manager.

npm install @unii/sdk

Initialize the client

Create a UniiClient instance with your API key.

import { UniiClient } from "@unii/sdk";

const client = new UniiClient({
  apiKey: process.env.UNII_API_KEY,
});

Create a chat completion

Send a message to Unii and receive a grounded assistant response.

const response = await client.createChatCompletion({
  messages: [{ role: "user", content: "What is the return policy window?" }],
});

console.log(response.choices[0].message.content);

Streaming responses

Stream a response in real time using an async iterator.

const stream = await client.streamChatCompletion({
  messages: [{ role: "user", content: "Write a short poem about code." }],
});

for await (const chunk of stream) {
  process.stdout.write(chunk.choices[0]?.delta?.content ?? "");
}

Error handling

Handle API errors with typed error objects.

try {
  const response = await client.createChatCompletion({
    messages: [{ role: "user", content: "Hello" }],
  });
} catch (error) {
  if (error instanceof Error) {
    console.error("API error:", error.message);
  }
}

On this page