网络搜索
您可以通过激活和自定义 web
插件,或者将 :online
附加到模型后缀让 OpenRouter 上任何模型支持 Web 搜索:
{
"model": "openai/gpt-4o:online"
}
这是使用 web
插件的快捷方式,完全等同于:
{
"model": "openrouter/auto",
"plugins": [{ "id": "web" }]
}
该网络搜索插件由 Exa 提供支持,并使用其 "auto" 方法(关键字搜索和基于嵌入的网络搜索的组合)来查找最相关的结果并增强/巩固您的提示词。
解析网络搜索结果
所有模型(包括 Perplexity 和 OpenAI Online 等纯原生模型)的 Web 搜索结果均可在 API 中获得,并由 OpenRouter 进行标准化,以遵循 OpenAI Chat Completion Message type 中的相同注释模式:
{
"message": {
"role": "assistant",
"content": "Here's the latest news I found: ...",
"annotations": [
{
"type": "url_citation",
"url_citation": {
"url": "https://www.example.com/web-search-result",
"title": "Title of the web search result",
"content": "Content of the web search result", // Added by OpenRouter if available
"start_index": 100, // The index of the first character of the URL citation in the message.
"end_index": 200 // The index of the last character of the URL citation in the message.
}
}
]
}
}
自定义 Web 插件
可自定义 Web 插件允许的最大结果以及用于将它们附加到流式输出的提示词:
{
"model": "openai/gpt-4o:online",
"plugins": [
{
"id": "web",
"max_results": 1, // Defaults to 5
"search_prompt": "Some relevant web results:" // See default below
}
]
}
默认情况下,Web 插件使用以下搜索提示且使用当前日期:
A web search was conducted on `date`. Incorporate the following web search results into your response.
IMPORTANT: Cite them using markdown links named using the domain of the source.
Example: [nytimes.com](https://nytimes.com/some-page).
价格
该 Web 插件使用您的 OpenRouter 余额,并按 每 1000 条结果 $4 收费。默认情况下,max_results
设置为 5,因此每次请求最多需支付 $0.02,此外还需支付搜索结果提示词Token的 LLM 使用费。