'Nur POST-Anfragen sind erlaubt.']); exit; } $apiKey = module_env('GEMINI_API_KEY'); if (empty($apiKey)) { http_response_code(500); echo json_encode(['error' => 'API-Schlüssel (GEMINI_API_KEY) ist weder lokal noch zentral konfiguriert.']); exit; } // Request Payload lesen $rawInput = file_get_contents('php://input'); $requestData = json_decode($rawInput, true); if (json_last_error() !== JSON_ERROR_NONE || !isset($requestData['prompt'])) { http_response_code(400); echo json_encode(['error' => 'Ungültige Anfrage: "prompt" wird benötigt.']); exit; } $prompt = trim($requestData['prompt']); $model = $requestData['model'] ?? 'gemini-2.5-flash'; // Google Gemini API Aufruf $endpoint = 'https://generativelanguage.googleapis.com/v1beta/models/' . urlencode($model) . ':generateContent?key=' . $apiKey; $payload = [ 'contents' => [ [ 'parts' => [ ['text' => $prompt] ] ] ] ]; $ch = curl_init($endpoint); curl_setopt_array($ch, [ CURLOPT_RETURNTRANSFER => true, CURLOPT_POST => true, CURLOPT_HTTPHEADER => ['Content-Type: application/json'], CURLOPT_POSTFIELDS => json_encode($payload), CURLOPT_TIMEOUT => 30 ]); $response = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); $curlError = curl_error($ch); curl_close($ch); if ($curlError) { http_response_code(500); echo json_encode(['error' => 'Verbindungsfehler zur API: ' . $curlError]); exit; } http_response_code($httpCode); echo $response;