OpenRouter 通过 API 引入网页搜索功能
阅读原文· openrouter.ai这是OpenRouter在2025年初推出的搜索API,当时让开发者能更方便地在请求中整合实时信息,现在看已经算不上新鲜事,但对当时需要这个功能的人来说还算实用。
OpenRouter 在其 API 中新增了网页搜索功能,使所有请求能够结合最新的网络搜索信息,从而获取更及时的响应结果。
Introducing Web Search via the API — OpenRouter Blog
Introducing Web Search via the API
OpenRouter · 1/23/2025
On this page
The OpenRouter API now supports a web search feature, available for all models. This enables developers to fetch and integrate web search results directly into their message streams. By appending :online to the model slug or activating the web plugin, you can include relevant, up-to-date information in your workflows.
Key Details
- Default Behavior: Fetches up to 5 web results per request.
- Pricing: $4 per 1,000 web results.
- Integration Options: Use the
webplugin directly in your API requests, or the:onlineshortcut for easier setup.
How it works
The web search plugin uses Exa.ai to retrieve results. Your prompt is passed to Exa, which executes relevant searches and summarizes the results. The results are then merged into a prompt. This is customizable (see below) but by default is:
A web search was conducted on {todays_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. [web search results are inserted here]
The plugin injects this as a system message before the user message in the request payload.
Example Usage
Append :online to any model slug to enable web search.
{
"model": "openai/gpt-4o:online"
}
This :online tag is simply shorthand for specifying the web plugin, which also works:
{
"model": "openai/gpt-4o",
"plugins": [{ "id": "web" }]
}
Customization Options
The web plugin has two customization options:
- Maximum Results: Control the number of results with
max_results(default: 5). - Custom Search Prompts: Tailor the prompt used to integrate results into the conversation.
Example:
{
"model": "openai/gpt-4o:online",
"plugins": [
{
"id": "web",
"max_results": 3,
"search_prompt": "Consider these web results when forming your response:"
}
]
}
For more information, check the documentation or try it directly with OpenRouter Chat by toggling the ‘web’ icon on the model selector.