> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://developers.alephant.io/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://developers.alephant.io/_mcp/server.

# Typescript SDK

> Alephant TypeScript SDK 的安装、配置和使用

官方 Alephant TypeScript SDK 让 TypeScript 和 Node.js 应用程序能够访问 Alephant SaaS API。它基于我们的 OpenAPI 规范通过 Fern 生成。

## 安装

通过 npm、yarn 或 pnpm 安装 SDK：

```bash
npm install @alephantai/saas-api
```

## 初始化

使用 SaaS API 基础 URL 和身份验证令牌导入并初始化客户端。传入 `Authorization` 请求头所需的完整值，例如 `Bearer <token>`。

```typescript
import { AlephantSaaSClient } from "@alephantai/saas-api";

const client = new AlephantSaaSClient({
  baseUrl: process.env.ALEPHANT_SAAS_BASE_URL!,
  apiKey: `Bearer ${process.env.ALEPHANT_API_TOKEN}`,
});
```

## 使用示例

### 冒烟测试

使用 health 端点验证 SDK 能否连接到已配置的 SaaS API 主机。

```typescript
const health = await client.system.healthCheck();
console.log(health.data);
```

### 列出工作区

获取您的帐户有权访问的所有工作区列表。

```typescript
async function fetchWorkspaces() {
  try {
    const response = await client.workspaces.listUsersWorkspaces();
    console.log(response);
  } catch (error) {
    console.error("Failed to fetch workspaces:", error);
  }
}
```

### 创建 Agent 和 Virtual Key

您可以使用 SDK 以编程方式创建新的 AI Agents 及其关联的 Virtual Keys。

```typescript
async function createNewAgent() {
  const newAgent = await client.agents.createAgent({
    name: "Customer Support Bot",
    provider: "openai",
    model: "gpt-4-turbo",
    environment: "production"
  });

  console.log(`Created agent with ID: ${newAgent.id}`);
  // A Virtual Key is automatically generated for this agent
}
```

## 错误处理

SDK 会针对非 2xx API 响应抛出结构化错误，让您能够以编程方式捕获并处理特定失败情形（例如速率限制或验证错误）。

## 仓库

如需高级配置、类型和源代码，请参阅生成的 SDK 软件包。