Skip to content

Openrouter support #1744

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 8, 2025
Merged

Openrouter support #1744

merged 2 commits into from
May 8, 2025

Conversation

irfansofyana
Copy link

@irfansofyana irfansofyana commented May 7, 2025

PR Type

Enhancement, Documentation


Description

  • Added Openrouter API support to litellm_ai_handler

  • Updated documentation for Openrouter model usage

  • Extended secrets template to include Openrouter settings


Changes walkthrough 📝

Relevant files
Enhancement
litellm_ai_handler.py
Add Openrouter API key and base support to handler             

pr_agent/algo/ai_handlers/litellm_ai_handler.py

  • Added logic to support Openrouter API key and base URL
  • Set environment variables for Openrouter integration
  • Updated initialization to handle Openrouter settings
  • +12/-0   
    Documentation
    changing_a_model.md
    Document Openrouter model configuration and usage               

    docs/docs/usage-guide/changing_a_model.md

  • Added section explaining Openrouter model usage
  • Provided configuration and API key instructions for Openrouter
  • Linked to Openrouter API key generation page
  • +16/-0   
    Configuration changes
    .secrets_template.toml
    Add Openrouter section to secrets template                             

    pr_agent/settings/.secrets_template.toml

  • Added [openrouter] section for key and api_base
  • Updated template to support Openrouter configuration
  • +5/-1     

    Need help?
  • Type /help how to ... in the comments thread for any questions about Qodo Merge usage.
  • Check out the documentation for more information.
  • Copy link
    Contributor

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Potential Overwrite

    The Openrouter configuration might overwrite previous API settings without checking if Azure AD was already configured. Consider adding a condition to prevent unintended overrides.

    if get_settings().get("OPENROUTER.KEY", None):
        openrouter_api_key = get_settings().get("OPENROUTER.KEY", None)
        os.environ["OPENROUTER_API_KEY"] = openrouter_api_key
        litellm.api_key = openrouter_api_key
        openai.api_key = openrouter_api_key
    
        openrouter_api_base = get_settings().get("OPENROUTER.API_BASE", "https://openrouter.ai/api/v1")
        os.environ["OPENROUTER_API_BASE"] = openrouter_api_base
        self.api_base = openrouter_api_base
        litellm.api_base = openrouter_api_base
    Hardcoded URL

    The default Openrouter API base URL is hardcoded. Consider moving this default value to a constants file or configuration setting.

    openrouter_api_base = get_settings().get("OPENROUTER.API_BASE", "https://openrouter.ai/api/v1")
    os.environ["OPENROUTER_API_BASE"] = openrouter_api_base

    Copy link
    Contributor

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    General
    Remove redundant default value

    Avoid redundant check for None in the second call to get_settings().get(). The
    first check already confirms the key exists, and the second call uses the same
    default value unnecessarily.

    pr_agent/algo/ai_handlers/litellm_ai_handler.py [121-126]

     # Support for Openrouter models
     if get_settings().get("OPENROUTER.KEY", None):
    -    openrouter_api_key = get_settings().get("OPENROUTER.KEY", None)
    +    openrouter_api_key = get_settings().get("OPENROUTER.KEY")
         os.environ["OPENROUTER_API_KEY"] = openrouter_api_key
         litellm.api_key = openrouter_api_key
         openai.api_key = openrouter_api_key
    • Apply / Chat
    Suggestion importance[1-10]: 3

    __

    Why: The suggestion correctly identifies a redundant None default in the get_settings().get("OPENROUTER.KEY", None) call on line 123. Since the if condition on line 122 already ensures the key exists and its value is not None, providing None as a default in the subsequent get() call is unnecessary. The change is a minor code cleanup.

    Low
    • More
    • Author self-review: I have reviewed the PR code suggestions, and addressed the relevant ones.

    @irfansofyana
    Copy link
    Author

    Hi @mrT23 kindly request your review as one of the maintainer on this project, thanks!

    @mrT23
    Copy link
    Collaborator

    mrT23 commented May 8, 2025

    thanks @irfansofyana , openrouter is quite popular

    @mrT23 mrT23 merged commit f5857f0 into qodo-ai:main May 8, 2025
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    2 participants