Skip to main content

TypeScript SDK

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

npm install @ainative/sdk

Quick Start

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>:

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

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

NamespaceMethodsDescription
db.projectscreate(), get(), list(), update(), delete()Project management
db.vectorsupsert(projectId, data), search(projectId, data), batchUpsert(projectId, data), list(projectId)Vector operations
db.memorystore(projectId, data), search(projectId, data), list(projectId)Memory storage
db.eventspublish(projectId, data), list(projectId), stream(projectId)Event streaming
db.filesupload(projectId, data), list(projectId)File metadata
db.analyticsusage(projectId), costs(projectId), overview(projectId)Usage analytics
db.databasestatus(projectId), enable(projectId), updateConfig(projectId, config)DB management

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

Streaming

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

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