Files
Aether/apps/aether-gateway/src/control/route/ai.rs
T

159 lines
4.6 KiB
Rust
Raw Normal View History

use super::{
classified, classified_with_request_auth_channel, is_claude_cli_request, is_gemini_cli_request,
is_gemini_models_route, is_gemini_operation_route, ClassifiedRoute,
};
pub(super) fn classify_ai_public_route(
method: &http::Method,
normalized_path: &str,
headers: &http::HeaderMap,
) -> Option<ClassifiedRoute> {
if method == http::Method::POST && normalized_path == "/v1/chat/completions" {
Some(classified(
"ai_public",
"openai",
"chat",
"openai:chat",
true,
))
2026-05-03 17:32:41 +08:00
} else if method == http::Method::POST && normalized_path == "/v1/embeddings" {
Some(classified(
"ai_public",
"openai",
"embedding",
"openai:embedding",
true,
))
} else if method == http::Method::POST && normalized_path == "/v1/rerank" {
Some(classified(
"ai_public",
"openai",
"rerank",
"openai:rerank",
true,
))
} else if method == http::Method::POST
&& matches!(normalized_path, "/v1/responses" | "/v1/responses/compact")
{
if normalized_path.ends_with("/compact") {
Some(classified(
"ai_public",
"openai",
"responses:compact",
"openai:responses:compact",
true,
))
} else {
Some(classified(
"ai_public",
"openai",
"responses",
"openai:responses",
true,
))
}
} else if method == http::Method::POST
&& matches!(
normalized_path,
2026-05-16 19:23:23 +08:00
"/v1/images/generations" | "/v1/images/edits"
)
{
Some(classified(
"ai_public",
"openai",
"image",
"openai:image",
true,
))
} else if method == http::Method::POST && normalized_path == "/v1/messages/count_tokens" {
Some(classified(
"ai_public",
"claude",
"count_tokens",
2026-04-29 09:25:19 +08:00
"claude:messages",
false,
))
} else if method == http::Method::POST && normalized_path == "/v1/messages" {
let request_auth_channel = if is_claude_cli_request(headers) {
"bearer_like"
} else {
"api_key"
2026-04-29 09:25:19 +08:00
};
Some(classified_with_request_auth_channel(
2026-04-29 09:25:19 +08:00
"ai_public",
"claude",
"messages",
request_auth_channel,
2026-04-29 09:25:19 +08:00
"claude:messages",
true,
))
} else if normalized_path.starts_with("/v1/videos") {
Some(classified(
"ai_public",
"openai",
"video",
"openai:video",
true,
))
} else if is_gemini_models_route(normalized_path) {
if normalized_path.ends_with(":predictLongRunning") {
Some(classified(
"ai_public",
"gemini",
"video",
"gemini:video",
true,
))
} else if normalized_path.ends_with(":embedContent")
|| normalized_path.ends_with(":batchEmbedContents")
{
Some(classified_with_request_auth_channel(
"ai_public",
"gemini",
"embedding",
"api_key",
"gemini:embedding",
true,
))
} else if is_gemini_cli_request(headers) {
Some(classified_with_request_auth_channel(
2026-04-29 09:25:19 +08:00
"ai_public",
"gemini",
"generate_content",
"bearer_like",
2026-04-29 09:25:19 +08:00
"gemini:generate_content",
true,
))
} else {
Some(classified_with_request_auth_channel(
"ai_public",
"gemini",
2026-04-29 09:25:19 +08:00
"generate_content",
"api_key",
2026-04-29 09:25:19 +08:00
"gemini:generate_content",
true,
))
}
} else if is_gemini_operation_route(normalized_path) {
Some(classified(
"ai_public",
"gemini",
"video",
"gemini:video",
true,
))
} else if (method == http::Method::POST && normalized_path == "/upload/v1beta/files")
|| normalized_path.starts_with("/v1beta/files")
{
Some(classified(
"ai_public",
"gemini",
"files",
2026-04-29 09:25:19 +08:00
"gemini:files",
true,
))
} else {
None
}
}