nano-pro/debug.php
DJP 4deed84ba0 Initial commit: Nano AI Image Generator
- Complete working image generation app using Imagen 3
- PHP backend with Gemini API integration
- Dark themed UI with prompt enhancement
- Session management and logging system

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 (1M context) <noreply@anthropic.com>
2025-12-16 08:35:02 -05:00

101 lines
3.6 KiB
PHP

<?php
/**
* Debug script to test Nano Banana Pro API directly
*/
require_once 'config.php';
echo "<h1>Nano Banana Pro API Debug</h1>";
if (!defined('GEMINI_API_KEY') || empty(GEMINI_API_KEY)) {
die("<p style='color:red'>ERROR: API key not configured in config.php</p>");
}
echo "<p>API Key configured: <strong>Yes</strong> (ending in " . substr(GEMINI_API_KEY, -8) . ")</p>";
// 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 "<h2>Request Details:</h2>";
echo "<pre>URL: $url</pre>";
echo "<pre>Payload: " . json_encode($payload, JSON_PRETTY_PRINT) . "</pre>";
echo "<h2>Making API Call...</h2>";
$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 "<p><strong>HTTP Status Code:</strong> $httpCode</p>";
if ($curlError) {
echo "<p style='color:red'><strong>cURL Error:</strong> $curlError</p>";
}
echo "<h2>Raw Response:</h2>";
echo "<pre style='background:#f5f5f5;padding:15px;border:1px solid #ccc;max-height:400px;overflow:auto;'>";
echo htmlspecialchars($response);
echo "</pre>";
echo "<h2>Parsed Response:</h2>";
$parsed = json_decode($response, true);
echo "<pre style='background:#f5f5f5;padding:15px;border:1px solid #ccc;max-height:400px;overflow:auto;'>";
print_r($parsed);
echo "</pre>";
// Check if image exists
if (isset($parsed['candidates'][0]['content']['parts'])) {
echo "<h2>Response Analysis:</h2>";
echo "<p><strong>Parts found:</strong> " . count($parsed['candidates'][0]['content']['parts']) . "</p>";
foreach ($parsed['candidates'][0]['content']['parts'] as $index => $part) {
echo "<p><strong>Part $index structure:</strong></p>";
echo "<pre>" . print_r(array_keys($part), true) . "</pre>";
if (isset($part['inline_data']['data'])) {
echo "<p style='color:green'>✓ Image data found in inline_data format!</p>";
echo "<p>Data length: " . strlen($part['inline_data']['data']) . " characters</p>";
echo "<img src='data:image/png;base64," . $part['inline_data']['data'] . "' style='max-width:400px;border:2px solid #FFC407;'>";
} elseif (isset($part['inlineData']['data'])) {
echo "<p style='color:green'>✓ Image data found in inlineData format!</p>";
echo "<p>Data length: " . strlen($part['inlineData']['data']) . " characters</p>";
echo "<img src='data:image/png;base64," . $part['inlineData']['data'] . "' style='max-width:400px;border:2px solid #FFC407;'>";
} else {
echo "<p style='color:orange'>No image data in this part</p>";
}
}
} else {
echo "<p style='color:red'><strong>ERROR:</strong> No candidates/content/parts found in response</p>";
if (isset($parsed['error'])) {
echo "<p style='color:red'><strong>API Error:</strong> " . htmlspecialchars($parsed['error']['message'] ?? 'Unknown error') . "</p>";
echo "<pre>" . print_r($parsed['error'], true) . "</pre>";
}
}