Skip to content

Fix Vertex channel global region format for claude models - #1253

Merged
Calcium-Ion merged 1 commit into
QuantumNous:mainfrom
TopickAI:main
Jun 19, 2025
Merged

Fix Vertex channel global region format for claude models#1253
Calcium-Ion merged 1 commit into
QuantumNous:mainfrom
TopickAI:main

Conversation

@sgyy

@sgyy sgyy commented Jun 18, 2025

Copy link
Copy Markdown

Fix Vertex channel global region format for claude models

Summary by CodeRabbit

  • Bug Fixes
    • Resolved an issue with Claude model requests where selecting the "global" region now correctly uses the appropriate global endpoint, ensuring proper connectivity.

@coderabbitai

coderabbitai Bot commented Jun 18, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

The update modifies the URL construction logic in the GetRequestURL method of the Adaptor struct for Claude request mode. It introduces a conditional to use a different base URL when the region is set to "global", omitting the region subdomain in that case, while retaining the previous format for other regions.

Changes

File(s) Change Summary
relay/channel/vertex/adaptor.go Adjusted Claude request URL logic to handle "global" region as a special case, using a different base URL format.

Poem

A clever hop in code today,
For Claude requests that come our way—
If "global" is the region's name,
The URL will not be the same!
With branches neat and logic sound,
Our endpoints now are global-bound.
🐇🌍

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@coderabbitai coderabbitai Bot left a comment

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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
relay/channel/vertex/adaptor.go (1)

126-141: Factor out duplicate URL-building logic
The global / non-global split is now implemented three times (Gemini, new Claude branch, and previously elsewhere). Repeating the fmt.Sprintf blocks makes future maintenance error-prone.

Consider extracting a small helper:

+func buildVertexURL(region, projectID, publisher, model, suffix string) string {
+    if region == "global" {
+        return fmt.Sprintf("https://aiplatform.googleapis.com/v1/projects/%s/locations/global/publishers/%s/models/%s:%s",
+            projectID, publisher, model, suffix)
+    }
+    return fmt.Sprintf("https://%s-aiplatform.googleapis.com/v1/projects/%s/locations/%s/publishers/%s/models/%s:%s",
+        region, projectID, region, publisher, model, suffix)
+}

Then call:

return buildVertexURL(region, adc.ProjectID, "anthropic", model, suffix), nil

Reduces duplication and keeps all publisher-specific URLs consistent.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0b9b21e and 4447e51.

📒 Files selected for processing (1)
  • relay/channel/vertex/adaptor.go (1 hunks)
🔇 Additional comments (1)
relay/channel/vertex/adaptor.go (1)

126-132: Correct handling of the global endpoint – looks good
The conditional branch introduces the correct base URL for the global region, matching Google’s documented pattern (https://aiplatform.googleapis.com/...). Implementation aligns with the earlier Gemini logic.

Comment on lines +134 to +141
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

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.

@Calcium-Ion
Calcium-Ion merged commit 2fdb2be into QuantumNous:main Jun 19, 2025
x22x22 pushed a commit to x22x22/new-api that referenced this pull request Apr 24, 2026
Fix Vertex channel global region format for claude models
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants