Simple OpenAI API Test"; // Your API key $apiKey = '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'; echo "

Testing OpenAI API...

"; $data = [ 'model' => 'gpt-4', 'messages' => [ ['role' => 'user', 'content' => 'Say "Hello" only.'] ], 'max_tokens' => 10 ]; $ch = curl_init(); curl_setopt_array($ch, [ CURLOPT_URL => 'https://api.openai.com/v1/chat/completions', CURLOPT_POST => true, CURLOPT_POSTFIELDS => json_encode($data), CURLOPT_HTTPHEADER => [ 'Content-Type: application/json', 'Authorization: Bearer ' . $apiKey ], CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 30, CURLOPT_HEADER => true ]); $response = curl_exec($ch); $httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); $headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE); curl_close($ch); $headers = substr($response, 0, $headerSize); $body = substr($response, $headerSize); echo "

Results:

"; echo "

HTTP Status: $httpCode

"; if ($httpCode == 200) { echo "

✅ SUCCESS! API is working

"; $data = json_decode($body, true); if (isset($data['choices'][0]['message']['content'])) { echo "

Response: " . htmlspecialchars($data['choices'][0]['message']['content']) . "

"; } } elseif ($httpCode == 429) { echo "

❌ RATE LIMITED!

"; $data = json_decode($body, true); if (isset($data['error']['message'])) { echo "

Error: " . htmlspecialchars($data['error']['message']) . "

"; } echo "

Rate Limit Headers:

"; $headerLines = explode("\n", $headers); foreach ($headerLines as $line) { if (stripos($line, 'x-ratelimit') !== false) { echo "

" . htmlspecialchars($line) . "

"; } } echo "

Solutions:

"; echo ""; } elseif ($httpCode == 401) { echo "

❌ AUTHENTICATION FAILED!

"; echo "

Your API key may be invalid or expired.

"; } else { echo "

❌ ERROR! HTTP $httpCode

"; echo "

Response: " . htmlspecialchars($body) . "

"; } echo "

Full Response Headers:

"; echo "
" . htmlspecialchars($headers) . "
"; echo "

Next Steps:

"; if ($httpCode == 200) { echo "

✅ Your API is working! You can now use the enhanced files:

"; echo "
    "; echo "
  1. Replace includes/config.php with the enhanced version
  2. "; echo "
  3. Replace includes/GptHelper.php with the enhanced version
  4. "; echo "
  5. Replace simple_foreground_processor.php with the enhanced version
  6. "; echo "
"; } elseif ($httpCode == 429) { echo "

⚠️ You're rate limited. Follow these steps:

"; echo "
    "; echo "
  1. STOP all OptimAIze processes immediately
  2. "; echo "
  3. Wait 2-3 hours for the rate limit to reset
  4. "; echo "
  5. Use the enhanced files with ultra-conservative settings
  6. "; echo "
  7. Start with 1 request per 90 seconds
  8. "; echo "
"; } else { echo "

❌ Fix the API issue first, then proceed with enhancements.

"; } ?>