aisearchapi-client
v1.0.11
Published
TypeScript client library for AI Search API - search and retrieve intelligent responses with context awareness
Maintainers
Readme
⚡ AI Search API - TypeScript Client
A comprehensive TypeScript client for the AI Search API that provides intelligent semantic search with context awareness and flexible response formats.
👉 Start by creating your free account:
- 🆕 Sign Up
- 🔑 Log In
- 📊 Dashboard (get and manage API keys)
✨ Features
- 🔍 Semantic AI Search – Natural language queries powered by embeddings
- 💬 Context Awareness – Add chat-like conversation context
- 📝 Flexible Responses – Markdown or plain text
- ⚡ TypeScript First – Strong typing, IntelliSense, better DX
- 📊 Usage Tracking – Check API balance anytime
📦 Installation
npm install aisearchapi-client
# or with yarn
yarn add aisearchapi-clientOr install from source:
git clone https://github.com/aisearchapi/aisearchapi-js.git
cd aisearchapi-js
npm install🚀 Quick Start
import { AISearchAPIClient } from 'aisearchapi-client';
const client = new AISearchAPIClient({
apiKey: 'your-api-key-here' // get it from https://app.aisearchapi.io/dashboard?utm_source=github
});
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 // in ms
});Search
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
Basic Search
const result = await client.search({ prompt: 'Explain quantum computing simply' });
console.log(result.answer);Contextual Search
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 built in TypeScript:
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
- Markdown (default): rich text formatting, lists, code blocks
- Plain text: simple string without formatting
await client.search({ prompt: 'Explain REST APIs', response_type: 'markdown' });
await client.search({ prompt: 'Explain Node.js', response_type: 'text' });⚠️ Error Codes
| Code | Meaning | Fix | |------|---------|-----| | 401 | Unauthorized | Invalid API key → Get key | | 429 | Too Many Requests | Rate limit hit | | 433 | Quota Exceeded | Credits finished | | 500 | Server Error | Try again later | | 503 | Service Down | Maintenance |
🔑 Environment Variables
# .env
AI_SEARCH_API_KEY=your-key-hereconst client = new AISearchAPIClient({
apiKey: process.env.AI_SEARCH_API_KEY!
});🌐 Browser Support
Primarily for Node.js. For browsers: configure CORS + secure your keys.
📚 Resources
📜 License
MIT License - see the LICENSE.
🔍 SEO Keywords
AI Search API TypeScript client, semantic search Node.js, contextual AI JavaScript, AI Search API npm package, AI Search API key setup, intelligent search SDK
