The official TypeScript SDK for interacting with the AgentSearch API. This SDK provides a simple and intuitive interface for making requests to various AgentSearch endpoints.
Install the SDK using npm:
npm install agent-search
Or using yarn:
yarn add agent-search
First, import and initialize the AgentSearch client:
import { AgentSearch } from "agentsearch-sdk";
const agentSearch = new AgentSearch("your_api_key");
Now you can use the various API methods:
// Get an answer
const answerResponse = await agentSearch.answer.get({
query: "What is the capital of France?",
});
// Perform an advanced search
const advancedSearchResponse = await agentSearch.answer.searchAdvanced({
query: "Latest developments in AI",
additionalInstructions: "Focus on the last 6 months",
});
const browseResult = await agentSearch.browse.explore({
url: "https://example.com",
singlePage: true,
});
const crawlResult = await agentSearch.crawl.start({
url: "https://example.com",
crawlOptions: {
maxDepth: 3,
limit: 100,
},
});
// Perform a Serper search
const searchResults = await agentSearch.search.serperSearch({
q: "best restaurants in New York",
num: 10,
});
// Perform a LinkedIn search
const linkedInResults = await agentSearch.search.linkedInSearch({
query: "software engineers",
page: 1,
resultsPerPage: 20,
});
// Rerank search results
const rerankedResults = await agentSearch.search.rerank({
query: "machine learning applications",
});
// Generate search queries
const generatedQueries = await agentSearch.search.generateQueries({
query: "Electric vehicles market trends",
});
const scrapedContent = await agentSearch.scrape.extract({
url: "https://example.com",
scrapeOptions: {
formats: ["markdown", "html"],
onlyMainContent: true,
},
});
The SDK uses custom AgentSearchError
for error handling. You can catch and handle these errors in your code:
try {
const result = await agentSearch.answer.getAnswer({ query: "Some query" });
// Handle successful response
} catch (error) {
if (error instanceof AgentSearchError) {
console.error(`API Error: ${error.message}, Status: ${error.status}`);
} else {
console.error("Unexpected error:", error);
}
}
For detailed information about each API endpoint and its parameters, please refer to the API documentation.
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.