WebSearchAPI.ai Quickstart Guide
Learn how to quickly get started with WebSearchAPI.ai and make your first API call.
WebSearchAPI.ai provides two powerful APIs designed specifically for AI applications: the Web Search API for intelligent search and the Web Scraper API for advanced content extraction. This guide will walk you through the process of setting up and making your first API calls.
Creating an API Key
Before you can use WebSearchAPI.ai, you'll need to create an API key:
- Sign up for a WebSearchAPI.ai account
- Navigate to the Developer section in your dashboard
- Click on "Create New API Key"
- Give your key a descriptive name (e.g., "Development Key")
- Set appropriate permissions and expiration if needed
- Copy your new API key for use in your applications
Remember: Your API key grants access to your account and quotas. Keep it secure and never share it publicly.
Making Your First API Call
Once you have your API key, you can start making requests to the WebSearchAPI.ai endpoints. Below are examples for both APIs using different methods:
Using the Web Search API
The Web Search API allows you to search the web and get AI-optimized results with optional content extraction.
Using cURL
# Direct API call to WebSearchAPI.ai
curl -X POST https://api.websearchapi.ai/ai-search \
-H "Content-Type: application/json" \
-H "Authorization: Bearer APIKEY" \
-d '{
"query": "Why the market crashed?",
"maxResults": 5,
"includeContent": false,
"country": "us",
"language": "en"
}'Using Python
import requests
API_KEY = "your_api_key_here"
url = "https://api.websearchapi.ai/ai-search"
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {API_KEY}"
}
data = {
"query": "Why the market crashed?",
"maxResults": 5,
"includeContent": False,
"country": "us",
"language": "en"
}
response = requests.post(url, headers=headers, json=data)
results = response.json()
print(results)Using JavaScript
async function searchWithWebSearchAPI() {
const API_KEY = 'your_api_key_here';
const url = 'https://api.websearchapi.ai/ai-search';
const response = await fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${API_KEY}`
},
body: JSON.stringify({
query: 'Why the market crashed?',
maxResults: 5,
includeContent: false,
country: 'us',
language: 'en'
})
});
const data = await response.json();
console.log(data);
}
searchWithWebSearchAPI();Understanding the Response
The API will return a JSON response with the following structure:
{
"searchParameters": {
"query": "Why the market crashed?",
"maxResults": 5,
"includeContent": false,
"country": "us",
"language": "en"
},
"organic": [
{
"title": "U.S. stocks plunge after Trump's tariff shock to global trade",
"url": "https://www.nbcnews.com/business/markets/us-stocks-dow-nasdaq-sp-plummet-trump-tariffs-rcna199476",
"description": "U.S. stocks take a historic plunge after Trump's tariffs shock global trade. Wall Street notched its worst day since the depths of the pandemic ...",
"position": 1
},
{
"title": "Markets Crash, Economists Warn of Recession as Trump ...",
"url": "https://www.usnews.com/news/economy/articles/2025-04-03/markets-crash-economists-warn-of-recession-as-trump-announces-sweeping-import-tariffs-on-many-countries",
"description": "The announcement of sweeping tariffs of at least 10% on U.S. imports rocked markets Thursday and had economists warning of dire times for ...",
"position": 2
},
{
"title": "Markets Shudder At Trump's Tariffs: S&P 500 Has Worst Day In 5 ...",
"url": "https://www.forbes.com/sites/dereksaul/2025/04/03/markets-shudder-heres-what-stocks-are-losing-the-most-in-tariff-selloff/",
"description": "Stocks nosedived across the board Thursday as Wall Street largely panned the highly aggressive tariffs announced by President Donald Trump, ...",
"position": 3
},
{
"title": "Stock market plunges after Trump tariff announcement - NBC News",
"url": "https://www.nbcnews.com/video/stock-market-plunges-after-trump-tariff-announcement-236427845598",
"description": "The markets closed down around 4% after President Donald Trump's announcement to slap reciprocal tariffs on global trading partners.",
"position": 4
}
]
}When you set includeContent: true, the API will automatically crawl each
page and return the full content in structured markdown format, ready for AI
consumption.
API Parameters
Code Examples
# With full content crawling enabled
curl -X POST https://api.websearchapi.ai/ai-search \
-H "Content-Type: application/json" \
-H "Authorization: Bearer APIKEY" \
-d '{
"query": "Latest AI advancements",
"maxResults": 3,
"includeContent": true,
"country": "us",
"language": "en"
}'Using the Web Scraper API
The Web Scraper API allows you to extract content from any URL with advanced features like browser rendering, CSS selectors, and AI-powered image alt text generation.
Basic Scraping Example
curl -X POST https://api.websearchapi.ai/scrape \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"url": "https://example.com/article",
"returnFormat": "markdown",
"engine": "browser"
}'Advanced Scraping with Selectors
import requests
API_KEY = "your_api_key_here"
url = "https://api.websearchapi.ai/scrape"
headers = {
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json"
}
payload = {
"url": "https://example.com/article",
"returnFormat": "markdown",
"engine": "browser",
"targetSelector": "article, main",
"removeSelector": "header, footer, nav, .ads",
"withLinksSummary": True,
"withImagesSummary": True
}
response = requests.post(url, headers=headers, json=payload)
data = response.json()
print(f"Title: {data['data']['title']}")
print(f"Content: {data['data']['content'][:200]}...")Scraper API Response
{
"code": 200,
"data": {
"title": "Example Article Title",
"url": "https://example.com/article",
"content": "# Example Article Title\n\nClean markdown content...",
"links": {
"https://example.com/related": "Related Article"
},
"images": {
"https://example.com/image.jpg": "AI-generated alt text"
}
}
}The Scraper API supports multiple rendering engines, CSS selectors for precise content extraction, JavaScript injection, and customizable markdown formatting. See the Scraper API documentation for complete details.
Next Steps
Now that you've made your first API calls, explore:
- Web Search API Reference - Complete documentation for search capabilities
- Web Scraper API Reference - Complete documentation for scraping features
- API Playground - Test APIs interactively
- Dashboard - Manage your API keys and monitor usage
For any questions or issues, please reach out to our support team or visit our community forum.