AlexZvl
AlexZvl

Reputation: 2302

PredictionServiceClient hanging and eventually times out

I have an external function, from my NextJS app, that tries to instantiate PredictionServiceClient, but every time it hangs and eventually times-out with no explanation of the issue.

  import { v1beta1 } from '@google-cloud/aiplatform';

  export function GET(request: Request) {
  
    const client = new v1beta1.PredictionServiceClient({apiEndpoint: 'europe-west3-aiplatform.googleapis.com'});

   return new Response(JSON.stringify('ok'));
 }

I do use OIDC as authentication, but passing authClient does not solve the issue, it just times-out

enter image description here

Upvotes: 0

Views: 47

Answers (1)

Gang Chen
Gang Chen

Reputation: 545

There are couple of things:

  1. try to use the v1 (GA) API endpoint.
  2. Typically PredictionServiceClient operates in background, your handler will likely be an async call.
  3. Your sample code seems only showing instantiate PredictionServiceClient but not making actual predict calls.

Here is a sample code to try:

import { PredictionServiceClient } from '@google-cloud/aiplatform';


export default async function handler(req, res) {  

  const client = new v1.PredictionServiceClient({apiEndpoint: 'europe-west3-aiplatform.googleapis.com'});

  // Define your prediction request object 
  // including actual model endpoint, instance configuration and other parameters
  const request = {
    endpoint,
    instances,
    parameters,
  };

  try {
     const predictionResponse = await client.predict(request); // Your actual Vertex AI prediction call

     res.status(200).json({ result: 'ok', prediction: predictionResponse}); // Send JSON response
  } catch (error) {
    console.error("Error during prediction:", error);
    res.status(500).json({ error: 'Prediction failed.' }); // Send error response as JSON
  }
}

Upvotes: 1

Related Questions