search_models
Find and filter AI models on OpenRouter.ai by criteria like price, context length, provider, and capabilities including vision or function calling.
Instructions
Search and filter OpenRouter.ai models based on various criteria
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | No | Optional search query to filter by name, description, or provider | |
| provider | No | Filter by specific provider (e.g., "anthropic", "openai", "cohere") | |
| minContextLength | No | Minimum context length in tokens | |
| maxContextLength | No | Maximum context length in tokens | |
| maxPromptPrice | No | Maximum price per 1K tokens for prompts | |
| maxCompletionPrice | No | Maximum price per 1K tokens for completions | |
| capabilities | No | Filter by model capabilities | |
| limit | No | Maximum number of results to return (default: 10) |
Implementation Reference
- src/tool-handlers/search-models.ts:20-68 (handler)The main handler function that implements the core logic of the 'search_models' tool. It refreshes the model cache if necessary, performs the search using ModelCache.searchModels, formats results as JSON, and handles errors.export async function handleSearchModels( request: { params: { arguments: SearchModelsToolRequest } }, apiClient: OpenRouterAPIClient, modelCache: ModelCache ) { const args = request.params.arguments; try { // Refresh the cache if needed if (!modelCache.isCacheValid()) { const models = await apiClient.getModels(); modelCache.setModels(models); } // Search models based on criteria const results = modelCache.searchModels({ query: args.query, provider: args.provider, minContextLength: args.minContextLength, maxContextLength: args.maxContextLength, maxPromptPrice: args.maxPromptPrice, maxCompletionPrice: args.maxCompletionPrice, capabilities: args.capabilities, limit: args.limit || 10, }); return { content: [ { type: 'text', text: JSON.stringify(results, null, 2), }, ], }; } catch (error) { if (error instanceof Error) { return { content: [ { type: 'text', text: `Error searching models: ${error.message}`, }, ], isError: true, }; } throw error; } }
- TypeScript interface defining the expected input shape (SearchModelsToolRequest) for the search_models tool, used for type checking in the handler.export interface SearchModelsToolRequest { query?: string; provider?: string; minContextLength?: number | string; maxContextLength?: number | string; maxPromptPrice?: number | string; maxCompletionPrice?: number | string; capabilities?: { functions?: boolean; tools?: boolean; vision?: boolean; json_mode?: boolean; }; limit?: number | string; }
- src/tool-handlers.ts:222-283 (registration)Registration of the 'search_models' tool in the ListTools response, specifying name, description, and full inputSchema matching the handler's expected arguments.// Search Models Tool { name: 'search_models', description: 'Search and filter OpenRouter.ai models based on various criteria', inputSchema: { type: 'object', properties: { query: { type: 'string', description: 'Optional search query to filter by name, description, or provider', }, provider: { type: 'string', description: 'Filter by specific provider (e.g., "anthropic", "openai", "cohere")', }, minContextLength: { type: 'number', description: 'Minimum context length in tokens', }, maxContextLength: { type: 'number', description: 'Maximum context length in tokens', }, maxPromptPrice: { type: 'number', description: 'Maximum price per 1K tokens for prompts', }, maxCompletionPrice: { type: 'number', description: 'Maximum price per 1K tokens for completions', }, capabilities: { type: 'object', description: 'Filter by model capabilities', properties: { functions: { type: 'boolean', description: 'Requires function calling capability', }, tools: { type: 'boolean', description: 'Requires tools capability', }, vision: { type: 'boolean', description: 'Requires vision capability', }, json_mode: { type: 'boolean', description: 'Requires JSON mode capability', } } }, limit: { type: 'number', description: 'Maximum number of results to return (default: 10)', minimum: 1, maximum: 50 } } }, },
- src/tool-handlers.ts:349-354 (registration)Dispatch logic in the CallToolRequest handler that routes 'search_models' tool calls to the handleSearchModels function with appropriate parameters and dependencies.case 'search_models': return handleSearchModels({ params: { arguments: request.params.arguments as SearchModelsToolRequest } }, this.apiClient, this.modelCache);