diff --git a/controller/video_proxy_gemini.go b/controller/video_proxy_gemini.go index a9f953189..4352a9616 100644 --- a/controller/video_proxy_gemini.go +++ b/controller/video_proxy_gemini.go @@ -166,7 +166,12 @@ func getVertexVideoURL(channel *model.Channel, task *model.Task) (string, error) return "", fmt.Errorf("vertex task adaptor not found") } - resp, err := adaptor.FetchTask(baseURL, channel.Key, map[string]any{ + key := getVertexTaskKey(channel, task) + if key == "" { + return "", fmt.Errorf("vertex key not available for task") + } + + resp, err := adaptor.FetchTask(baseURL, key, map[string]any{ "task_id": task.GetUpstreamTaskID(), "action": task.Action, }, channel.GetSetting().Proxy) @@ -193,6 +198,25 @@ func getVertexVideoURL(channel *model.Channel, task *model.Task) (string, error) return "", fmt.Errorf("vertex video url not found") } +func getVertexTaskKey(channel *model.Channel, task *model.Task) string { + if task != nil { + if key := strings.TrimSpace(task.PrivateData.Key); key != "" { + return key + } + } + if channel == nil { + return "" + } + keys := channel.GetKeys() + for _, key := range keys { + key = strings.TrimSpace(key) + if key != "" { + return key + } + } + return strings.TrimSpace(channel.Key) +} + func extractVertexVideoURLFromTaskData(task *model.Task) string { if task == nil || len(task.Data) == 0 { return "" diff --git a/model/task.go b/model/task.go index 984445083..2fbd3fd66 100644 --- a/model/task.go +++ b/model/task.go @@ -173,7 +173,8 @@ func InitTask(platform constant.TaskPlatform, relayInfo *commonRelay.RelayInfo) properties := Properties{} privateData := TaskPrivateData{} if relayInfo != nil && relayInfo.ChannelMeta != nil { - if relayInfo.ChannelMeta.ChannelType == constant.ChannelTypeGemini { + if relayInfo.ChannelMeta.ChannelType == constant.ChannelTypeGemini || + relayInfo.ChannelMeta.ChannelType == constant.ChannelTypeVertexAi { privateData.Key = relayInfo.ChannelMeta.ApiKey } if relayInfo.UpstreamModelName != "" {