SDKs & Migration

Install a thin client, or point your existing provider code at SearchRouter with a one-line change. An agent can migrate an entire codebase for you.

SearchRouter is a hosted gateway; the SDKs are small HTTP clients over it (no models, no heavy dependencies), so installs are trivial and upgrades happen server-side.

Install

bash
pip install searchrouter
bash
npm install searchrouter

Python

python
from searchrouter import SearchRouter

sr = SearchRouter(api_key="sk-sr-...")          # or SEARCHROUTER_API_KEY

hits = sr.search("best vector databases for RAG",
                 model="searchrouter/auto-search",
                 provider={"sort": "quality"})
vecs = sr.embeddings(["hello", "world"],
                     model="cohere/embed-v4", input_type="document")
ranked = sr.rerank("hybrid search", ["doc a", "doc b"],
                   model="cohere/rerank-v3.5", top_n=1)

TypeScript / JavaScript

typescript
import { SearchRouter } from "searchrouter";

const sr = new SearchRouter({ apiKey: "sk-sr-..." });

const hits = await sr.search("best vector databases for RAG", {
  model: "searchrouter/auto-search",
  provider: { sort: "quality" },
});

Already using the OpenAI SDK? Change two lines.

SearchRouter's /embeddings is wire-compatible with OpenAI and /rerank matches Cohere. The cheapest migration is a config edit:

python
from openai import OpenAI

# point the official OpenAI SDK at SearchRouter - nothing else changes
client = OpenAI(api_key="sk-sr-...", base_url="https://searchrouter.ai/api/v1")
client.embeddings.create(model="openai/text-embedding-3-small", input=texts)
# swap "openai/" for "cohere/", "voyage/", "jina/" to change providers

Migrate an existing codebase

The SDK ships a scanner that finds direct provider calls (Exa, Tavily, Cohere, Voyage, OpenAI embeddings, Perplexity, LangChain) and emits per-provider replacement recipes. Mechanical swaps are applied automatically; the rest are rewritten by a coding agent using the recipes and the repo's AGENTS.md.

bash
python -m searchrouter.migrate scan ./your_app          # human report
python -m searchrouter.migrate scan ./your_app --json    # machine-readable, for an agent
python -m searchrouter.migrate apply ./your_app          # auto-apply the safe swaps

What each call-site maps to

You currently callReplace with
OpenAI embeddings.createBase-URL swap, or sr.embeddings(...)
Cohere rerank / embedsr.rerank(...) / sr.embeddings(..., input_type=...)
Exa search / search_and_contentssr.search(q, model="exa/neural")
Tavily client.searchsr.search(q, model="searchrouter/auto-search")
Voyage embedsr.embeddings(texts, model="voyage/voyage-3")
Perplexity sonarsr.answer(q, model="perplexity/sonar")
Why migrate? You don't just get parity - migrated code gains automatic fallback, provider switching by changing one string, unified billing, and usage analytics.