$apiKey='xxxxxxxxxxxxxxx';
$url = "https://generativelanguage.googleapis.com/v1beta/models/gemini-1.5-pro-latest:generateContent? key=$apiKey";
$query['text']='Why has Google search gotten so bad?';
$message['role']='user';
$message['parts']=array($query);
$data['contents']=array($message);
$payload=json_encode($data);
$headers=['Content-Type:application/json','X-GEMINI-APIKEY:'.$apiKey];
$ch=curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
$response=curl_exec($ch);
curl_close($ch);
$result=json_decode($response,true);
echo $result['candidates'][0]['content']['parts'][0]['text'];