Xpersona
T

Tavily Quota Router

CLAWHUB · Unverified

Tavily quota-aware multi-key search router. Load BEFORE issuing any web_search call (Tavily is the default backend in this Hermes install, and burst searches...

62
Rank
84
Safety
1.2k
Downloads

About

What it does, and when to use it.

Capability contract not published. No trust telemetry is available yet. 1.2K downloads reported by the source. Last updated 10/11/2026.

Avoid when

  • Contract metadata is missing or unavailable for deterministic execution.

Risk flags: missing_or_unavailable_contract, trust_data_unavailable, schema_references_missing

Install and run

Setup complexity: low.

clawhub skill install s170w2naqc89g91hx4dh7tjbq983g7h3:tavily-quota-router
  1. Install using `clawhub skill install s170w2naqc89g91hx4dh7tjbq983g7h3:tavily-quota-router` in an isolated environment before connecting it to live workloads.
  2. No published capability contract is available yet, so validate auth and request/response behavior manually.
  3. Review the upstream CLAWHUB listing at https://clawhub.ai/fangtang0206/tavily-quota-router before using production credentials.

Contract: missing

curl -s "https://www.xpersona.co/api/v1/agents/clawhub-fangtang0206-tavily-quota-router/snapshot"

Run-check

$0.02 USD

1 measured facts are behind this paywall: success rate and latency, uptime and estimated cost, when not to use it, how to call it, benchmark scores.

Agents pay $0.02 in USDC. A card payment is $0.50, the smallest a card allows.

Documentation

CLAWHUB

114,985 characters of source documentation, loaded on request.

Extracted files

5 files captured from the source.

SKILL.md

---
name: tavily-quota-router
description: >-
  Tavily quota-aware multi-key search router. Load BEFORE issuing any web_search call (Tavily is the default backend in this Hermes install, and burst searches burn rate limits within seconds). Use when you want reliable Tavily-backed web search across multiple API keys, automatic failover for invalid/rate-limited keys, official usage-based routing via Tavily's /usage endpoint, and status visibility for each key. Critical rules: max 1 web_search per assistant turn, stop on first 429, do not retry within cooldown.
---

# Tavily Quota Router

Use this skill for **multi-key Tavily search routing**. Do not confuse it with OpenClaw's built-in `web_search` provider.

## What this skill does

- Reads multiple Tavily API keys from `config/keys.json`
- Syncs each key's real usage from Tavily's official `/usage` endpoint
- Chooses a healthy key automatically before each search
- Skips invalid, rate-limited, exhausted, or cooled-down keys
- Exposes status information for every configured key

## Best use cases

Use this skill when the user wants any of the following:

- Multiple Tavily API keys with automatic routing
- Quota-aware Tavily search instead of single-key search
- Better resilience when one key becomes invalid or temporarily unavailable
- Visibility into per-key usage and remaining plan quota

## Files

- `config/keys.json` - active local multi-key configuration (do not publish with real keys)
- `config/keys.example.json` - editable example configuration
- `config/keys.publish.json` - safe publish template for packaging/release
- `state/quota.json` - local runtime state and cooldown markers
- `scripts/tavily_multi_key.py` - core router script

If `config/keys.json` is still empty, copy the structure from `config/keys.example.json` and add real keys before searching.

## Config format

### Recommended format (v2)

```json
{
  "format_version": 2,
  "cooldown_minutes": 10,
  "keys": [
    {
      "key": "tvly-your-key-1",
      "account": "your-email@example.com",
      "notes": "main account"
    },
    {
      "key": "tvly-your-key-2",
      "account": "backup@example.com",
      "notes": "backup key"
    }
  ]
}
```

### Legacy format (still supported)

```json
{
  "cooldown_minutes": 10,
  "keys": [
    "tvly-your-key-1",
    "tvly-your-key-2"
  ]
}
```

### Automatic migration

Legacy string-array configs are still supported. On first run, the router will automatically migrate the config to the v2 object format and write it back to `config/keys.json`.

If an older config used `source`, it will be mapped into `account` during migration.

## Commands

Show status:

```bash
python3 scripts/tavily_multi_key.py status
```

Test all keys:

```bash
python3 scripts/tavily_multi_key.py test-keys
```

Search:

```bash
python3 scripts/tavily_multi_key.py search --query 'OpenClaw docs' --count 5
```

Reset only local state:

```bash
python3 scripts/tavily_multi_key.py reset-month
```

## 🔴 BURST GUARD — HARD 

README.md

# Tavily Quota Router

**Multi-key Tavily search router with auto-failover, 429-aware cooldown, and quota observability.**

[![License: MIT-0](https://img.shields.io/badge/License-MIT--0-blue.svg)](https://opensource.org/licenses/MIT-0)

Tavily is a great web search API for AI agents, but a single API key has hard rate limits (100 RPM for dev keys, 1000/month quota) — one burst from your agent and you're 429-blocked. This router solves that by rotating across multiple keys automatically.

**For installation and configuration, see [QUICKSTART.md](./QUICKSTART.md).**

## What it does

- **Auto-rotates across keys** — when key A 429s, the next search automatically uses key B
- **Honors Tavily's `Retry-After` header** — instead of using a 10-minute blanket cooldown, the router waits exactly as long as Tavily tells it to (typically 10-60s)
- **Recovers from auth errors** — 401/403 puts a key on a 1-hour cooldown, then auto-reprobes (instead of permanently disabling it)
- **Per-key observability** — `status` shows usage, cooldown, and last error for each key
- **Hot-swappable keys** — edit `config/keys.json` while the router is running; changes take effect on the next search

## When to use this

✅ You have 2+ Tavily keys and want fault-tolerance  
✅ Your agent bursts >5 searches in quick succession  
✅ You use Tavily >500 times/month  
✅ You want to see per-key quota usage in real time

❌ You only have 1 key (direct HTTP is simpler)  
❌ You use Tavily <100 times/month (won't hit limits)  
❌ You need production-grade high concurrency (≥100 req/sec) — use the Tavily SDK with your own queue

## Install

```bash
clawhub install @fangtang0206/tavily-quota-router
```

Then follow [QUICKSTART.md](./QUICKSTART.md) — 5 commands, ~2 minutes.

## Usage

```bash
python3 ~/.hermes/skills/openclaw-imports/tavily-quota-router/scripts/tavily_multi_key.py search \
    --query "your query here" --count 5
```

Or import from your agent code:

```python
import subprocess, json
result = subprocess.run([
    'python3',
    '~/.hermes/skills/openclaw-imports/tavily-quota-router/scripts/tavily_multi_key.py',
    'search', '--query', q, '--count', '5'
], capture_output=True, text=True)
data = json.loads(result.stdout)
if data['ok']:
    for r in data['results']:
        print(r['title'], r['url'])
```

## Why these specific behaviors?

These are documented in [SKILL.md](./SKILL.md) and traced through verification transcripts in `references/`:

- [references/tavily-429-retry-after-2026-07-17.md](./references/tavily-429-retry-after-2026-07-17.md) — why we parse `Retry-After`, with a real Tavily 429 response dump
- [references/tavily-401-403-recovery-pattern.md](./references/tavily-401-403-recovery-pattern.md) — why we don't permanently disable on auth errors
- [references/state-machine-2026-07-08.md](./references/state-machine-2026-07-08.md) — `state/quota.json` field semantics
- [references/security-hardening.md](./references/security-hardening.md) — env var migration path for

_meta.json

{
  "ownerId": "kn70fwjpgmfpw6r22zf4aqdq8x83h1jv",
  "slug": "tavily-quota-router",
  "version": "1.1.1",
  "publishedAt": 1784279295456
}

references/security-hardening.md

# Security Hardening — keys.json Hygiene

Captured from the 2026-07-08 audit: 4 real `tvly-dev-...` keys were sitting in plaintext in `config/keys.json` on老大's NAS. The bundled `.gitignore` is a 34-byte stub that may not actually exclude them. Below is the migration path to environment variables.

## Threat model

| Vector | Risk | Impact |
|---|---|---|
| Backup leak (`/home/cubeSugar` → cloud sync) | High | All 4 keys exposed, attacker drains 4000 quota/month, account may be banned for ToS violation |
| Skill directory shared / published | Critical | Same as above, but adversary knows your account structure |
| `state/quota.json` leaked | Low | Reveals `last_sync_at` + key index map, useful for fingerprinting |
| `.gitignore` gap | High if you `git init` the parent | Sudden key exposure in commit history |

## Verify the .gitignore

```bash
cat /home/cubeSugar/.hermes/skills/openclaw-imports/tavily-quota-router/.gitignore
# Should exclude: config/keys.json  state/quota.json
# Real file is ~34 bytes — check it actually lists both
```

If either file is missing from the gitignore, add it:

```gitignore
config/keys.json
state/quota.json
```

## Migration to environment variables

The router script (`tavily_multi_key.py`) reads keys from JSON only. To swap to env-var-driven config, two options:

### Option A: wrapper script (least invasive)

Create `scripts/tavily_env.sh` that exports keys before calling the Python script:

```bash
#!/bin/bash
# scripts/tavily_env.sh
export TAVILY_KEY_1="${TAVILY_KEY_1}"
export TAVILY_KEY_2="${TAVILY_KEY_2}"
# ... as many as you have
exec python3 "$(dirname "$0")/tavily_multi_key.py" "$@"
```

Then in `config/keys.json` you'd still have a stub, but the **real** keys live in your shell env / secret manager. This is a half-measure — the JSON is still there.

### Option B: patch the script (cleaner)

Modify `load_config()` to read from `os.environ` when `config/keys.json` is absent:

```python
import os
def load_config():
    raw_cfg = load_json(CONFIG, {})
    if not raw_cfg.get('keys'):
        # Fall back to env vars: TAVILY_KEY_1, TAVILY_KEY_2, ...
        env_keys = []
        for i in range(1, 20):  # arbitrary upper bound
            k = os.environ.get(f'TAVILY_KEY_{i}')
            if k:
                env_keys.append({'key': k, 'account': os.environ.get(f'TAVILY_ACCOUNT_{i}'), 'notes': f'from env TAVILY_KEY_{i}'})
        if env_keys:
            return {'format_version': 2, 'cooldown_minutes': 10, 'keys': env_keys}
    # ... rest of original logic
```

Then `config/keys.json` only needs the example structure, real keys stay in `.bashrc` / systemd EnvironmentFile / secret manager.

## Quick wins (do these today)

1. **Check what `state/quota.json` shows** — if you don't recognize all 4 keys, rotate the unrecognized ones at https://app.tavily.com/home
2. **Verify the directory isn't in any git repo**:
   ```bash
   cd /home/cubeSugar/.hermes/skills/openclaw-imports/tavily-quota-router
   git rev-parse --is-in

references/state-machine-2026-07-08.md

# State Machine Walkthrough — 2026-07-08

Captured during a real 4-key health check on老大's NAS (fnOS / Debian 12). Used to verify the key status logic in `scripts/tavily_multi_key.py` and to find the answer to "when do disabled keys get re-evaluated?".

## Setup snapshot

- 4 keys configured, all `tvly-dev-...` format (Tavily Researcher plan, 1000 quota each)
- `state/quota.json` `month: 2026-04`, `last_sync_at: 2026-04-10T14:46:xx` (3 months stale)
- Key index 3 had `disabled: true` with `last_error: "HTTP 401"` from April 10

## Verification sequence

```bash
# 1. Full health check — refreshes ALL keys
python3 scripts/tavily_multi_key.py test-keys
```

Result: **all 4 keys returned 200 from `/usage`**, including the one marked `disabled: true` in state. The `test-keys` call ran `sync_all_usage` which re-evaluates every key and resets `disabled: false`, `last_error: null` on success.

| Index | Key (masked) | Pre-state | Post-state | `/usage` | Plan | Used / Limit |
|---|---|---|---|---|---|---|
| 0 | `tvly-dev...BORr` | healthy | healthy | ✅ | Researcher | 5 / 1000 |
| 1 | `tvly-dev...rzxM` | healthy | healthy | ✅ | Researcher | 6 / 1000 |
| 2 | `tvly-dev...gjVX` | healthy | healthy | ✅ | Researcher | 3 / 1000 |
| 3 | `tvly-dev...cUnO` | `disabled: true` | healthy | ✅ | Researcher | 0 / 1000 |

```bash
# 2. Real search — confirms routing logic
python3 scripts/tavily_multi_key.py search --query "抖音小游戏开发文档" --count 3
```

Result: `key_index: 3` was picked (糖仔's key, `account: acubesugar@outlook.com`), returned 3 valid results, all from `developer.open-douyin.com` / `layaair.com`. The `mark_success` call cleared key 3's state further.

## Confirmed logic (read straight from `tavily_multi_key.py`)

### What changes `disabled`

1. **`test-keys` / `status`** — calls `sync_all_usage`, which on `/usage` success sets `state['keys'][i]['disabled'] = False`. This is the **only** path that re-evaluates keys other than the one currently in use.
2. **Search success** — `mark_success` sets `disabled = False` **only for the key that succeeded**.
3. **Cross-month rollover** — `normalize_state` wipes the whole per-key list when `state.month != current_month()`. Happens silently on the first call of each new month.

### What sets `disabled: true`

- HTTP 401 or 403 from `/search` or `/usage` → `mark_error(... disable=True)`. Stays `true` forever (across restarts, across searches) until a `test-keys` run revalidates.

### What sets `cooldown_until`

- Non-401/403 errors (429, 5xx, timeout, network) → `mark_error(... disable=False)` sets `cooldown_until = now + cooldown_minutes` (default 10min).
- `is_cooled(st)` in `choose_key` skips keys where `now() < cooldown_until`.
- Cleared on next success via `mark_success`, or on `reset-month`.

## Common confusion clarified

**Q: A key was 401'd 3 months ago. Did it auto-recover?**
**A:** Yes — the April → May → June → July month rollovers silently reset its `disabled: true` marker. The state file in front of you was just

Sponsored

Ads related to Tavily Quota Router and adjacent AI workflows.