文档导航

JavaScript SDK

JavaScript SDK

TypeSafe AI 的 JavaScript 与 TypeScript SDK。

快速开始

安装 SDK(需要 Node.js 20 或更新版本):

npm install @typesafe-ai/sdk

在环境里设置 TYPESAFE_API_KEY,然后创建并使用客户端:

import { choice, TypeSafeClient } from "@typesafe-ai/sdk";

const client = new TypeSafeClient();
const response = await client.systemOne({
  state: { document: "I was charged twice. Please fix this ASAP." },
  questions: {
    category: choice("What is this ticket about?", {
      billing: null,
      technical: null,
      other: null,
    }),
  },
});

console.log(response.answers.category.choice);

答案类型会从你的问题推断出来。该包包含 ESM、CommonJS 和 TypeScript 声明。

文档

在 TypeSafe 文档里了解 TypeSafe 能做什么。 关于 API 选项和默认值,见 SDK 的客户端和类型。