Kroos Developers
Kroos Developers › Platforms & tools

Client libraries & SDKs

Official Kroos packages for Node.js, web apps, Python, iOS and Android, plus plain-HTTPS clients for any language.

Kroos's APIs are plain HTTPS and JSON, so any HTTP client works. Official packages:

PackageForInstall
@kroos-dev/nodeNode.js servers and Next.js route handlers: end-user tokens, context providers, webhooks, the organization APInpm install @kroos-dev/node
@kroos-dev/webWebsites and web apps: load the chatbot, switch the signed-in user, React <KroosChat />npm install @kroos-dev/web
kroosPython servers: the same as @kroos-dev/nodepip install kroos
KroosKitiOS and macOS apps (SwiftUI): native chat client and KroosChatViewSwift Package Manager: https://github.com/kroosAI/kroos-ios
Kroos for AndroidAndroid apps (Jetpack Compose): native chat client and KroosChatScreenGradle: implementation("ai.kroos:kroos-android:0.1.0") (Maven Central)

Mobile apps use your publishable key plus a registered app id (app:ios:<bundle id> or app:android:<package>) in your allowed origins. Signed-in users get an end-user token from your backend; never sign tokens or store secret keys in an app.

Next.js in two files#

jsapp/api/kroos/token/route.js
import { kroosTokenRoute } from "@kroos-dev/node/next";
import { pseudonymousId } from "@kroos-dev/node";

export const GET = kroosTokenRoute({
  getUser: async () => {
    const user = await currentUser(); // your session
    return user ? { sub: pseudonymousId(user.id, "my-site"), segment: "member" } : null;
  },
});
jsxapp/layout.jsx
import { KroosChat } from "@kroos-dev/web/react";
// inside <body>:
<KroosChat publishableKey={process.env.NEXT_PUBLIC_KROOS_PUBLISHABLE_KEY} tokenUrl="/api/kroos/token" />

Swift (iOS)#

swift
import KroosKit
let chat = KroosChat(publishableKey: "kroos_pk_...") { try? await MyAPI.shared.kroosToken() }
// SwiftUI: KroosChatView(chat: chat)

Kotlin (Android)#

kotlin
val chat = KroosChat(publishableKey = "kroos_pk_...", appId = "android:${BuildConfig.APPLICATION_ID}") { myApi.kroosToken() }
// Compose: KroosChatScreen(chat)

Without a package#

These small clients cover the common calls in any project. Ready-made integrations: the website chatbot, CMS plugins, IDE extensions and MCP servers.

Node.js (18+)#

jskroos.js
export class Kroos {
  constructor({ secretKey, adminKey, publishableKey, web = "https://kroos.ai", api = "https://api.kroos.ai" } = {}) {
    Object.assign(this, { secretKey, adminKey, publishableKey, web, api });
  }
  async #call(base, path, { key, body, method } = {}) {
    const res = await fetch(base + path, {
      method: method ?? (body ? "POST" : "GET"),
      headers: { ...(body ? { "content-type": "application/json" } : {}), ...(key ? { authorization: `Bearer ${key}` } : {}) },
      body: body ? JSON.stringify(body) : undefined,
    });
    const j = await res.json().catch(() => ({}));
    if (!res.ok) throw Object.assign(new Error(j.error?.message ?? `HTTP ${res.status}`), { code: j.error?.code, fix: j.error?.fix, status: res.status });
    return j;
  }
  organization() { return this.#call(this.web, "/api/tenant", { key: this.secretKey }); }
  knowledge() { return this.#call(this.web, "/api/tenant/knowledge", { key: this.secretKey }); }
  saveKnowledge(model) { return this.#call(this.web, "/api/tenant/knowledge", { key: this.secretKey, body: model, method: "PUT" }); }
  usage(groupBy = "workspace,meter") { return this.#call(this.web, `/v1/organizations/usage?group_by=${groupBy}`, { key: this.adminKey }); }
  addWebhook(url, events) { return this.#call(this.web, "/api/tenant/webhooks", { key: this.secretKey, body: { url, events } }); }
  // Website chatbot API: call from a server only if your server's origin is allowed, otherwise from the browser.
  chat(message, { conversationId, userToken } = {}) { return this.#call(this.api, "/api/public/v1/chat", { body: { pk: this.publishableKey, message, conversationId, userToken } }); }
}

Python (3.9+)#

pythonkroos.py
import json, urllib.request

class KroosError(Exception):
    def __init__(self, status, code, message, fix=None):
        super().__init__(message); self.status, self.code, self.fix = status, code, fix

class Kroos:
    def __init__(self, secret_key=None, admin_key=None, web="https://kroos.ai", api="https://api.kroos.ai"):
        self.secret_key, self.admin_key, self.web, self.api = secret_key, admin_key, web, api

    def _call(self, base, path, key=None, body=None, method=None):
        req = urllib.request.Request(base + path, method=method or ("POST" if body is not None else "GET"))
        if key: req.add_header("authorization", f"Bearer {key}")
        data = None
        if body is not None:
            req.add_header("content-type", "application/json"); data = json.dumps(body).encode()
        try:
            with urllib.request.urlopen(req, data) as r: return json.loads(r.read() or b"null")
        except urllib.error.HTTPError as e:
            err = json.loads(e.read() or b"{}").get("error", {})
            raise KroosError(e.code, err.get("code"), err.get("message", str(e)), err.get("fix"))

    def organization(self): return self._call(self.web, "/api/tenant", self.secret_key)
    def usage(self, group_by="workspace,meter"): return self._call(self.web, f"/v1/organizations/usage?group_by={group_by}", self.admin_key)
    def set_spend_limit(self, usd): return self._call(self.web, "/v1/organizations/spend_limit", self.admin_key, {"usd": usd}, "PUT")

Good practice#

  • Branch on error.code; show error.fix.label and link to error.fix.url for setup problems.
  • Retry 429 and 5xx with backoff; never retry 4xx validation errors unchanged.
  • Log kroos-request-id from responses.

Last updated 2026-12-03