Skip to content

Commit c599fb7

Browse files
committed
feat: add OpenRouter provider support and icon
1 parent e7e0f84 commit c599fb7

File tree

4 files changed

+34
-0
lines changed

4 files changed

+34
-0
lines changed

astrbot/core/config/default.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,6 +1042,18 @@ class ChatProviderTemplate(TypedDict):
10421042
"proxy": "",
10431043
"custom_headers": {},
10441044
},
1045+
"OpenRouter": {
1046+
"id": "openrouter",
1047+
"provider": "openrouter",
1048+
"type": "openrouter_chat_completion",
1049+
"provider_type": "chat_completion",
1050+
"enable": True,
1051+
"key": [],
1052+
"timeout": 120,
1053+
"api_base": "https://openrouter.ai/v1",
1054+
"proxy": "",
1055+
"custom_headers": {},
1056+
},
10451057
"NVIDIA": {
10461058
"id": "nvidia",
10471059
"provider": "nvidia",

astrbot/core/provider/manager.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,10 @@ def dynamic_import_provider(self, type: str) -> None:
301301
from .sources.oai_aihubmix_source import (
302302
ProviderAIHubMix as ProviderAIHubMix,
303303
)
304+
case "openrouter_chat_completion":
305+
from .sources.openrouter_source import (
306+
ProviderOpenRouter as ProviderOpenRouter,
307+
)
304308
case "anthropic_chat_completion":
305309
from .sources.anthropic_source import (
306310
ProviderAnthropic as ProviderAnthropic,
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from ..register import register_provider_adapter
2+
from .openai_source import ProviderOpenAIOfficial
3+
4+
5+
@register_provider_adapter("openrouter_chat_completion", "OpenRouter Chat Completion Provider Adapter")
6+
class ProviderOpenRouter(ProviderOpenAIOfficial):
7+
def __init__(
8+
self,
9+
provider_config: dict,
10+
provider_settings: dict,
11+
) -> None:
12+
super().__init__(provider_config, provider_settings)
13+
# Reference to: https://openrouter.ai/docs/api/reference/overview#headers
14+
self.client._custom_headers["HTTP-Referer"] = ( # type: ignore
15+
"https://github.com/AstrBotDevs/AstrBot"
16+
)
17+
self.client._custom_headers["X-TITLE"] = "AstrBot" # type: ignore

dashboard/src/utils/providerUtils.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ export function getProviderIcon(type) {
3434
'vllm': 'https://registry.npmmirror.com/@lobehub/icons-static-svg/latest/files/icons/vllm.svg',
3535
'groq': 'https://registry.npmmirror.com/@lobehub/icons-static-svg/latest/files/icons/groq.svg',
3636
'aihubmix': 'https://registry.npmmirror.com/@lobehub/icons-static-svg/latest/files/icons/aihubmix-color.svg',
37+
'openrouter': 'https://registry.npmmirror.com/@lobehub/icons-static-svg/latest/files/icons/openrouter.svg',
3738
"tokenpony": "https://tokenpony.cn/tokenpony-web/logo.png",
3839
"compshare": "https://compshare.cn/favicon.ico"
3940
};

0 commit comments

Comments
 (0)