feat: add openrouter as a new provider #104
Open
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.
Description
Added OpenRouter.ai as a unified LLM provider option, allowing users to access multiple LLM providers (OpenAI, Anthropic, Google, etc.) through a single API key. This simplifies configuration management and provides a more flexible approach to LLM provider selection.
Related Issues
Resolves: Feature request for OpenRouter.ai support to simplify mcp_agent.secrets.yaml configuration
Related Issue
Changes Made
Configuration Files
openroutersection withapi_keyfieldllm_provideroptions to include "openrouter"openrouterconfiguration section withbase_url,default_model,base_max_tokens, andretry_max_tokenssettingsCode Implementation
utils/llm_utils.py:
get_preferred_llm_class()to support OpenRouter provider selectionget_default_models()to include OpenRouter model configurationschema/mcp-agent.config.schema.json:
OpenRouterSettingsdefinition with properties for api_key, base_url, and default_modelllm_providerenum to include "openrouter" optionopenrouterproperty to the main schemaDocumentation
Technical Details
Architecture Decision
OpenAIAugmentedLLMclass since OpenRouter provides an OpenAI-compatible APIprovider/modelformat as per OpenRouter specificationBenefits
✅ Simplified Configuration: Single API key for multiple LLM providers
✅ Unified Billing: Consolidated billing across all providers
✅ Easy Model Switching: Change models without managing multiple API keys
✅ Backward Compatible: Existing configurations continue to work unchanged
✅ Cost Optimization: Access to OpenRouter's competitive pricing
Checklist
Testing
Manual Testing Performed
Configuration Example
Additional Notes
Migration Path
Users can adopt OpenRouter incrementally:
llm_providerwhen readyFuture Enhancements
Breaking Changes
None. This is a purely additive feature that maintains full backward compatibility.
Screenshots/Examples
N/A - This is a configuration and backend integration feature without UI changes.