A lightweight TypeScript client for Bing Search API, designed for AI applications.
- Type-safe: Full TypeScript support with comprehensive type definitions
- Configurable: Customizable search parameters and API settings
- Minimal: Zero external runtime dependencies
- Developer-friendly: Clean API with Promise-based interface
npm install @agent-infra/bing-search
# or
yarn add @agent-infra/bing-search
# or
pnpm add @agent-infra/bing-search
import { BingSearchClient } from '@agent-infra/bing-search';
const client = new BingSearchClient({
apiKey: 'YOUR_API_KEY',
});
const results = await client.search({
q: 'climate change',
count: 5,
});
console.log(results.webPages?.value);
// Set in your environment:
// BING_SEARCH_API_KEY=your-api-key
import { BingSearchClient } from '@agent-infra/bing-search';
const client = new BingSearchClient();
const results = await client.search({ q: 'renewable energy' });
import { ConsoleLogger } from '@agent-infra/logger';
import { BingSearchClient } from '@agent-infra/bing-search';
const logger = new ConsoleLogger('[BingSearch]');
const client = new BingSearchClient({
apiKey: 'YOUR_API_KEY',
logger,
});
const results = await client.search({ q: 'machine learning' });
constructor(config?: Partial<BingSearchConfig>)
Configuration options:
interface BingSearchConfig {
baseUrl?: string; // Default: 'https://api.bing.microsoft.com/v7.0'
apiKey?: string; // Bing API subscription key
headers?: Record<string, string>;
logger?: Logger;
}
async search(params: BingSearchOptions): Promise<BingSearchResponse>
Search options:
interface BingSearchOptions {
q: string; // Search query (required)
count?: number; // Number of results to return
offset?: number; // Result offset for pagination
mkt?: string; // Market code (e.g., 'en-US')
safeSearch?: 'Off' | 'Moderate' | 'Strict';
[key: string]: any; // Additional parameters
}
interface BingSearchResponse {
webPages?: {
value: WebPage[];
totalEstimatedMatches?: number;
webSearchUrl?: string;
};
images?: {
value: Image[];
// ...
};
videos?: {
value: Video[];
// ...
};
// Additional response fields
}
See examples.
Copyright (c) 2025 ByteDance, Inc. and its affiliates.
Licensed under the Apache License, Version 2.0.