[['parts' => [['text' => $prompt]]]], 'generationConfig' => ['responseMimeType' => 'application/json', 'temperature' => 0.7] ]; $ch = curl_init($url); curl_setopt_array($ch, [ CURLOPT_POST => true, CURLOPT_POSTFIELDS => json_encode($payload), CURLOPT_HTTPHEADER => ['Content-Type: application/json'], CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 60 ]); $res = curl_exec($ch); curl_close($ch); if (!$res) return null; $json = json_decode($res, true); $text = $json['candidates'][0]['content']['parts'][0]['text'] ?? ''; $text = preg_replace('/^```json\s*/i', '', $text); $text = preg_replace('/```\s*$/i', '', $text); return json_decode(trim($text), true); } }