介绍
# Brave Image Search
通过 Brave Search API 搜索图片。
## 使用方法
```bash curl -s "https://api.search.brave.com/res/v1/images/search?q=QUERY&count=COUNT" \ -H "X-Subscription-Token: $BRAVE_API_KEY" ```
## 参数
| 参数 | 是否必填 | 描述 | |-------|----------|-------------| | `q` | 是 | 搜索词(URL 编码) | | `count` | 否 | 结果数量(1-100,默认 20) | | `country` | 否 | 用于区域偏好的 2 字母国家代码(US, DE, IL) | | `search_lang` | 否 | 语言代码(en, de, he) | | `safesearch` | 否 | off, moderate, strict(默认:moderate) |
## 响应解析
每个结果中的关键字段: - `results[].title` — 图片标题 - `results[].properties.url` — 完整图片 URL - `results[].thumbnail.src` — 缩略图 URL - `results[].source` — 来源网站 - `results[].properties.width/height` — 尺寸
## 示例
在以色列搜索“sunset beach”图片: ```bash curl -s "https://api.search.brave.com/res/v1/images/search?q=sunset%20beach&count=5&country=IL" \ -H "X-Subscription-Token: $BRAVE_API_KEY" ```
然后从 JSON 响应中提取: - 缩略图:`.results[0].thumbnail.src` - 完整图片:`.results[0].properties.url`
## 展示结果
展示图片搜索结果时: 1. 直接向用户发送图片(不要仅列出 URL) 2. 完整图片使用 `results[].properties.url`,缩略图使用 `results[].thumbnail.src` 3. 将图片标题作为说明文字 4. 如果结果多于展示的数量,告知用户(例如:“找到 20 张图片,展示了 3 张 — 需要更多吗?”)
示例流程: ``` User: "find me pictures of sunsets" → Search with count=10 → Send 3-5 images with captions → "Found 10 sunset images, showing 5. Want to see more?" ```
## 注意事项
- 查询字符串需要进行 URL 编码(空格 → `%20`) - API 密钥来自环境变量:`$BRAVE_API_KEY` - 遵守订阅层级的速率限制