Vitor EL
Vitor EL

Reputation: 555

How to make a prediction to a private Vertex AI endpoint with Node.js client libraries?

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?

Upvotes: 3

Views: 2597

Answers (1)

sublimental
sublimental

Reputation: 391

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'

});

Upvotes: 2

Related Questions