Nano Banana Pro API Debug"; if (!defined('GEMINI_API_KEY') || empty(GEMINI_API_KEY)) { die("

ERROR: API key not configured in config.php

"); } echo "

API Key configured: Yes (ending in " . substr(GEMINI_API_KEY, -8) . ")

"; // Test API call $url = "https://generativelanguage.googleapis.com/v1beta/models/gemini-3-pro-image-preview:generateContent"; $payload = [ 'contents' => [ ['parts' => [['text' => 'A simple red circle on white background']]] ], 'generationConfig' => [ 'responseModalities' => ['IMAGE'], 'imageConfig' => [ 'aspectRatio' => '1:1', 'imageSize' => '1K' ] ] ]; echo "

Request Details:

"; echo "
URL: $url
"; echo "
Payload: " . json_encode($payload, JSON_PRETTY_PRINT) . "
"; echo "

Making API Call...

"; $ch = curl_init($url); curl_setopt_array($ch, [ CURLOPT_HTTPHEADER => [ 'Content-Type: application/json', 'x-goog-api-key: ' . GEMINI_API_KEY ], CURLOPT_POST => true, CURLOPT_POSTFIELDS => json_encode($payload), CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYPEER => true, CURLOPT_TIMEOUT => 120 ]); $response = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); $curlError = curl_error($ch); curl_close($ch); echo "

HTTP Status Code: $httpCode

"; if ($curlError) { echo "

cURL Error: $curlError

"; } echo "

Raw Response:

"; echo "
";
echo htmlspecialchars($response);
echo "
"; echo "

Parsed Response:

"; $parsed = json_decode($response, true); echo "
";
print_r($parsed);
echo "
"; // Check if image exists if (isset($parsed['candidates'][0]['content']['parts'])) { echo "

Response Analysis:

"; echo "

Parts found: " . count($parsed['candidates'][0]['content']['parts']) . "

"; foreach ($parsed['candidates'][0]['content']['parts'] as $index => $part) { echo "

Part $index structure:

"; echo "
" . print_r(array_keys($part), true) . "
"; if (isset($part['inline_data']['data'])) { echo "

✓ Image data found in inline_data format!

"; echo "

Data length: " . strlen($part['inline_data']['data']) . " characters

"; echo ""; } elseif (isset($part['inlineData']['data'])) { echo "

✓ Image data found in inlineData format!

"; echo "

Data length: " . strlen($part['inlineData']['data']) . " characters

"; echo ""; } else { echo "

No image data in this part

"; } } } else { echo "

ERROR: No candidates/content/parts found in response

"; if (isset($parsed['error'])) { echo "

API Error: " . htmlspecialchars($parsed['error']['message'] ?? 'Unknown error') . "

"; echo "
" . print_r($parsed['error'], true) . "
"; } }