Tavily Metered Search
Web search with built-in usage tracking and quota management for Tavily API (free tier: 1000 searches/month).
Quick Start
CODEBLOCK0
Arguments
| Argument | Default | Description |
|---|
| INLINECODE0 | (required) | Search query string |
| INLINECODE1 |
5 | Number of results (1-10), configurable via config file |
|
--format |
md | Output:
raw (JSON),
brave (JSON),
md (Markdown) |
|
--include-answer | false | Include AI-generated short answer |
|
--search-depth |
basic |
basic or
advanced, configurable via config file |
|
--no-count | false | Skip usage tracking (still consumes API quota) |
Configuration
Edit config/config.json to customize default settings:
CODEBLOCK1
| Setting | Description | Default |
|---|
| INLINECODE14 | Monthly limit, blocks search when reached | 900 |
| INLINECODE15 |
Warning threshold, shows alert when reached | 800 |
|
searchDepth | Default search depth | basic |
|
defaultMaxResults | Default number of results | 5 |
Usage Tracking
- - Automatic tracking: Each successful search increments a counter stored in INLINECODE18
- Monthly reset: Counter resets on the 1st of each month
- Limit enforcement: When
limit is reached, search is blocked with a message suggesting web_fetch as alternative - Warning alert: When
warningThreshold is reached, a reminder is appended to search results
Output Formats
md (default)
Human-readable Markdown list:
CODEBLOCK2
raw
Full JSON with
query,
answer?, INLINECODE26
brave
Brave-like format: INLINECODE28
Requirements
- - Tavily API key via either:
- Environment variable:
TAVILY_API_KEY
-
~/.openclaw/.env file: INLINECODE31
Get a free API key at https://tavily.com
File Structure
CODEBLOCK3
Notes
- - Free tier: 1000 searches/month (default limit is 900 to leave buffer)
- Keep
--max-results small (3-5) to reduce token usage - Use
--no-count for testing without affecting quota
Tavily 计量搜索
内置使用追踪和配额管理的Tavily API网络搜索(免费套餐:每月1000次搜索)。
快速开始
bash
基础搜索(Markdown输出,默认)
python3 {baseDir}/scripts/tavily_search.py --query 今日AI新闻
附带简短回答
python3 {baseDir}/scripts/tavily_search.py --query 什么是RAG --include-answer
JSON输出
python3 {baseDir}/scripts/tavily_search.py --query python教程 --format raw
python3 {baseDir}/scripts/tavily_search.py --query python教程 --format brave
跳过计数(用于测试)
python3 {baseDir}/scripts/tavily_search.py --query 测试 --no-count
参数
| 参数 | 默认值 | 描述 |
|---|
| --query | (必需) | 搜索查询字符串 |
| --max-results |
5 | 结果数量(1-10),可通过配置文件设置 |
| --format | md | 输出格式:raw(JSON)、brave(JSON)、md(Markdown) |
| --include-answer | false | 包含AI生成的简短回答 |
| --search-depth | basic | basic或advanced,可通过配置文件设置 |
| --no-count | false | 跳过使用追踪(仍消耗API配额) |
配置
编辑config/config.json以自定义默认设置:
json
{
limit: 900,
warningThreshold: 800,
searchDepth: basic,
defaultMaxResults: 5
}
| 设置 | 描述 | 默认值 |
|---|
| limit | 月度限制,达到后阻止搜索 | 900 |
| warningThreshold |
警告阈值,达到时显示提醒 | 800 |
| searchDepth | 默认搜索深度 | basic |
| defaultMaxResults | 默认结果数量 | 5 |
使用追踪
- - 自动追踪:每次成功搜索都会递增存储在data/tavily-usage.json中的计数器
- 月度重置:计数器在每月1日重置
- 限制执行:达到limit时,搜索被阻止并显示建议使用web_fetch作为替代的消息
- 警告提醒:达到warningThreshold时,搜索结果末尾会附加提醒
输出格式
md(默认)
人类可读的Markdown列表:
- 1. 标题
https://example.com
- 摘要文本...
raw
完整JSON,包含query、answer?、results: [{title, url, content}]
brave
类Brave格式:{query, results: [{title, url, snippet}], answer?}
要求
- - Tavily API密钥,通过以下任一方式提供:
- 环境变量:TAVILY
APIKEY
- ~/.openclaw/.env文件:TAVILY
APIKEY=tvly-...
在https://tavily.com获取免费API密钥
文件结构
tavily-metered-search/
├── SKILL.md # 技能文档
├── scripts/
│ └── tavily_search.py # 主搜索脚本
├── config/
│ └── config.json # 用户配置
└── data/
└── tavily-usage.json # 运行时状态(自动维护)
备注
- - 免费套餐:每月1000次搜索(默认限制为900以留出缓冲)
- 保持--max-results较小(3-5)以减少令牌使用
- 使用--no-count进行测试而不影响配额