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 text
  • sourceIndexes (SourceIndex[], optional): Array of source indexes to search within. Available values: SourceIndex.TAKO or SourceIndex.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 card
  • title: Card title
  • description: Detailed description of the card’s content
  • webpage_url: URL of a webpage hosting the interactive knowledge card
  • image_url: URL of a static image of the knowledge card
  • embed_url: URL of an embeddable iframe of the knowledge card
  • sources: The sources of the knowledge card
  • methodologies: 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 code
  • message: Error message
  • details: Additional error details from the API (if available)