@@ -203,10 +203,19 @@ func (provider *VertexProvider) ChatCompletion(ctx context.Context, key schemas.
203203 return nil , newConfigurationError ("region is not set in key config" , schemas .Vertex )
204204 }
205205
206- url := fmt .Sprintf ("https://%s-aiplatform.googleapis.com/v1beta1/projects/%s/locations/%s/endpoints/openapi/chat/completions" , region , projectID , region )
207-
206+ var url string
208207 if strings .Contains (request .Model , "claude" ) {
209- url = fmt .Sprintf ("https://%s-aiplatform.googleapis.com/v1/projects/%s/locations/%s/publishers/anthropic/models/%s:rawPredict" , region , projectID , region , request .Model )
208+ if region == "global" {
209+ url = fmt .Sprintf ("https://aiplatform.googleapis.com/v1/projects/%s/locations/global/publishers/anthropic/models/%s:rawPredict" , projectID , request .Model )
210+ } else {
211+ url = fmt .Sprintf ("https://%s-aiplatform.googleapis.com/v1/projects/%s/locations/%s/publishers/anthropic/models/%s:rawPredict" , region , projectID , region , request .Model )
212+ }
213+ } else {
214+ if region == "global" {
215+ url = fmt .Sprintf ("https://aiplatform.googleapis.com/v1beta1/projects/%s/locations/global/endpoints/openapi/chat/completions" , projectID )
216+ } else {
217+ url = fmt .Sprintf ("https://%s-aiplatform.googleapis.com/v1beta1/projects/%s/locations/%s/endpoints/openapi/chat/completions" , region , projectID , region )
218+ }
210219 }
211220
212221 // Create request
@@ -286,12 +295,19 @@ func (provider *VertexProvider) ChatCompletion(ctx context.Context, key schemas.
286295 }
287296
288297 var openAIErr schemas.BifrostError
289- var vertexErr []VertexError
290298
299+ var vertexErr []VertexError
291300 if err := sonic .Unmarshal (body , & openAIErr ); err != nil {
292301 // Try Vertex error format if OpenAI format fails
293302 if err := sonic .Unmarshal (body , & vertexErr ); err != nil {
294- return nil , newBifrostOperationError (schemas .ErrProviderResponseUnmarshal , err , schemas .Vertex )
303+
304+ //try with single Vertex error format
305+ var vertexErr VertexError
306+ if err := sonic .Unmarshal (body , & vertexErr ); err != nil {
307+ return nil , newBifrostOperationError (schemas .ErrProviderResponseUnmarshal , err , schemas .Vertex )
308+ }
309+
310+ return nil , newProviderAPIError (vertexErr .Error .Message , nil , resp .StatusCode , schemas .Vertex , nil , nil )
295311 }
296312
297313 if len (vertexErr ) > 0 {
@@ -395,7 +411,12 @@ func (provider *VertexProvider) ChatCompletionStream(ctx context.Context, postHo
395411 delete (requestBody , "model" )
396412 delete (requestBody , "region" )
397413
398- url := fmt .Sprintf ("https://%s-aiplatform.googleapis.com/v1/projects/%s/locations/%s/publishers/anthropic/models/%s:streamRawPredict" , region , projectID , region , request .Model )
414+ var url string
415+ if region == "global" {
416+ url = fmt .Sprintf ("https://aiplatform.googleapis.com/v1/projects/%s/locations/global/publishers/anthropic/models/%s:streamRawPredict" , projectID , request .Model )
417+ } else {
418+ url = fmt .Sprintf ("https://%s-aiplatform.googleapis.com/v1/projects/%s/locations/%s/publishers/anthropic/models/%s:streamRawPredict" , region , projectID , region , request .Model )
419+ }
399420
400421 // Prepare headers for Vertex Anthropic
401422 headers := map [string ]string {
@@ -418,7 +439,12 @@ func (provider *VertexProvider) ChatCompletionStream(ctx context.Context, postHo
418439 provider .logger ,
419440 )
420441 } else {
421- url := fmt .Sprintf ("https://%s-aiplatform.googleapis.com/v1beta1/projects/%s/locations/%s/endpoints/openapi/chat/completions" , region , projectID , region )
442+ var url string
443+ if region == "global" {
444+ url = fmt .Sprintf ("https://aiplatform.googleapis.com/v1beta1/projects/%s/locations/global/endpoints/openapi/chat/completions" , projectID )
445+ } else {
446+ url = fmt .Sprintf ("https://%s-aiplatform.googleapis.com/v1beta1/projects/%s/locations/%s/endpoints/openapi/chat/completions" , region , projectID , region )
447+ }
422448 authHeader := map [string ]string {}
423449 if key .Value != "" {
424450 authHeader ["Authorization" ] = "Bearer " + key .Value
0 commit comments