tako-sdk
v0.1.5
Published
JavaScript/TypeScript SDK for the Tako API
Downloads
90
Readme
Tako SDK
A lightweight TypeScript SDK for the Tako API.
Installation
npm install tako-sdk
# or
yarn add tako-sdk
# or
pnpm add tako-sdkQuick Start
import { createTakoClient } from 'tako-sdk';
// Initialize the client
const tako = createTakoClient(process.env.TAKO_API_KEY!);
// Search Tako Knowledge
const results = await tako.knowledgeSearch('AMD vs. Nvidia headcount since 2015');
console.log(results.outputs.knowledge_cards);Usage Example: Next.js API Route (App Router)
// app/api/tako-search/route.ts
import { createTakoClient } from 'tako-sdk';
import { NextResponse } from 'next/server';
export async function POST(request: Request) {
const { query, sourceIndexes } = await request.json();
const tako = createTakoClient(process.env.TAKO_API_KEY!);
try {
const results = await tako.knowledgeSearch(query, sourceIndexes);
return NextResponse.json(results);
} catch (error: any) {
return NextResponse.json(
{ error: error.message || 'An error occurred' },
{ status: error.status || 500 }
);
}
}API Reference
createTakoClient(apiKey)
Creates a new Tako API client.
const tako = createTakoClient('your-api-key');Parameters:
apiKey(string): Your Tako API key
takoClient.knowledgeSearch(text, sourceIndexes?)
Search Tako Knowledge using natural language.
const results = await tako.knowledgeSearch('AMD vs. Nvidia headcount since 2015');Parameters:
text(string): The natural language query textsourceIndexes(SourceIndex[], optional): Array of source indexes to search within. Available values:SourceIndex.TAKOorSourceIndex.WEB
Returns: Promise<KnowledgeSearchResponse>
The response contains an array of knowledge cards in the outputs.knowledge_cards field. Each knowledge card contains:
card_id: Unique identifier for the cardtitle: Card titledescription: Detailed description of the card's contentwebpage_url: URL of a webpage hosting the interactive knowledge cardimage_url: URL of a static image of the knowledge cardembed_url: URL of an embeddable iframe of the knowledge cardsources: The sources of the knowledge cardmethodologies: The methodologies of the knowledge card
For detailed API response types and subfield structure, see the Tako API Documentation.
Error Handling
The SDK throws typed exceptions for different errors:
import {
TakoException,
TakoUnauthorizedException,
TakoRateLimitException,
} from 'tako-sdk';
try {
const results = await tako.knowledgeSearch(query);
} catch (error) {
if (error instanceof TakoUnauthorizedException) {
console.error('Authentication error:', error.message);
} else if (error instanceof TakoRateLimitException) {
console.error('Rate limit exceeded:', error.message);
} else if (error instanceof TakoNotFoundException) {
console.error('Resource not found:', error.message);
} else if (error instanceof TakoException) {
console.error('API error:', error.message);
} else {
console.error('Unexpected error:', error);
}
}Each exception includes:
status: HTTP status codemessage: Error messagedetails: Additional error details from the API (if available)
