feat: add openrouter support in litellm

This commit is contained in:
irfan.putra
2025-05-07 11:54:07 +07:00
parent f85587fb1f
commit 7a6a28d2b9
2 changed files with 16 additions and 1 deletions

View File

@ -118,6 +118,18 @@ class LiteLLMAIHandler(BaseAiHandler):
litellm.api_base = self.api_base
openai.api_base = self.api_base
# Support for Openrouter models
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
# Models that only use user meessage
self.user_message_only_models = USER_MESSAGE_ONLY_MODELS

View File

@ -108,3 +108,6 @@ client_id = "" # Your Azure AD application client ID
client_secret = "" # Your Azure AD application client secret
tenant_id = "" # Your Azure AD tenant ID
api_base = "" # Your Azure OpenAI service base URL (e.g., https://openai.xyz.com/)
[openrouter]
key = ""