> 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 full documentation content, see https://developers.alephant.io/llms-full.txt.

# Typescript SDK

> Installation, configuration, and usage of the Alephant TypeScript SDK

The official Alephant TypeScript SDK provides access to the Alephant SaaS API from TypeScript and Node.js applications. It is generated from our OpenAPI specification using Fern.

## Installation

Install the SDK via npm, yarn, or pnpm:

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

## Initialization

Import and initialize the client with your SaaS API base URL and an authentication token. Pass the full value expected by the `Authorization` header, for example `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}`,
});
```

## Example Usage

### Smoke test

Use the health endpoint to verify that the SDK can reach your configured SaaS API host.

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

### Listing Workspaces

Retrieve a list of all workspaces your account has access to.

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

### Creating an Agent and Virtual Key

You can programmatically provision new AI Agents and their associated Virtual Keys using the SDK.

```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
}
```

## Error Handling

The SDK throws structured errors for non-2xx API responses, allowing you to catch and handle specific failure scenarios (like rate limits or validation errors) programmatically.

## Repository

For advanced configurations, types, and source code, refer to the generated SDK package.