How fatwang2/search2ai works
search2ai is a self-hosted, Perplexity-compatible search gateway: clients submit search, news, or crawl requests and receive normalized results with provider identity and fallback warnings. Its library core selects configured providers, retries along operation-specific chains, optionally enriches results with crawled content, and caches responses. Hono exposes HTTP and MCP interfaces; an optional legacy chat proxy injects gateway tools into OpenAI-compatible chat requests. Provider implementations and several HTTP/MCP relationships are shown in the supplied source index and excerpts; edges for documented but unsampled deployment capabilities are omitted.
Main entry points: gateway.ts Gateway operations · app.ts HTTP routes · index.ts Provider registry · http.ts Provider HTTP helpers
Components 20
Client interfaces
- Hono assembly
src/hono.ts - HTTP routes
src/server/app.ts - MCP tools
src/mcp/server.ts - OpenAPI document
src/server/openapi.ts
Gateway core
- Gateway operations
src/core/gateway.ts - Configuration
src/core/config.ts - Fallback chain
src/core/fallback.ts - Result cache
src/core/cache.ts - Request schemas
src/core/schema.ts
Search providers
- Provider registry
src/core/providers/index.ts - Search1API
src/core/providers/search1api.ts - Tavily
src/core/providers/tavily.ts - Exa
src/core/providers/exa.ts - Other search backends
src/core/providers - Crawl backends
src/core/providers - Provider HTTP helpers
src/core/http.ts
Chat compatibility
- Chat upstream
src/chat/upstream.ts - Tool-using chat proxy
src/chat/proxy.ts
Other components
- API clients
- OpenAI-compatible model
Connections 29
- API clients → Hono assembly: calls
README.md - Hono assembly → Configuration: builds config
src/hono.ts - Hono assembly → Gateway operations: creates
src/hono.ts - Hono assembly → HTTP routes: assembles
src/hono.ts - HTTP routes → Gateway operations: routes requests
src/server/app.ts - HTTP routes → Request schemas: validates
src/server/app.ts - HTTP routes → MCP tools: connects transport
src/server/app.ts - HTTP routes → OpenAPI document: serves document
src/server/app.ts - MCP tools → Gateway operations: invokes tools
src/mcp/server.ts - Gateway operations → Configuration: uses settings
src/core/gateway.ts - Gateway operations → Provider registry: creates providers
src/core/gateway.ts - Gateway operations → Fallback chain: runs operations
src/core/gateway.ts - Gateway operations → Result cache: reads writes
src/core/gateway.ts - Provider registry → Search1API: registers
src/core/providers/index.ts - Provider registry → Tavily: registers
src/core/providers/index.ts - Provider registry → Exa: registers
src/core/providers/index.ts - Provider registry → Other search backends: registers
src/core/providers/index.ts - Provider registry → Crawl backends: registers
src/core/providers/index.ts - Search1API → Provider HTTP helpers: uses
src/core/providers/search1api.ts - Tavily → Provider HTTP helpers: uses
src/core/providers/tavily.ts - Exa → Provider HTTP helpers: uses
src/core/providers/exa.ts - Other search backends → Provider HTTP helpers: uses
src/core/providers/index.ts - Crawl backends → Provider HTTP helpers: uses
src/core/providers/index.ts - API clients → Tool-using chat proxy: submits chat
README.md - HTTP routes → Tool-using chat proxy: routes completions
src/server/app.ts - Tool-using chat proxy → Gateway operations: executes tools
src/chat/proxy.ts - Tool-using chat proxy → Chat upstream: calls completions
src/chat/proxy.ts - HTTP routes → Chat upstream: forwards requests
src/server/app.ts - Chat upstream → OpenAI-compatible model: sends requests
src/chat/upstream.ts