This SDK helps you use the AI Search API in your Node.js or TypeScript projects.
It gives you semantic search with context, flexible response formats, and strong TypeScript support.
👉 To start, create a free account:

Features

  • 🔍 Semantic AI Search – Ask natural language questions
  • 💬 Context Awareness – Add chat-like history
  • 📝 Flexible Responses – Choose Markdown or plain text
  • TypeScript First – IntelliSense & type safety
  • 📊 Usage Tracking – Check your credits anytime

Installation

You can install the SDK with npm or yarn:
npm install aisearchapi-client
# or
yarn add aisearchapi-client
Or install from source:
git clone https://github.com/aisearchapi/aisearchapi-js.git
cd aisearchapi-js
npm install

Quick Start

Import and create a client with your API key:
import { AISearchAPIClient } from 'aisearchapi-client';

const client = new AISearchAPIClient({
  apiKey: 'your-api-key-here' // get it from the Dashboard
});

const result = await client.search({
  prompt: 'What is machine learning and how does it work?',
  response_type: 'markdown'
});

console.log(result.answer);
console.log('Sources:', result.sources);

API Reference

Client Configuration

const client = new AISearchAPIClient({
  apiKey: 'your-api-key',
  baseUrl: 'https://api.aisearchapi.io',
  timeout: 30000 // ms
});
const result = await client.search({
  prompt: 'Your query',
  context: [{ role: 'user', content: 'Previous message' }],
  response_type: 'markdown'
});

Balance

const balance = await client.balance();
console.log('Credits left:', balance.available_credits);

Usage Examples

const result = await client.search({ prompt: 'Explain quantum computing simply' });
console.log(result.answer);
const result = await client.search({
  prompt: 'What are the benefits?',
  context: [
    { role: 'user', content: 'I am researching renewable energy' },
    { role: 'user', content: 'Specifically solar and wind' }
  ]
});

Check Balance

const balance = await client.balance();
if (balance.available_credits < 10) {
  console.warn('Low balance!');
}

Error Handling

import { AISearchAPIError } from 'aisearchapi-client';

try {
  const result = await client.search({ prompt: 'Hello' });
} catch (error) {
  if (error instanceof AISearchAPIError) {
    console.error(`API Error [${error.statusCode}]:`, error.message);
  }
}

TypeScript Support

This client is written in TypeScript. You can use strong typing:
import type { SearchRequest, SearchResponse } from 'aisearchapi-client';

const params: SearchRequest = {
  prompt: 'What is TypeScript?',
  response_type: 'markdown'
};

const response: SearchResponse = await client.search(params);

Response Formats

You can choose how answers are returned:
  • Markdown (default): rich formatting, lists, code blocks
  • Text: simple string
await client.search({ prompt: 'Explain REST APIs', response_type: 'markdown' });
await client.search({ prompt: 'Explain Node.js', response_type: 'text' });

Error Codes

CodeMeaningFix
401UnauthorizedInvalid API key → get a new one
429Too Many RequestsRate limit hit
433Quota ExceededCredits finished
500Server ErrorTry again later
503Service DownMaintenance

Environment Variables

You can store your API key in .env:
AI_SEARCH_API_KEY=your-key-here
Then use it in your code:
const client = new AISearchAPIClient({
  apiKey: process.env.AI_SEARCH_API_KEY!
});

Browser Support

This SDK is made for Node.js.
For browser use:
  • Configure CORS
  • Keep your API keys secure

Resources