Official TypeScript SDK for the Serpex SERP API. Fetch search results in JSON format with type safety.
npm install serpexyarn add serpexpnpm add serpexGet started with the Serpex TypeScript SDK in just a few lines of code.
import { SerpexClient } from 'serpex';
// Initialize the client with your API key
const client = new SerpexClient('your-api-key-here');
// Web search with Google
const webResults = await client.search({
q: 'typescript tutorial',
engine: 'google',
category: 'web',
time_range: 'week' // Only for web search
});
// News search - always returns latest news
const newsResults = await client.search({
q: 'artificial intelligence',
engine: 'google',
category: 'news' // Always returns latest news
});
console.log(webResults.results[0].title);
console.log(newsResults.results[0].published_date);new SerpexClient(apiKey: string, baseUrl?: string)apiKey - Your API key from the Serpex dashboardbaseUrl - Optional base URL (defaults to production API)const results = await client.search({
q: 'javascript frameworks',
engine: 'google',
category: 'web',
time_range: 'month'
});| Parameter | Type | Required | Description |
|---|---|---|---|
| q | string | Yes | Search query |
| engine | string | Yes | Search engine (auto, google, bing, duckduckgo, brave, yahoo, yandex) |
| category | string | No | Search category (web, news). News always returns latest articles. |
| time_range | string | No | Time range filter (day, week, month, year). Only for web search, ignored for news. |
interface SearchResponse {
metadata: {
number_of_results: number;
response_time: number;
timestamp: string;
credits_used: number;
};
id: string;
query: string;
engines: string[];
results: Array<{
title: string;
url: string;
snippet: string;
position: number;
engine: string;
published_date: string | null;
img_src?: string;
duration?: string;
score?: number;
}>;
answers: any[];
corrections: string[];
infoboxes: any[];
suggestions: string[];
}import { SerpexClient, SerpApiException } from 'serpex';
try {
const results = await client.search({
q: 'test query',
engine: 'google'
});
} catch (error) {
if (error instanceof SerpApiException) {
console.log('API Error:', error.message);
console.log('Status Code:', error.statusCode);
}
}