Reputation: 2302
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
Upvotes: 0
Views: 47
Reputation: 545
There are couple of things:
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