VantigeClient
The main client class for interacting with the Vantige AI API.
Constructor
new VantigeClient(config: VantigeClientConfig)
Parameters
config
- Configuration object for the clientapiKey
(string, required) - Your Vantige API keybaseUrl
(string, optional) - Custom API endpoint (defaults to production URL)
Example
import { VantigeClient } from '@vantige-ai/typescript-sdk';
const client = new VantigeClient({
apiKey: process.env.VANTIGE_API_KEY
});
Methods
listKnowledgeBases()
Lists all knowledge bases available to your organization.
listKnowledgeBases(): Promise<KnowledgeBase[]>
Returns
Promise<KnowledgeBase[]>
- Array of knowledge base objects
Example
const knowledgeBases = await client.listKnowledgeBases();
knowledgeBases.forEach(kb => {
console.log(`${kb.name} (${kb.corpusId}): ${kb.description}`);
});
Response Type
interface KnowledgeBase {
corpusId: string;
name: string;
description: string;
createdAt: string;
updatedAt: string;
}
query()
Queries a specific knowledge base with semantic search and optional AI generation.
query(params: QueryParams): Promise<QueryResponse>
Parameters
params
- Query parameters objectcorpusId
(string, required) - The ID of the knowledge base to queryquery
(string, required) - The search querylimit
(number, optional) - Maximum number of results (1-100, default: 10)generateAnswer
(boolean, optional) - Whether to generate an AI answer (default: false)
Returns
Promise<QueryResponse>
- Query response with results and optional AI answer
Example
// Basic search
const searchResults = await client.query({
corpusId: 'docs',
query: 'How do I authenticate?',
limit: 5
});
// With AI-generated answer
const response = await client.query({
corpusId: 'docs',
query: 'What is the refund policy?',
generateAnswer: true
});
console.log('Answer:', response.answer);
console.log('Sources:', response.results.map(r => r.title));
Response Type
interface QueryResponse {
results: SearchResult[];
answer?: string;
queryId: string;
corpusId: string;
}
interface SearchResult {
id: string;
title: string;
content: string;
url?: string;
score: number;
metadata: Record<string, any>;
}
Error Handling
All methods can throw VantigeSDKError
with specific error codes:
try {
const response = await client.query({
corpusId: 'docs',
query: 'test'
});
} catch (error) {
if (error instanceof VantigeSDKError) {
switch (error.code) {
case 401:
console.error('Invalid API key');
break;
case 404:
console.error('Knowledge base not found');
break;
case 429:
console.error('Rate limited');
break;
}
}
}
Type Definitions
VantigeClientConfig
interface VantigeClientConfig {
apiKey: string;
baseUrl?: string;
}
QueryParams
interface QueryParams {
corpusId: string;
query: string;
limit?: number;
generateAnswer?: boolean;
}