Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions relay/channel/vertex/adaptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,23 @@ func (a *Adaptor) GetRequestURL(info *relaycommon.RelayInfo) (string, error) {
if v, ok := claudeModelMap[info.UpstreamModelName]; ok {
model = v
}
return fmt.Sprintf(
"https://%s-aiplatform.googleapis.com/v1/projects/%s/locations/%s/publishers/anthropic/models/%s:%s",
region,
adc.ProjectID,
region,
model,
suffix,
), nil
if region == "global" {
return fmt.Sprintf(
"https://aiplatform.googleapis.com/v1/projects/%s/locations/global/publishers/anthropic/models/%s:%s",
adc.ProjectID,
model,
suffix,
), nil
} else {
return fmt.Sprintf(
"https://%s-aiplatform.googleapis.com/v1/projects/%s/locations/%s/publishers/anthropic/models/%s:%s",
region,
adc.ProjectID,
region,
model,
suffix,
), nil
Comment on lines +134 to +141

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Guard against empty region values
GetModelRegion can theoretically return an empty string for unknown models. In that case the non-global branch would render https://-aiplatform.googleapis.com/..., which is invalid and will 4xx.

Add a sanity check right after retrieving region, e.g.:

region := GetModelRegion(info.ApiVersion, info.OriginModelName)
+if region == "" {
+    return "", fmt.Errorf("unable to determine region for model %s", info.OriginModelName)
+}

Prevents malformed hosts and surfaces configuration problems early.

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In relay/channel/vertex/adaptor.go around lines 134 to 141, add a check
immediately after retrieving the region value from GetModelRegion to verify it
is not empty. If the region is empty, return an error indicating an invalid or
unknown region instead of proceeding to construct the URL. This prevents
generating malformed URLs like "https://-aiplatform.googleapis.com/..." and
surfaces configuration issues early.

}
} else if a.RequestMode == RequestModeLlama {
return fmt.Sprintf(
"https://%s-aiplatform.googleapis.com/v1beta1/projects/%s/locations/%s/endpoints/openapi/chat/completions",
Expand Down