API Documentation
AI Search Gateway provides a unified REST API and MCP server for web search and page content extraction. SearXNG-powered with intelligent fallback chains. Self-hosted with full data control.
Base URL
https://search.iamnaime.info.bd
All API endpoints are relative to this base URL. The server uses TLS 1.3 encryption in production.
Authentication
All API requests require a Bearer token in the Authorization header.
Tokens are SHA-256 hashed. Comparison uses constant-time crypto.timingSafeEqual to prevent timing attacks.
Authorization: Bearer YOUR_API_KEY
Two Authentication Sources
The gateway checks two sources in order: API_TOKENS env var (admin tokens, SHA-256 hashed) and api-keys.json (user-generated keys).
User keys grant access to /v1/* and /mcp endpoints. Admin tokens have full access.
Search API
/v1/search
Search the web across 70+ engines via SearXNG with DuckDuckGo fallback. Returns structured results with titles, URLs, and snippets.
Query Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
q |
string | Yes | Search query. URL-encoded. |
categories |
string | No | Engine categories. Comma-separated. Examples: general, images, news, science, files |
engines |
string | No | Specific engines. Comma-separated. Examples: google, bing, duckduckgo, brave, wikipedia, arxiv |
language |
string | No | Search language. Format: lang-COUNTRY. Default: en-US. Examples: en-GB, fr-FR, de-DE |
time_range |
string | No | Time filter. Values: day, week, month, year |
safesearch |
integer | No | Safe search level. 0 = off, 1 = moderate, 2 = strict. Default: 1 |
Example Request
# Basic search $ curl -H "Authorization: Bearer $TOKEN" \ "https://search.iamnaime.info.bd/v1/search?q=latest+AI+news" # With filters $ curl -H "Authorization: Bearer $TOKEN" \ "https://search.iamnaime.info.bd/v1/search?q=climate+change&engines=google,bing&time_range=week&language=en-US" # Node.js const res = await fetch('/v1/search?q=hello+world', { headers: { 'Authorization': `Bearer ${TOKEN}` } }); const data = await res.json();
Response
{
"query": "latest AI news",
"results": [
{
"title": "Article Title",
"url": "https://example.com/article",
"content": "Snippet text...",
"engine": "google",
"score": 0.95,
"category": "general"
}
],
"number_of_results": 10,
"engine": "searxng",
"cached": false,
"request_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
}
Read API
/v1/read
Extract clean, readable text from any URL. Uses page-reader service (trafilatura) with local HTML extraction fallback. Handles JavaScript-rendered content and complex layouts. Dual fallback chain ensures high availability.
Request Body (JSON)
| Field | Type | Required | Description |
|---|---|---|---|
url |
string | Yes | URL to extract content from. Must be a valid HTTP/HTTPS URL. Internal IPs blocked (SSRF protection). |
timeout |
integer | No | Extraction timeout in seconds. Range: 1-30. Default: 10 |
$ curl -X POST \ -H "Authorization: Bearer $TOKEN" \ -H "Content-Type: application/json" \ -d '{"url":"https://docs.anthropic.com","timeout":15}' \ "https://search.iamnaime.info.bd/v1/read" # Node.js const res = await fetch('/v1/read', { method: 'POST', headers: { 'Authorization': `Bearer ${TOKEN}`, 'Content-Type': 'application/json' }, body: JSON.stringify({ url: 'https://example.com' }) });
{
"url": "https://docs.anthropic.com",
"title": "Anthropic Documentation",
"text": "Extracted page content (plain text)...",
"word_count": 1542,
"method_used": "page-reader",
"cached": false,
"request_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
}
Text Truncation: Responses are truncated to 8,000 characters by default (configurable via MAX_TEXT_LENGTH).
When truncated, the response includes a truncated: true field.
MCP Server
/mcp
Native Model Context Protocol server with SSE (Server-Sent Events) transport. Compatible with Claude Code, Claude Desktop, Cursor, and any MCP client. Provides tools for web search and page reading directly from AI agents.
GET /mcp
Establishes SSE connection. Returns event stream.
POST /mcp/messages?sessionId=xxx
JSON-RPC message channel. Raw body stream (not JSON middleware).
Available Tools
web_search
SEARCH
General web search via SearXNG. Accepts query, engines, language, time_range, categories, and safesearch parameters. Falls back to DuckDuckGo HTML on SearXNG failure.
search_images
IMAGES
Image search via SearXNG. Returns titles, URLs, thumbnails, and source info. Uses the images category across multiple engines.
search_videos
VIDEOS
Video search via SearXNG. Returns titles, URLs, thumbnails, duration, and publication dates. Aggregates from YouTube, Vimeo, Dailymotion, and more.
search_news
NEWS
News article search via SearXNG. Returns titles, URLs, snippets, publication dates, and source outlets. Supports time_range filtering (day, week, month, year).
search_papers
SCIENCE
Academic paper search via SearXNG. Returns titles, URLs, snippets, authors, journals, and DOIs. Aggregates from arXiv, Google Scholar, Semantic Scholar, PubMed, and more.
read_page
EXTRACT
Extract readable text from a URL. Uses page-reader service (trafilatura) with local HTML extraction fallback. Returns title, text content, and word count. Max 8,000 chars.
Client Configuration
Claude Code
{
"mcpServers": {
"web-search": {
"url": "https://search.iamnaime.info.bd/mcp",
"headers": {
"Authorization": "Bearer YOUR_API_KEY"
}
}
}
}
Claude Desktop
{
"mcpServers": {
"web-search": {
"url": "https://search.iamnaime.info.bd/mcp",
"headers": {
"Authorization": "Bearer YOUR_API_KEY"
}
}
}
}
Rate Limits
Differentiated rate limits per route. Applied per API key (falls back to IP if no key). Uses sliding window algorithm. Both REST and MCP endpoints share the same limits.
| Route | Limit | Window |
|---|---|---|
/v1/search |
20 requests | 1 minute |
/v1/read |
40 requests | 1 minute |
/mcp (all tools) |
60 requests | 1 minute |
| Default / other | 60 requests | 1 minute |
| Monthly per user | 43,200 requests | calendar month |
# Response includes IETF rate limit headers: RateLimit-Limit: 20 RateLimit-Remaining: 18 RateLimit-Reset: 45 Retry-After: 12 # only on 429
Caching
LRU cache with configurable TTL. HTTP ETag support for 304 Not Modified responses.
Error Format
All errors follow a consistent envelope format. Every response includes a request_id (UUID) for debugging,
also available in the X-Request-Id response header.
{
"error": {
"code": "VALIDATION_ERROR",
"message": "Missing required parameter: q",
"details": {},
"status": 400
},
"request_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
}
Common Error Codes
| Status | Code | Description |
|---|---|---|
| 400 | VALIDATION_ERROR |
Missing or invalid request parameters |
| 401 | UNAUTHORIZED |
Missing or invalid Authorization header |
| 403 | SSRF_BLOCKED |
URL targets internal/private IP range |
| 408 | EXTRACTION_TIMEOUT |
Page extraction exceeded timeout |
| 429 | RATE_LIMIT_EXCEEDED |
Too many requests. Check Retry-After header. |
| 429 | QUOTA_EXCEEDED |
Monthly request quota exceeded |
| 500 | INTERNAL_ERROR |
Unexpected server error |
| 502 | UPSTREAM_FAILURE |
Both page-reader and local fallback failed |
Quick Start
Get up and running in under a minute.
Step 1: Get your API key
Register at search.iamnaime.info.bd with your email. Verify the 6-digit code. Your API key is sent via email.
Step 2: Test your key
$ curl -s -H "Authorization: Bearer YOUR_KEY" \ "https://search.iamnaime.info.bd/v1/search?q=hello+world" | jq .number_of_results 10
Step 3: Connect your AI tool
Add the MCP server to your Claude Code or Claude Desktop config. See MCP Configuration above.
Step 4: Start searching
Your AI agent can now use web_search and read_page tools to access the internet in real time.