body { font-family: monospace; background: #000; color: #0f0; padding: 20px; } h2, h3 { color: #0ff; } pre { background: #111; padding: 15px; border-left: 3px solid #0f0; overflow-x: auto; } .error { color: #f00; } .success { color: #0f0; } .warning { color: #ff0; } img { background: #fff; padding: 10px; } "; echo "
❌ No API key configured!
"; exit; } else { echo "✅ API Key: " . substr($apiKey, 0, 10) . "..." . substr($apiKey, -6) . "
"; } // Test 2: Try to list available models echo "✅ API connection successful!
"; echo "Available models with IMAGE generation:
❌ Could not fetch models. Response:
"; echo "" . json_encode($modelsData, JSON_PRETTY_PRINT) . ""; } // Test 3: Try the image generation with the current model echo "
Model: $model
"; echo "URL: $url
"; echo "" . json_encode($payload, JSON_PRETTY_PRINT) . ""; echo "
⏳ Sending request...
"; $response = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); $curlError = curl_error($ch); curl_close($ch); echo "HTTP Status Code: "; if ($httpCode == 200) { echo "$httpCode ✅
"; } else { echo "$httpCode ❌"; } if ($curlError) { echo "cURL Error: $curlError
"; } $responseData = json_decode($response, true); echo "" . json_encode($responseData, JSON_PRETTY_PRINT) . ""; echo "
" . json_encode($responseData['error'], JSON_PRETTY_PRINT) . ""; if (isset($responseData['error']['message'])) { $errorMsg = $responseData['error']['message']; echo "
Error Message: $errorMsg
"; // Provide helpful suggestions if (stripos($errorMsg, 'not found') !== false || stripos($errorMsg, 'models/') !== false) { echo "💡 Suggestion: The model name might be incorrect or deprecated.
"; } elseif (stripos($errorMsg, 'quota') !== false || stripos($errorMsg, 'limit') !== false) { echo "💡 Suggestion: You may have exceeded your API quota.
"; } elseif (stripos($errorMsg, 'internal') !== false) { echo "💡 Suggestion: This might be a temporary API issue or the model is having problems.
"; } } } // Check for image in response if (isset($responseData['candidates'][0]['content']['parts'][0]['inlineData']['data'])) { echo "MIME Type: $mimeType
"; echo "Data length: " . strlen($imageData) . " characters
"; echo "Debug completed at " . date('Y-m-d H:i:s') . "
"; ?>