[ [ 'role' => 'user', 'parts' => [ ['text' => $userMessage] ] ] ], 'systemInstruction' => [ 'parts' => [ ['text' => $systemPrompt] ] ] ]); $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $payload); curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Content-Type: application/json' ]); curl_setopt($ch, CURLOPT_TIMEOUT, 15); $response = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if ($httpCode !== 200) { error_log("[Gemini API Error] HTTP " . $httpCode . " | Response: " . $response); return null; } $data = json_decode($response, true); return $data['candidates'][0]['content']['parts'][0]['text'] ?? null; } }