Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
phsl
/
new-api
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Unverified
Commit
987b7ecd
authored
Apr 30, 2026
by
yyhhyyyyyy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix(vertex): honor custom base_url as gateway prefix
parent
ed7f8399
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
115 additions
and
76 deletions
+115
-76
relay/channel/task/vertex/adaptor.go
+20
-28
relay/channel/vertex/adaptor.go
+9
-48
relay/channel/vertex/url_builder.go
+86
-0
No files found.
relay/channel/task/vertex/adaptor.go
View file @
987b7ecd
...
...
@@ -95,20 +95,7 @@ func (a *TaskAdaptor) BuildRequestURL(info *relaycommon.RelayInfo) (string, erro
if
strings
.
TrimSpace
(
region
)
==
""
{
region
=
"global"
}
if
region
==
"global"
{
return
fmt
.
Sprintf
(
"https://aiplatform.googleapis.com/v1/projects/%s/locations/global/publishers/google/models/%s:predictLongRunning"
,
adc
.
ProjectID
,
modelName
,
),
nil
}
return
fmt
.
Sprintf
(
"https://%s-aiplatform.googleapis.com/v1/projects/%s/locations/%s/publishers/google/models/%s:predictLongRunning"
,
region
,
adc
.
ProjectID
,
region
,
modelName
,
),
nil
return
vertexcore
.
BuildGoogleModelURL
(
a
.
baseURL
,
vertexcore
.
DefaultAPIVersion
,
adc
.
ProjectID
,
region
,
modelName
,
"predictLongRunning"
),
nil
}
// BuildRequestHeader sets required headers.
...
...
@@ -238,6 +225,22 @@ func (a *TaskAdaptor) GetModelList() []string {
}
func
(
a
*
TaskAdaptor
)
GetChannelName
()
string
{
return
"vertex"
}
func
buildFetchOperationURL
(
baseURL
,
upstreamName
string
)
(
string
,
error
)
{
region
:=
extractRegionFromOperationName
(
upstreamName
)
if
region
==
""
{
region
=
"us-central1"
}
project
:=
extractProjectFromOperationName
(
upstreamName
)
modelName
:=
extractModelFromOperationName
(
upstreamName
)
if
strings
.
TrimSpace
(
modelName
)
==
""
{
return
""
,
fmt
.
Errorf
(
"cannot extract model from operation name"
)
}
if
strings
.
TrimSpace
(
project
)
==
""
{
return
""
,
fmt
.
Errorf
(
"cannot extract project from operation name"
)
}
return
vertexcore
.
BuildGoogleModelURL
(
baseURL
,
vertexcore
.
DefaultAPIVersion
,
project
,
region
,
modelName
,
"fetchPredictOperation"
),
nil
}
// FetchTask fetch task status
func
(
a
*
TaskAdaptor
)
FetchTask
(
baseUrl
,
key
string
,
body
map
[
string
]
any
,
proxy
string
)
(
*
http
.
Response
,
error
)
{
taskID
,
ok
:=
body
[
"task_id"
]
.
(
string
)
...
...
@@ -248,20 +251,9 @@ func (a *TaskAdaptor) FetchTask(baseUrl, key string, body map[string]any, proxy
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"decode task_id failed: %w"
,
err
)
}
region
:=
extractRegionFromOperationName
(
upstreamName
)
if
region
==
""
{
region
=
"us-central1"
}
project
:=
extractProjectFromOperationName
(
upstreamName
)
modelName
:=
extractModelFromOperationName
(
upstreamName
)
if
project
==
""
||
modelName
==
""
{
return
nil
,
fmt
.
Errorf
(
"cannot extract project/model from operation name"
)
}
var
url
string
if
region
==
"global"
{
url
=
fmt
.
Sprintf
(
"https://aiplatform.googleapis.com/v1/projects/%s/locations/global/publishers/google/models/%s:fetchPredictOperation"
,
project
,
modelName
)
}
else
{
url
=
fmt
.
Sprintf
(
"https://%s-aiplatform.googleapis.com/v1/projects/%s/locations/%s/publishers/google/models/%s:fetchPredictOperation"
,
region
,
project
,
region
,
modelName
)
url
,
err
:=
buildFetchOperationURL
(
baseUrl
,
upstreamName
)
if
err
!=
nil
{
return
nil
,
err
}
payload
:=
fetchOperationPayload
{
OperationName
:
upstreamName
}
data
,
err
:=
common
.
Marshal
(
payload
)
...
...
relay/channel/vertex/adaptor.go
View file @
987b7ecd
...
...
@@ -133,47 +133,11 @@ func (a *Adaptor) getRequestUrl(info *relaycommon.RelayInfo, modelName, suffix s
a
.
AccountCredentials
=
*
adc
if
a
.
RequestMode
==
RequestModeGemini
{
if
region
==
"global"
{
return
fmt
.
Sprintf
(
"https://aiplatform.googleapis.com/v1/projects/%s/locations/global/publishers/google/models/%s:%s"
,
adc
.
ProjectID
,
modelName
,
suffix
,
),
nil
}
else
{
return
fmt
.
Sprintf
(
"https://%s-aiplatform.googleapis.com/v1/projects/%s/locations/%s/publishers/google/models/%s:%s"
,
region
,
adc
.
ProjectID
,
region
,
modelName
,
suffix
,
),
nil
}
return
BuildGoogleModelURL
(
info
.
ChannelBaseUrl
,
DefaultAPIVersion
,
adc
.
ProjectID
,
region
,
modelName
,
suffix
),
nil
}
else
if
a
.
RequestMode
==
RequestModeClaude
{
if
region
==
"global"
{
return
fmt
.
Sprintf
(
"https://aiplatform.googleapis.com/v1/projects/%s/locations/global/publishers/anthropic/models/%s:%s"
,
adc
.
ProjectID
,
modelName
,
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
,
modelName
,
suffix
,
),
nil
}
return
BuildAnthropicModelURL
(
info
.
ChannelBaseUrl
,
DefaultAPIVersion
,
adc
.
ProjectID
,
region
,
modelName
,
suffix
),
nil
}
else
if
a
.
RequestMode
==
RequestModeOpenSource
{
return
fmt
.
Sprintf
(
"https://aiplatform.googleapis.com/v1beta1/projects/%s/locations/%s/endpoints/openapi/chat/completions"
,
adc
.
ProjectID
,
region
,
),
nil
return
BuildOpenSourceChatCompletionsURL
(
info
.
ChannelBaseUrl
,
adc
.
ProjectID
,
region
),
nil
}
}
else
{
var
keyPrefix
string
...
...
@@ -182,20 +146,17 @@ func (a *Adaptor) getRequestUrl(info *relaycommon.RelayInfo, modelName, suffix s
}
else
{
keyPrefix
=
"?"
}
if
region
==
"global"
{
if
a
.
RequestMode
==
RequestModeGemini
{
return
fmt
.
Sprintf
(
"https://aiplatform.googleapis.com/v1/publishers/google/models/%s:%s%skey=%s"
,
modelName
,
suffix
,
"%s%skey=%s"
,
BuildGoogleModelURL
(
info
.
ChannelBaseUrl
,
DefaultAPIVersion
,
""
,
region
,
modelName
,
suffix
),
keyPrefix
,
info
.
ApiKey
,
),
nil
}
else
{
}
else
if
a
.
RequestMode
==
RequestModeClaude
{
return
fmt
.
Sprintf
(
"https://%s-aiplatform.googleapis.com/v1/publishers/google/models/%s:%s%skey=%s"
,
region
,
modelName
,
suffix
,
"%s%skey=%s"
,
BuildAnthropicModelURL
(
info
.
ChannelBaseUrl
,
DefaultAPIVersion
,
""
,
region
,
modelName
,
suffix
),
keyPrefix
,
info
.
ApiKey
,
),
nil
...
...
relay/channel/vertex/url_builder.go
0 → 100644
View file @
987b7ecd
package
vertex
import
(
"fmt"
"strings"
)
const
(
DefaultAPIVersion
=
"v1"
OpenSourceAPIVersion
=
"v1beta1"
PublisherGoogle
=
"google"
PublisherAnthropic
=
"anthropic"
)
func
normalizeVertexBaseURL
(
baseURL
string
)
string
{
return
strings
.
TrimRight
(
strings
.
TrimSpace
(
baseURL
),
"/"
)
}
func
normalizeVertexRegion
(
region
string
)
string
{
region
=
strings
.
TrimSpace
(
region
)
if
region
==
""
{
return
"global"
}
return
region
}
func
appendVertexAPIVersion
(
baseURL
,
version
string
)
string
{
version
=
strings
.
Trim
(
strings
.
TrimSpace
(
version
),
"/"
)
if
version
==
""
{
return
baseURL
}
if
strings
.
HasSuffix
(
baseURL
,
"/"
+
version
)
{
return
baseURL
}
return
baseURL
+
"/"
+
version
}
func
BuildAPIBaseURL
(
baseURL
,
version
,
projectID
,
region
string
)
string
{
if
normalized
:=
normalizeVertexBaseURL
(
baseURL
);
normalized
!=
""
{
normalized
=
appendVertexAPIVersion
(
normalized
,
version
)
region
=
normalizeVertexRegion
(
region
)
if
strings
.
TrimSpace
(
projectID
)
!=
""
{
normalized
=
fmt
.
Sprintf
(
"%s/projects/%s/locations/%s"
,
normalized
,
projectID
,
region
)
}
return
normalized
}
region
=
normalizeVertexRegion
(
region
)
if
strings
.
TrimSpace
(
projectID
)
==
""
{
if
region
==
"global"
{
return
fmt
.
Sprintf
(
"https://aiplatform.googleapis.com/%s"
,
version
)
}
return
fmt
.
Sprintf
(
"https://%s-aiplatform.googleapis.com/%s"
,
region
,
version
)
}
if
region
==
"global"
{
return
fmt
.
Sprintf
(
"https://aiplatform.googleapis.com/%s/projects/%s/locations/global"
,
version
,
projectID
)
}
return
fmt
.
Sprintf
(
"https://%s-aiplatform.googleapis.com/%s/projects/%s/locations/%s"
,
region
,
version
,
projectID
,
region
)
}
func
BuildPublisherModelURL
(
baseURL
,
version
,
projectID
,
region
,
publisher
,
modelName
,
action
string
)
string
{
return
fmt
.
Sprintf
(
"%s/publishers/%s/models/%s:%s"
,
BuildAPIBaseURL
(
baseURL
,
version
,
projectID
,
region
),
publisher
,
modelName
,
action
,
)
}
func
BuildGoogleModelURL
(
baseURL
,
version
,
projectID
,
region
,
modelName
,
action
string
)
string
{
return
BuildPublisherModelURL
(
baseURL
,
version
,
projectID
,
region
,
PublisherGoogle
,
modelName
,
action
)
}
func
BuildAnthropicModelURL
(
baseURL
,
version
,
projectID
,
region
,
modelName
,
action
string
)
string
{
return
BuildPublisherModelURL
(
baseURL
,
version
,
projectID
,
region
,
PublisherAnthropic
,
modelName
,
action
)
}
func
BuildOpenSourceChatCompletionsURL
(
baseURL
,
projectID
,
region
string
)
string
{
return
fmt
.
Sprintf
(
"%s/endpoints/openapi/chat/completions"
,
BuildAPIBaseURL
(
baseURL
,
OpenSourceAPIVersion
,
projectID
,
region
),
)
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment