diff --git a/astrbot/core/config/default.py b/astrbot/core/config/default.py index 96772241c..944b074c4 100644 --- a/astrbot/core/config/default.py +++ b/astrbot/core/config/default.py @@ -1042,6 +1042,18 @@ CONFIG_METADATA_2 = { "proxy": "", "custom_headers": {}, }, + "OpenRouter": { + "id": "openrouter", + "provider": "openrouter", + "type": "openrouter_chat_completion", + "provider_type": "chat_completion", + "enable": True, + "key": [], + "timeout": 120, + "api_base": "https://openrouter.ai/v1", + "proxy": "", + "custom_headers": {}, + }, "NVIDIA": { "id": "nvidia", "provider": "nvidia", diff --git a/astrbot/core/provider/manager.py b/astrbot/core/provider/manager.py index 38700d5e8..a331c97e9 100644 --- a/astrbot/core/provider/manager.py +++ b/astrbot/core/provider/manager.py @@ -301,6 +301,10 @@ class ProviderManager: from .sources.oai_aihubmix_source import ( ProviderAIHubMix as ProviderAIHubMix, ) + case "openrouter_chat_completion": + from .sources.openrouter_source import ( + ProviderOpenRouter as ProviderOpenRouter, + ) case "anthropic_chat_completion": from .sources.anthropic_source import ( ProviderAnthropic as ProviderAnthropic, diff --git a/astrbot/core/provider/sources/openrouter_source.py b/astrbot/core/provider/sources/openrouter_source.py new file mode 100644 index 000000000..7727b24fe --- /dev/null +++ b/astrbot/core/provider/sources/openrouter_source.py @@ -0,0 +1,17 @@ +from ..register import register_provider_adapter +from .openai_source import ProviderOpenAIOfficial + + +@register_provider_adapter("openrouter_chat_completion", "OpenRouter Chat Completion Provider Adapter") +class ProviderOpenRouter(ProviderOpenAIOfficial): + def __init__( + self, + provider_config: dict, + provider_settings: dict, + ) -> None: + super().__init__(provider_config, provider_settings) + # Reference to: https://openrouter.ai/docs/api/reference/overview#headers + self.client._custom_headers["HTTP-Referer"] = ( # type: ignore + "https://github.com/AstrBotDevs/AstrBot" + ) + self.client._custom_headers["X-TITLE"] = "AstrBot" # type: ignore diff --git a/dashboard/src/utils/providerUtils.js b/dashboard/src/utils/providerUtils.js index 594f68e36..b02af6942 100644 --- a/dashboard/src/utils/providerUtils.js +++ b/dashboard/src/utils/providerUtils.js @@ -34,6 +34,7 @@ export function getProviderIcon(type) { 'vllm': 'https://registry.npmmirror.com/@lobehub/icons-static-svg/latest/files/icons/vllm.svg', 'groq': 'https://registry.npmmirror.com/@lobehub/icons-static-svg/latest/files/icons/groq.svg', 'aihubmix': 'https://registry.npmmirror.com/@lobehub/icons-static-svg/latest/files/icons/aihubmix-color.svg', + 'openrouter': 'https://registry.npmmirror.com/@lobehub/icons-static-svg/latest/files/icons/openrouter.svg', "tokenpony": "https://tokenpony.cn/tokenpony-web/logo.png", "compshare": "https://compshare.cn/favicon.ico" };