fix: open source models use v1 endpoints instead of v1beta1 - #2451
fix: open source models use v1 endpoints instead of v1beta1#2451seefs001 wants to merge 4832 commits into
Conversation
…ps directly and add GetUserGroupRatio function
fix: correct topUp link
Gemini渠道支持veo视频生成
* feat: add ali wan video * refactor: use same UnmarshalBodyReusable * feat: enhance request body metadata * feat: opt wan convertToOpenAIVideo * feat: add wan support other param via json metadata * refactor: remove unused code * fix ali --------- Co-authored-by: feitianbubu <feitianbubu@qq.com>
* feat: claude 1h cache * feat: claude 1h cache * fix price
修复即梦v30-pro视频生成失败问题
…d size validation
feat: EditTokenModal 中针对用户创建的 token 默认无限额度
feat: add environment variable switch for critical rate limit
fix: trim suffix p for jimeng image model
fix: health check
feat(token): add cross-group retry option for token processing
fix: correct sender format issues fix #1347
feat(adaptor): add '-xhigh' suffix to reasoning effort options
fix(channel_select): adjust priority retry logic for cross-group
…or channel selection
… and streaming support
feat: support gpt tts series model quota calculate
…in GetAudioDuration" This reverts commit e293be0138316e5c33313552a9038508ed4dbf34.
feat(auth): enhance IP restriction handling with CIDR support
WalkthroughA new request mode Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Possibly related PRs
Poem
Pre-merge checks and finishing touches✅ Passed checks (5 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
relay/channel/vertex/adaptor.go (1)
352-356: Consider combining switch cases to reduce duplication.
RequestModeLlamaandRequestModeMaashave identical handlers in both streaming and non-streaming paths.Apply this diff to consolidate:
- case RequestModeLlama: - return openai.OaiStreamHandler(c, info, resp) - case RequestModeMaas: + case RequestModeLlama, RequestModeMaas: return openai.OaiStreamHandler(c, info, resp)And similarly for the non-streaming case (lines 370-373):
- case RequestModeLlama: - return openai.OpenaiHandler(c, info, resp) - case RequestModeMaas: + case RequestModeLlama, RequestModeMaas: return openai.OpenaiHandler(c, info, resp)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
relay/channel/vertex/adaptor.go(7 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-08-05T17:14:17.246Z
Learnt from: neotf
Repo: QuantumNous/new-api PR: 1511
File: setting/ratio_setting/model_ratio.go:118-123
Timestamp: 2025-08-05T17:14:17.246Z
Learning: Claude models handle "-thinking" variants differently from Gemini models. For Claude models, only the base model (without "-thinking") gets an entry in defaultModelRatio map. The "-thinking" variants rely on the Claude relay handler stripping the suffix using strings.TrimSuffix(textRequest.Model, "-thinking") before looking up the ratio, so they automatically use the base model's ratio.
Applied to files:
relay/channel/vertex/adaptor.go
🧬 Code graph analysis (1)
relay/channel/vertex/adaptor.go (1)
relay/channel/openai/relay-openai.go (2)
OaiStreamHandler(106-194)OpenaiHandler(196-294)
🔇 Additional comments (4)
relay/channel/vertex/adaptor.go (4)
26-31: LGTM!The new
RequestModeMaasconstant follows the existing naming and numbering convention.
79-89: LGTM!The detection logic correctly identifies MaaS models using the
-maassuffix pattern, and the ordering ensures no conflicts with existing model types.
219-221: LGTM!MaaS correctly shares the same URL construction path as Llama since both use the OpenAI-compatible endpoints API.
317-319: LGTM!Correctly passes through the OpenAI request without conversion for MaaS endpoints.
| } else if a.RequestMode == RequestModeMaas { | ||
| return fmt.Sprintf( | ||
| "https://%s-aiplatform.googleapis.com/v1/projects/%s/locations/%s/endpoints/openapi/chat/completions", | ||
| region, | ||
| adc.ProjectID, | ||
| region, | ||
| ), nil |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
find . -name "adaptor.go" -o -name "*adaptor*" 2>/dev/null | head -20Repository: QuantumNous/new-api
Length of output: 739
🏁 Script executed:
find . -path "*vertex*" -name "*.go" 2>/dev/null | head -20Repository: QuantumNous/new-api
Length of output: 282
🏁 Script executed:
cat -n ./relay/channel/vertex/adaptor.go | head -160Repository: QuantumNous/new-api
Length of output: 6346
🏁 Script executed:
cat -n ./relay/channel/vertex/adaptor.go | sed -n '100,150p'Repository: QuantumNous/new-api
Length of output: 1880
🏁 Script executed:
cat -n ./relay/channel/vertex/adaptor.go | sed -n '136,150p'Repository: QuantumNous/new-api
Length of output: 637
Missing global region handling for MaaS models.
The code at lines 143-150 does not handle the global region case. When region == "global", it incorrectly produces https://global-aiplatform.googleapis.com/v1/... instead of the correct https://aiplatform.googleapis.com/v1/... (without the region prefix).
The global endpoint for MaaS uses the format https://aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/global/endpoints/..., which requires omitting the region prefix. Compare with the correct implementations for Gemini (lines 100-117) and Claude (lines 118-135), which both check if region == "global" and construct URLs without the region prefix.
Apply this diff to fix:
} else if a.RequestMode == RequestModeMaas {
+ if region == "global" {
+ return fmt.Sprintf(
+ "https://aiplatform.googleapis.com/v1/projects/%s/locations/global/endpoints/openapi/chat/completions",
+ adc.ProjectID,
+ ), nil
+ }
return fmt.Sprintf(
"https://%s-aiplatform.googleapis.com/v1/projects/%s/locations/%s/endpoints/openapi/chat/completions",
region,
adc.ProjectID,
region,
), nil
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| } else if a.RequestMode == RequestModeMaas { | |
| return fmt.Sprintf( | |
| "https://%s-aiplatform.googleapis.com/v1/projects/%s/locations/%s/endpoints/openapi/chat/completions", | |
| region, | |
| adc.ProjectID, | |
| region, | |
| ), nil | |
| } else if a.RequestMode == RequestModeMaas { | |
| if region == "global" { | |
| return fmt.Sprintf( | |
| "https://aiplatform.googleapis.com/v1/projects/%s/locations/global/endpoints/openapi/chat/completions", | |
| adc.ProjectID, | |
| ), nil | |
| } | |
| return fmt.Sprintf( | |
| "https://%s-aiplatform.googleapis.com/v1/projects/%s/locations/%s/endpoints/openapi/chat/completions", | |
| region, | |
| adc.ProjectID, | |
| region, | |
| ), nil |
🤖 Prompt for AI Agents
In relay/channel/vertex/adaptor.go around lines 143 to 149, the MaaS URL
construction always prefixes the host with the region (producing
https://global-aiplatform.googleapis.com/...), so add a conditional like the
Gemini/Claude paths: if region == "global" build the URL using host
"aiplatform.googleapis.com" (no region prefix) and locations/global in the path;
otherwise keep the existing "%s-aiplatform.googleapis.com" host with the region
inserted. Ensure the returned path uses
projects/{project}/locations/{region}/endpoints/... (or locations/global when
region == "global") and return nil error as before.
fix #2404
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.