Zero-dependency Tavily API proxy with automatic key rotation.
Tavily's free tier gives 1,000 searches/month per API key. MultiTavilyKey lets you pool multiple keys โ when one hits the rate limit (429), it automatically rotates to the next. Your tools keep working, no interruption.
Works with any MCP-compatible client: Hermes Agent, Codex CLI, Claude Desktop, Cursor, Windsurf, and any tool that can register an MCP server or call api.tavily.com.
Your MCP client (Hermes / Codex / Claude / โฆ)
โโโ localhost:8765 (MultiTavilyKey)
โโ TAVILY_API_KEY (primary) โ 200 โ return
โโ TAVILY_API_KEY_BACKUP1 โ 429 โ try next
โโ TAVILY_API_KEY_BACKUP2 โ 429 โ try next
โโ TAVILY_API_KEY_BACKUP3 โ 429 โ try next
โโ All exhausted โ clear error
The proxy serves two interfaces on the same port:
- MCP SSE endpoint (
GET /mcp+POST /mcp/message) โ implements the Model Context Protocol, exposingtavily_search,tavily_extract,tavily_research,tavily_crawl, andtavily_map - REST API proxy (
/*) โ forwards any POST toapi.tavily.com/{path}with key rotation
git clone https://github.com/lunkerchen/MultiTavilyKey.git
cd MultiTavilyKey
# Create .env with your Tavily API keys:
echo 'TAVILY_API_KEY=tvly-your-primary-key' >> .env
echo 'TAVILY_API_KEY_BACKUP1=tvly-backup-1' >> .env
echo 'TAVILY_API_KEY_BACKUP2=tvly-backup-2' >> .env
echo 'TAVILY_API_KEY_BACKUP3=tvly-backup-3' >> .envpython3 tavily-proxy.pyOr use the wrapper that loads from .env:
bash tavily-proxy.shHealth check:
curl http://127.0.0.1:8765/health
# โ {"status":"ok","keys_total":4,"service":"MultiTavilyKey"}Hermes Agent:
hermes mcp add tavily --url "http://localhost:8765/mcp"
hermes gateway restartCodex CLI:
codex mcp add tavily --url "http://localhost:8765/mcp"Claude Desktop:
// claude_desktop_config.json
{
"mcpServers": {
"tavily": {
"url": "http://localhost:8765/mcp"
}
}
}Cursor / Windsurf:
Add as an MCP server with URL http://localhost:8765/mcp.
# Edit paths in the plist, then:
cp com.multitavilykey.proxy.plist ~/Library/LaunchAgents/
launchctl load ~/Library/LaunchAgents/com.multitavilykey.proxy.plistOr run the installer:
bash install.shThe proxy starts at login, stays alive, and logs to mtk.log.
- Python 3.11+ โ install with "Add Python to PATH" checked
- Git for Windows (git-scm.com) or clone via any Git client
git clone https://github.com/lunkerchen/MultiTavilyKey.git
cd MultiTavilyKey
# Create .env with your Tavily API keys:
echo 'TAVILY_API_KEY=tvly-your-primary-key' >> .env
echo 'TAVILY_API_KEY_BACKUP1=tvly-backup-1' >> .env
echo 'TAVILY_API_KEY_BACKUP2=tvly-backup-2' >> .env
echo 'TAVILY_API_KEY_BACKUP3=tvly-backup-3' >> .envpython tavily-proxy.pyHealth check (in a new terminal):
curl http://127.0.0.1:8765/healthCreate a task that runs python tavily-proxy.py from the project directory at user login:
# One-liner to create a scheduled task
$action = New-ScheduledTaskAction -Execute "python" -Argument "tavily-proxy.py" -WorkingDirectory "$HOME\MultiTavilyKey"
$trigger = New-ScheduledTaskTrigger -AtLogOn
Register-ScheduledTask -TaskName "MultiTavilyKey" -Action $action -Trigger $trigger -RunLevel Limited -ForceOr use NSSM (Non-Sucking Service Manager) to run it as a Windows Service:
nssm install MultiTavilyKey "C:\path\to\python.exe" "C:\path\to\MultiTavilyKey\tavily-proxy.py"
nssm set MultiTavilyKey AppDirectory "C:\path\to\MultiTavilyKey"
nssm start MultiTavilyKeyLogs are written to mtk.log in the project directory.
If you use WSL2, follow the Linux instructions โ performance and reliability are better than native Windows for this kind of background proxy.
| Flag | Env var | Default | Description |
|---|---|---|---|
--host |
MTK_HOST |
127.0.0.1 |
Bind address |
--port |
MTK_PORT |
8765 |
Bind port |
--log-level |
โ | INFO |
DEBUG, INFO, WARNING, ERROR |
| Variable | Required | Purpose |
|---|---|---|
TAVILY_API_KEY |
โ | Primary Tavily API key |
TAVILY_API_KEY_BACKUP1 |
โ | First backup key |
TAVILY_API_KEY_BACKUP2 |
โ | Second backup key |
TAVILY_API_KEY_BACKUP3 |
โ | Third backup key |
MTK_HOST |
โ | Override bind host |
MTK_PORT |
โ | Override bind port |
MTK_ENV_FILE |
โ | Path to .env for the wrapper script |
- On HTTP 429 (rate limit / quota exceeded) or 402 (insufficient credits) โ automatically retries the next key
- Retries are instant (< 100ms overhead per retry)
- On other HTTP errors (4xx, 5xx) โ fails immediately (not a quota issue)
- When all keys are exhausted โ returns a clear error message
- Keys are tried in order:
TAVILY_API_KEYโBACKUP1โBACKUP2โBACKUP3
| Tool | Purpose |
|---|---|
tavily_search |
Web search with depth/domain/time/country control |
tavily_extract |
URL content extraction in clean text |
tavily_research |
Multi-source deep research and synthesis |
tavily_crawl |
Website crawling for page structure |
tavily_map |
Site structure exploration |
- โฆ use an API gateway? MultiTavilyKey is a single Python file with zero dependencies (stdlib only). No npm install, no Docker, no config file parsing.
- โฆ use one key? Tavily free tier is 1,000/month. Four keys = 4,000/month, and rotation is transparent.
- โฆ write a cron to swap keys? Cron has a delay between "key exhausted" and "key swapped". MultiTavilyKey retries in milliseconds.
- Python 3.11+ (stdlib only โ no pip install needed)
- macOS, Linux, or WSL
MIT