feat(ai-proxy): add OpenRouter provider support (#2823)

This commit is contained in:
澄潭
2025-08-28 19:26:21 +08:00
committed by GitHub
parent b2ffeff7b8
commit 44c33617fa
11 changed files with 5684 additions and 184 deletions

View File

@@ -144,6 +144,10 @@ For Groq, the corresponding `type` is `groq`. It has no unique configuration fie
For Grok, the corresponding `type` is `grok`. It has no unique configuration fields.
#### OpenRouter
For OpenRouter, the corresponding `type` is `openrouter`. It has no unique configuration fields.
#### ERNIE Bot
For ERNIE Bot, the corresponding `type` is `baidu`. It has no unique configuration fields.
@@ -894,6 +898,63 @@ provider:
}
```
### Using OpenAI Protocol Proxy for OpenRouter Service
**Configuration Information**
```yaml
provider:
type: openrouter
apiTokens:
- 'YOUR_OPENROUTER_API_TOKEN'
modelMapping:
'gpt-4': 'openai/gpt-4-turbo-preview'
'gpt-3.5-turbo': 'openai/gpt-3.5-turbo'
'claude-3': 'anthropic/claude-3-opus'
'*': 'openai/gpt-3.5-turbo'
```
**Example Request**
```json
{
"model": "gpt-4",
"messages": [
{
"role": "user",
"content": "Hello, who are you?"
}
],
"temperature": 0.7
}
```
**Example Response**
```json
{
"id": "gen-1234567890abcdef",
"object": "chat.completion",
"created": 1699123456,
"model": "openai/gpt-4-turbo-preview",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Hello! I am an AI assistant powered by OpenRouter. I can help answer questions, assist with creative tasks, engage in conversations, and more. How can I assist you today?"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 12,
"completion_tokens": 35,
"total_tokens": 47
}
}
```
### Using Auto Protocol Compatibility
The plugin now supports automatic protocol detection, capable of handling both OpenAI and Claude protocol format requests simultaneously.