API Reference v1

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.

REST API MCP SSE Bearer Auth JSON

Base URL

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.

HTTP HEADER
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.

Read API

POST /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)

FieldTypeRequiredDescription
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 COPY
$ 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' })
});
200 OK application/json
{
  "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

SSE /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.

SSE Endpoint
GET /mcp

Establishes SSE connection. Returns event stream.

Messages Endpoint
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

.claude/settings.json COPY
{
  "mcpServers": {
    "web-search": {
      "url": "https://search.iamnaime.info.bd/mcp",
      "headers": {
        "Authorization": "Bearer YOUR_API_KEY"
      }
    }
  }
}

Claude Desktop

claude_desktop_config.json COPY
{
  "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.

RouteLimitWindow
/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
RATE_LIMIT_HEADERS
# 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.

Search Cache
TTL5 minutes (300s)
Max entries1,000
KeyQuery + params hash
Read Cache
TTL1 hour (3600s)
Max entries1,000
KeyURL

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 RESPONSE
{
  "error": {
    "code": "VALIDATION_ERROR",
    "message": "Missing required parameter: q",
    "details": {},
    "status": 400
  },
  "request_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890"
}

Common Error Codes

StatusCodeDescription
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

terminal COPY
$ 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.