feat: add OpenRouter as a first-class LLM provider (fixes #612)

This commit is contained in:
octo-patch 2026-04-11 13:47:30 +08:00
parent 128059e7c1
commit f4571702e2
4 changed files with 13 additions and 2 deletions

View file

@ -14,6 +14,7 @@ SUPPORTED_PROVIDERS_WITH_BASE_URL = [
"qwen",
"amazon_bedrock",
"plano",
"openrouter",
]
SUPPORTED_PROVIDERS_WITHOUT_BASE_URL = [

View file

@ -190,6 +190,7 @@ properties:
- openai
- xiaomi
- gemini
- openrouter
routing_preferences:
type: array
items:
@ -238,6 +239,7 @@ properties:
- openai
- xiaomi
- gemini
- openrouter
routing_preferences:
type: array
items:

View file

@ -370,6 +370,8 @@ pub enum LlmProviderType {
AmazonBedrock,
#[serde(rename = "plano")]
Plano,
#[serde(rename = "openrouter")]
OpenRouter,
}
impl Display for LlmProviderType {
@ -391,6 +393,7 @@ impl Display for LlmProviderType {
LlmProviderType::Qwen => write!(f, "qwen"),
LlmProviderType::AmazonBedrock => write!(f, "amazon_bedrock"),
LlmProviderType::Plano => write!(f, "plano"),
LlmProviderType::OpenRouter => write!(f, "openrouter"),
}
}
}

View file

@ -44,6 +44,7 @@ pub enum ProviderId {
Zhipu,
Qwen,
AmazonBedrock,
OpenRouter,
}
impl TryFrom<&str> for ProviderId {
@ -71,6 +72,7 @@ impl TryFrom<&str> for ProviderId {
"qwen" => Ok(ProviderId::Qwen),
"amazon_bedrock" => Ok(ProviderId::AmazonBedrock),
"amazon" => Ok(ProviderId::AmazonBedrock), // alias
"openrouter" => Ok(ProviderId::OpenRouter),
_ => Err(format!("Unknown provider: {}", value)),
}
}
@ -148,7 +150,8 @@ impl ProviderId {
| ProviderId::Ollama
| ProviderId::Moonshotai
| ProviderId::Zhipu
| ProviderId::Qwen,
| ProviderId::Qwen
| ProviderId::OpenRouter,
SupportedAPIsFromClient::AnthropicMessagesAPI(_),
) => SupportedUpstreamAPIs::OpenAIChatCompletions(OpenAIApi::ChatCompletions),
@ -167,7 +170,8 @@ impl ProviderId {
| ProviderId::Ollama
| ProviderId::Moonshotai
| ProviderId::Zhipu
| ProviderId::Qwen,
| ProviderId::Qwen
| ProviderId::OpenRouter,
SupportedAPIsFromClient::OpenAIChatCompletions(_),
) => SupportedUpstreamAPIs::OpenAIChatCompletions(OpenAIApi::ChatCompletions),
@ -234,6 +238,7 @@ impl Display for ProviderId {
ProviderId::Zhipu => write!(f, "zhipu"),
ProviderId::Qwen => write!(f, "qwen"),
ProviderId::AmazonBedrock => write!(f, "amazon_bedrock"),
ProviderId::OpenRouter => write!(f, "openrouter"),
}
}
}