向 OpenCode 询问当前信息时,它可以搜索网络、阅读结果,并在回复中包含来源链接。
Find the latest Bun release and summarize the changes.
首次搜索时,系统会请你允许网络搜索并选择提供商。OpenCode 会在后续会话中记住你的选择。

提供商

OpenCode 内置五个搜索提供商:
| 提供商 | ID | 环境变量 | | --- | --- | --- | | Exa | exa | EXA_API_KEY | | Firecrawl | firecrawl | FIRECRAWL_API_KEY | | Parallel | parallel | PARALLEL_API_KEY | | Tavily | tavily | TAVILY_API_KEY | | TinyFish | tinyfish | TINYFISH_API_KEY(可选) |
在 TUI 中使用 /connect 连接账户,或在启动 OpenCode 前设置提供商的环境变量。
$ TAVILY_API_KEY=your-key opencode

选择

在 opencode.jsonc 中设置提供商,即可跳过选择提示。
{
  "$schema": "https://opencode.ai/config.json",
  "websearch": {
    "provider": "tavily",
  },
}
使用 "random" 可自动选择一个可用的提供商。每个会话会持续使用其选定的提供商,直到该提供商被限流。
{
  "$schema": "https://opencode.ai/config.json",
  "websearch": {
    "provider": "random",
  },
}

限制

当提供商返回 HTTP 429 时,随机选择会改用另一个可用的提供商重试搜索。被限流的提供商会等待其 Retry-After 时长;若响应中未包含有效时长,则等待 60 秒。
Exa returns HTTP 429
→ Exa enters cooldown
→ OpenCode retries with another provider
如果所有提供商都处于冷却中,搜索会立即失败。将会话迁移或重启其服务器会清除其记住的提供商;同一工作区内的会话共享冷却状态。

权限

网络搜索使用 websearch 权限动作,并以搜索查询作为资源。对于未明确允许的搜索,系统会先询问。
{
  "$schema": "https://opencode.ai/config.json",
  "permissions": [
    {
      "action": "websearch",
      "resource": "*",
      "effect": "ask",
    },
  ],
}
规则顺序与匹配方式请参阅权限。

禁用

将 websearch 设为 false,可从模型请求中移除网络搜索工具。
{
  "$schema": "https://opencode.ai/config.json",
  "websearch": false,
}