@@ -809,4 +809,95 @@ describe("VertexHandler", () => {
809809 )
810810 } )
811811 } )
812+
813+ describe ( "custom base URL" , ( ) => {
814+ it ( "should use custom base URL when provided with JSON credentials" , ( ) => {
815+ const customBaseUrl = "https://custom-vertex-endpoint.example.com"
816+
817+ const handler = new AnthropicVertexHandler ( {
818+ apiModelId : "claude-3-5-sonnet-v2@20241022" ,
819+ vertexProjectId : "test-project" ,
820+ vertexRegion : "us-central1" ,
821+ vertexBaseUrl : customBaseUrl ,
822+ vertexJsonCredentials : JSON . stringify ( {
823+ type : "service_account" ,
824+ project_id : "test-project" ,
825+ private_key_id : "key-id" ,
826+ private_key : "-----BEGIN PRIVATE KEY-----\ntest\n-----END PRIVATE KEY-----\n" ,
827+ client_email :
"[email protected] " , 828+ client_id : "123456789" ,
829+ auth_uri : "https://accounts.google.com/o/oauth2/auth" ,
830+ token_uri : "https://oauth2.googleapis.com/token" ,
831+ auth_provider_x509_cert_url : "https://www.googleapis.com/oauth2/v1/certs" ,
832+ client_x509_cert_url :
833+ "https://www.googleapis.com/robot/v1/metadata/x509/test%40test.iam.gserviceaccount.com" ,
834+ } ) ,
835+ } )
836+
837+ // Verify that AnthropicVertex was called with baseURL
838+ expect ( AnthropicVertex ) . toHaveBeenCalledWith (
839+ expect . objectContaining ( {
840+ baseURL : customBaseUrl ,
841+ projectId : "test-project" ,
842+ region : "us-central1" ,
843+ } ) ,
844+ )
845+ } )
846+
847+ it ( "should use custom base URL when provided with key file" , ( ) => {
848+ const customBaseUrl = "https://custom-vertex-endpoint.example.com"
849+
850+ const handler = new AnthropicVertexHandler ( {
851+ apiModelId : "claude-3-5-sonnet-v2@20241022" ,
852+ vertexProjectId : "test-project" ,
853+ vertexRegion : "us-central1" ,
854+ vertexBaseUrl : customBaseUrl ,
855+ vertexKeyFile : "/path/to/keyfile.json" ,
856+ } )
857+
858+ // Verify that AnthropicVertex was called with baseURL
859+ expect ( AnthropicVertex ) . toHaveBeenCalledWith (
860+ expect . objectContaining ( {
861+ baseURL : customBaseUrl ,
862+ projectId : "test-project" ,
863+ region : "us-central1" ,
864+ } ) ,
865+ )
866+ } )
867+
868+ it ( "should use custom base URL when provided without credentials" , ( ) => {
869+ const customBaseUrl = "https://custom-vertex-endpoint.example.com"
870+
871+ const handler = new AnthropicVertexHandler ( {
872+ apiModelId : "claude-3-5-sonnet-v2@20241022" ,
873+ vertexProjectId : "test-project" ,
874+ vertexRegion : "us-central1" ,
875+ vertexBaseUrl : customBaseUrl ,
876+ } )
877+
878+ // Verify that AnthropicVertex was called with baseURL
879+ expect ( AnthropicVertex ) . toHaveBeenCalledWith (
880+ expect . objectContaining ( {
881+ baseURL : customBaseUrl ,
882+ projectId : "test-project" ,
883+ region : "us-central1" ,
884+ } ) ,
885+ )
886+ } )
887+
888+ it ( "should not include baseURL when no custom URL is provided" , ( ) => {
889+ const handler = new AnthropicVertexHandler ( {
890+ apiModelId : "claude-3-5-sonnet-v2@20241022" ,
891+ vertexProjectId : "test-project" ,
892+ vertexRegion : "us-central1" ,
893+ } )
894+
895+ // Verify that AnthropicVertex was called without baseURL
896+ expect ( AnthropicVertex ) . toHaveBeenCalledWith (
897+ expect . not . objectContaining ( {
898+ baseURL : expect . anything ( ) ,
899+ } ) ,
900+ )
901+ } )
902+ } )
812903} )
0 commit comments