---
title: "TypeScript SDK"
description: "Official TypeScript/JavaScript SDK for all AINative Studio APIs"
canonical: "https://docs.ainative.studio/docs/sdks/typescript"
last-updated: "2026-10-03T21:47:10.764Z"
---

# TypeScript SDK

Source: https://docs.ainative.studio/docs/sdks/typescript

> Official TypeScript/JavaScript SDK for all AINative Studio APIs

# TypeScript SDK

The core TypeScript SDK wraps every AINative API — Chat, ZeroDB (vectors, memory, tables, files, events), Agent Cloud, and Agent Swarm.

```bash
npm install @ainative/sdk
```

## Quick Start

```typescript
import { AINativeClient, ZeroDBClient } from '@ainative/sdk';

// AINativeClient — chat, agent cloud, raw HTTP
const client = new AINativeClient({ apiKey: 'your-api-key' });

// ZeroDBClient — vectors, memory, files, events, projects
// Wraps AINativeClient; projectId is passed per-call, not in the constructor
const db = new ZeroDBClient(client);

// Chat completions
const response = await client.post('/api/v1/chat/completions', {
  model: 'meta-llama/llama-3.3-70b-instruct',
  messages: [{ role: 'user', content: 'What is ZeroDB?' }],
});
console.log(response.data.choices[0].message.content);

// Vector upsert — projectId is the first argument
await db.vectors.upsert('my-project', {
  vectorEmbedding: [0.1, 0.2, /* ... */],
  document: 'ZeroDB is a vector database',
  metadata: { source: 'docs' },
});

// Vector search
const results = await db.vectors.search('my-project', {
  queryVector: [0.1, 0.2, /* ... */],
  topK: 5,
});
console.log(results.data); // all ZeroDBClient methods return ApiResponse<T>

// Memory
await db.memory.store('my-project', {
  content: 'User prefers dark mode',
  agentId: 'agent-1',
  sessionId: 'session-123',
  role: 'user',
});
```

## Response Envelope

All `ZeroDBClient` methods return `ApiResponse<T>`:

```typescript
interface ApiResponse<T> {
  data: T;          // the actual payload — always access .data first
  status: number;   // HTTP status code
  headers: Headers;
  meta: {
    requestId: string;
    timestamp: string;
  };
}

// Example
const result = await db.vectors.search('my-project', { queryVector: [...], topK: 5 });
console.log(result.data.vectors);   // ✅ correct
console.log(result.vectors);        // ❌ undefined — missing .data
```

## Modules

### `AINativeClient` options

```typescript
const client = new AINativeClient({
  apiKey: 'your-api-key',
  organizationId: 'org-id',       // optional
  baseUrl: 'https://api.ainative.studio',  // default
  timeout: 30000,                  // ms, default 30s
  maxRetries: 3,                   // default 3
  debug: false,
});
// Note: projectId is NOT a constructor option — pass it per ZeroDBClient call
```

### `ZeroDBClient` methods

| Namespace | Methods | Description |
|-----------|---------|-------------|
| `db.projects` | `create()`, `get()`, `list()`, `update()`, `delete()` | Project management |
| `db.vectors` | `upsert(projectId, data)`, `search(projectId, data)`, `batchUpsert(projectId, data)`, `list(projectId)` | Vector operations |
| `db.memory` | `store(projectId, data)`, `search(projectId, data)`, `list(projectId)` | Memory storage |
| `db.events` | `publish(projectId, data)`, `list(projectId)`, `stream(projectId)` | Event streaming |
| `db.files` | `upload(projectId, data)`, `list(projectId)` | File metadata |
| `db.analytics` | `usage(projectId)`, `costs(projectId)`, `overview(projectId)` | Usage analytics |
| `db.database` | `status(projectId)`, `enable(projectId)`, `updateConfig(projectId, config)` | DB management |

For NoSQL table operations (insert/query/update rows), use the REST API directly — see [NoSQL Tables](/docs/zerodb/tables).

## Streaming

```typescript
const stream = await client.post('/api/v1/chat/completions', {
  model: 'meta-llama/llama-3.3-70b-instruct',
  messages: [{ role: 'user', content: 'Write a poem' }],
  stream: true,
});
```

## Error Handling

```typescript
import { AINativeClient } from '@ainative/sdk';

try {
  await client.post('/api/v1/chat/completions', { /* ... */ });
} catch (error: any) {
  console.log(`API error: ${error.status} ${error.message}`);
}
```

## Next Steps

- [Agent SDK](/docs/sdks/agent-sdk) — Specialized SDK for Agent Cloud APIs
- [Agent Runtime](/docs/sdks/agent-runtime) — Embeddable agent execution engine
- [React SDK](/docs/sdks/react) — React hooks and components
- [NoSQL Tables](/docs/zerodb/tables) — Insert and query structured data
