How to fix Prediction Service Client not being found error in PHP

I keep on getting

local.ERROR: Class “Google\Cloud\AIPlatform\V1\PredictionServiceClient” not found {“userId”:1,“exception”:"[object] (Error(code: 0): Class "Google\Cloud\AIPlatform\V1\PredictionServiceClient" not found

My code looks like this

use Illuminate\Http\Request;
use Google\Cloud\AIPlatform\V1\PredictionServiceClient;
use Google\Cloud\AIPlatform\V1\ModelName;
use Google\Cloud\AIPlatform\V1\PredictRequest;
use Google\Cloud\AIPlatform\V1\Content;
use Google\Cloud\AIPlatform\V1\ExampleBase;
use Google\ApiCore\ApiException;
use Google\Protobuf\Value;

    private function callGeminiAPI($prompt)
    {
        try {
            $client = new PredictionServiceClient([
                'credentials' => json_decode(file_get_contents(env('GOOGLE_APPLICATION_CREDENTIALS')), true),
                'apiEndpoint' => env('GOOGLE_LOCATION') . '-aiplatform.googleapis.com',
            ]);
    
            $formattedEndpoint = $client->endpointName(
                env('GOOGLE_PROJECT_ID'),
                env('GOOGLE_LOCATION'),
                'gemini-1.5-pro-001'
            );
    
            $instance = (new Value())
                ->setStructValue(['content' => $prompt]);
    
            $parameters = (new Value())
                ->setStructValue([
                    'temperature' => 0.2,
                    'maxOutputTokens' => 1024,
                    'topP' => 0.8,
                    'topK' => 40
                ]);
    
            $request = (new PredictRequest())
                ->setEndpoint($formattedEndpoint)
                ->setInstances([$instance])
                ->setParameters($parameters);
    
            $response = $client->predict($request);
            $predictions = $response->getPredictions();
    
            if (count($predictions) > 0) {
                $result = $predictions[0]->getStructValue()->getFieldsEntry('content')->getValue()->getStringValue();
                return $result;
            } else {
                return "No prediction received from the API.";
            }
        } catch (\Exception $e) {
            \Log::error('Error calling Gemini API: ' . $e->getMessage());
            return "Error: " . $e->getMessage();
        }
    }

I already have cloud-ai-platform installed.
Anyone know how to use the Prediction Service Client.
I am new to this.

This should have been triggered even before you executed the code. The editors such as VS Code and PhpStorm should have displayed that you’re trying to import a non-existent class. Can you provide me the repo url and I try checking and I’ll see if I can find the problem. Just to be clear I don’t use Vertex AI, I’ll do install just to find where that class is.

Hi, thanks for offering. I have found the solution. I was using

instead of use Google\Cloud\AIPlatform\V1\Client\PredictionServiceClient;

Seems I have been using some wrong methods.