跳到正文
OpenRouter:Announcements· OpenRouter·· 2025-01-23AI 评分47

通过 API 引入网络搜索功能

Introducing Web Search via the API

AI 导读

Anthropic 宣布通过 API 为其 AI 模型 Claude 提供联网搜索功能。该功能允许开发者在 API 请求中直接集成实时网络搜索结果,确保模型能获取并基于最新信息进行回应。此举旨在提升 Claude 回答的时效性与准确性,使其能够处理需要当前数据支持的查询,例如新闻、股价或体育比分。用户需在 API 调用中显式启用此搜索选项。

正文 · 原文

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 web plugin directly in your API requests, or the :online shortcut 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.

来源:OpenRouter:Announcements · openrouter.ai