feat: add web search and provider routing support#142
Closed
Conversation
- Add plugins and web_search_options for web search configuration - Add comprehensive provider routing types (order, sort, quantizations, etc.) - Handle :online model suffix for automatic web search enablement - Add web search annotations to response schemas - Support all provider routing parameters from OpenRouter API Co-Authored-By: Louis <louis@openrouter.ai>
Contributor
Original prompt from Louis |
Contributor
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
louisgv
commented
Aug 7, 2025
Comment on lines
+96
to
+98
| ...(this.modelId.endsWith(':online') && !this.settings.plugins && { | ||
| plugins: [{ type: 'web' as const }] | ||
| }), |
louisgv
commented
Aug 7, 2025
Comment on lines
+332
to
+341
| if (choice.message.annotations) { | ||
| for (const annotation of choice.message.annotations) { | ||
| if (annotation.type === 'url_citation') { | ||
| content.push({ | ||
| type: 'text' as const, | ||
| text: `[Citation: ${annotation.title || annotation.url}](${annotation.url})`, | ||
| }); | ||
| } | ||
| } | ||
| } |
Member
Author
There was a problem hiding this comment.
Check if the aisdk has better data type for citation/annotation
louisgv
commented
Aug 7, 2025
Comment on lines
+127
to
+131
| url: z.string(), | ||
| title: z.string().optional(), | ||
| content: z.string().optional(), | ||
| start_index: z.number().optional(), | ||
| end_index: z.number().optional(), |
Member
Author
There was a problem hiding this comment.
wrong schema -- this should be:
url_citation: z.object({
end_index: z.number(),
start_index: z.number(),
title: z.string(),
url: z.string(),
content: z.string().optional(),
}),
Contributor
|
Closing this PR as it has been split into two separate PRs for easier review:
Both PRs contain the same functionality but are now logically separated for independent review and merging. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
feat: add web search and provider routing support
Summary
This PR adds comprehensive support for OpenRouter's web search and provider routing features to the AI SDK provider. The implementation includes:
Web Search Support:
pluginsarray withwebtypeweb_search_optionsparameter:onlinesuffixProvider Routing Support:
order,allow_fallbacks,require_parameters,data_collectiononly,ignore,quantizations,sort,max_priceThe implementation maintains backward compatibility and follows existing code patterns for parameter handling and response processing.
Review & Testing Checklist for Human
plugins: [{ type: 'web' }]) and built-in (web_search_options) approaches work with real API callsorder,sort,quantizations, etc. are properly sent to the API and affect routing behavior:onlinemodel suffix handling - Confirm that using a model ID ending in:onlineautomatically enables web search when no explicit plugins are providedRecommended test plan:
openrouter('meta-llama/llama-3.1-8b-instruct:online', { ... })plugins: [{ type: 'web', max_results: 3, search_prompt: 'Find recent news' }]provider: { order: ['anthropic', 'openai'], sort: 'price' }Diagram
%%{ init : { "theme" : "default" }}%% graph TD User[User Code] --> Settings["src/types/openrouter-chat-settings.ts"]:::major-edit Settings --> ChatModel["src/chat/index.ts"]:::major-edit ChatModel --> Schemas["src/chat/schemas.ts"]:::major-edit ChatModel --> API[OpenRouter API]:::context API --> Responses[API Responses]:::context Responses --> ChatModel Settings --> WebSearch["Web Search Types<br/>plugins, web_search_options"]:::major-edit Settings --> Routing["Provider Routing Types<br/>order, sort, quantizations"]:::major-edit ChatModel --> GetArgs["getArgs() method<br/>:online suffix handling"]:::major-edit ChatModel --> Processing["Response Processing<br/>annotations handling"]:::major-edit Schemas --> Annotations["Annotation Schemas<br/>url_citation objects"]:::major-edit subgraph Legend L1[Major Edit]:::major-edit L2[Minor Edit]:::minor-edit L3[Context/No Edit]:::context end classDef major-edit fill:#90EE90 classDef minor-edit fill:#87CEEB classDef context fill:#FFFFFFNotes
The implementation replicates OpenRouter's documented API structure but should be validated against actual API behavior, especially for edge cases in web search annotation handling and provider routing parameter validation.