3

Documentation on this is a bit vague at the time of posting https://cloud.google.com/vertex-ai/docs/predictions/using-private-endpoints#sending-prediction-to-private-endpoint , they only mention how to do it with curl.

I would like to use the node.js client library if possible, but I've only managed to find examples that don't use a private endpoint ie: https://github.com/googleapis/nodejs-ai-platform/blob/main/samples/predict-custom-trained-model.js .

I've read through the type definitions of PredictionServiceClient imported from @google-cloud/aiplatform and didn't find a way to plug in my private endpoint. I've tried making the request anyway by simply specifying the resource name by doing const endpoint = projects/${project}/locations/${location}/endpoints/${endpointId} but this leads to the following error:

Error: 13 INTERNAL: Received RST_STREAM with code 0
    at Object.callErrorFromStatus (/home/vitor/vertexai/node_modules/@grpc/grpc-js/src/call.ts:81:24)
    at Object.onReceiveStatus (/home/vitor/vertexai/node_modules/@grpc/grpc-js/src/client.ts:343:36)
    at Object.onReceiveStatus (/home/vitor/vertexai/node_modules/@grpc/grpc-js/src/client-interceptors.ts:462:34)
    at Object.onReceiveStatus (/home/vitor/vertexai/node_modules/@grpc/grpc-js/src/client-interceptors.ts:424:48)
    at /home/vitor/vertexai/node_modules/@grpc/grpc-js/src/call-stream.ts:323:24
    at processTicksAndRejections (node:internal/process/task_queues:78:11) {
  code: 13,
  details: 'Received RST_STREAM with code 0',
  metadata: Metadata { internalRepr: Map(0) {}, options: {} }
}

My code looks like this:

(async () => {
        const client = new v1beta1.PredictionServiceClient();
        const location = "****";
        const project = "****";
        const endpointId = "****"
        const endpoint = `projects/${project}/locations/${location}/endpoints/${endpointId}`;

        const parameters = {
            structValue: {
                fields: {},
            },
        };

        const toInstance = (obj: any) => (
            {
                structValue: {
                    fields: {
                        ****
                    }
                }
            });

        const instance = toInstance(****);
        const instances = [instance];

        const res = await client.predict({
            instances,
            endpoint,
            parameters
        });
        console.log(res);
    })();

Is it possible to make this kind of request atm?

Vitor EL
  • 375
  • 2
  • 9
  • A curl is a simple API call. Why you can't do it? – guillaume blaquiere Mar 14 '22 at 17:40
  • 1
    I need to set authentication when making a curl request and I 'don't want to manage authentication if I'm running code inside google's infrastructure since they'll handle this for me as long as I use the client libraries. – Vitor EL Mar 14 '22 at 17:50
  • 1
    Private endpoint doesn't required authentication, but required to be in the same VPC. Your issue is not clear... – guillaume blaquiere Mar 14 '22 at 19:48
  • As guillaume is saying, your issue is not clear – Eduardo Ortiz Mar 14 '22 at 20:02
  • The issue is that I wanted to use the Node.js client library to request predictions to a private endpoint and I can't figure out how to tell the PredictionServiceClient to use my private endpoint. I thought I had to pass credentials with curl but since I don't I might as well just use curl. tks! – Vitor EL Mar 14 '22 at 21:11
  • Did you try from a VM in the same VPC as your VertexAI peering? – guillaume blaquiere Mar 15 '22 at 08:44
  • Yeah, all tests were done in a VM in the same VPC as VertexAi. HTTP requests to the private endpoint with curl or axios were working fine. I just couldn't find a way to make the requests using the client library. – Vitor EL Mar 15 '22 at 14:12
  • Another question, why don't you want to manage authentication into your project? – Eduardo Ortiz Mar 21 '22 at 18:47
  • Because GCP handles this for me. If a project is running under some service account then that project should have the credentials and permissions of that service account. Instantiating clients with credentials that I have created has given me headaches before. Like for example the credentials not being available in production or being commited to git history. For example, I think 'new Firestore()' is a better way to go about things than 'new Firestore({credentials})'. – Vitor EL Mar 21 '22 at 20:35
  • 1
    Based on this [doc](https://github.com/grpc/grpc-node/issues/1532) it looks like the problem is within the library that you are using and isn't related to GCP. – Eduardo Ortiz Mar 22 '22 at 14:10

1 Answers1

1

I had to initialize the client using the following in order to get it to behave as documented.

const client = new PredictionServiceClient({
apiEndpoint: 'us-central1-aiplatform.googleapis.com'

});

sublimental
  • 381
  • 1
  • 4
  • 9