mirror of
https://github.com/alibaba/higress.git
synced 2026-06-01 08:37:26 +08:00
feat(ai-proxy): add OpenRouter provider support (#2823)
This commit is contained in:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user